找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1983|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

四個(gè)按鍵槍聲 單片機(jī)模擬

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:200856 發(fā)表于 2017-5-20 00:34 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include <reg52.h>
#include <intrins.h>

#define uchar unsigned char
#define uint  unsigned int

sbit  BEEP= P1^5;
sbit  K1  = P3^0;
sbit  K2  = P3^1;
sbit  K3  = P3^3;
sbit  K4  = P3^2;

uchar  H_count,L_count;

/*********************************************************/
void  main()
{        
         P0=0;
        BEEP=1;
    TMOD=0x01;
    TH0=0xff;
    TL0=0xa0;
    H_count=0xff;
    L_count=0xa0;      
    EA=1;
    ET0=1;

    while(1)
    {
     if(K1 == 0)  TR0=1;
         if(K2 == 0)  TR0=1;
         if(K3 == 0)  TR0=1;
         if(K4 == 0)  TR0=1;
    }
}

/*********************************************************

**********************************************************/
void Time0(void) interrupt 1 using 0
{
        BEEP=~BEEP;
        if( L_count!=0x00 )
        {
           L_count--;
           TH0=H_count;
       TL0=L_count;
       return;
     }else  H_count--;
               
        if( H_count!=0xfc )
        {
           L_count--;
           TH0=H_count;
       TL0=L_count;
       return;
        }
        else
     {
        H_count=0xff;
        L_count=0xa0;
        TH0=H_count;
        TL0=L_count;
        BEEP=1;
        TR0=0;
     }   
}

/*********************************************************/

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表