1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉

標題: 按鍵控制數碼管加減演示 [打印本頁]

作者: weilibin    時間: 2018-6-4 10:01
標題: 按鍵控制數碼管加減演示
   #include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//段碼
uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
//待顯示的3位緩沖
uchar Num_Buffer[]={0,0,0};
//按鍵代碼,按鍵計數
uchar Key_Code,Key_Counts=0;
//延時
void DelayMS(uint x)
{
        uchar i;
        while(x--) for(i=0;i<120;i++);
}       
//顯示函數
void Show_Counts_ON_DSY()
{
        uchar i,j=0x01;
        Num_Buffer[2]=Key_Counts/100;
        Num_Buffer[1]=Key_Counts/10%10;
        Num_Buffer[0]=Key_Counts%10;
        for(i=0;i<3;i++)
        {
                j=_cror_(j,1);
                P0=0xff;
                P0=DSY_CODE[Num_Buffer[i]];
                P2=j;
                DelayMS(1);
        }
}
//主程序
void main()
{
        uchar i;
        P0=0xff;
        P1=0xff;
        P2=0x00;
        Key_Code=0xff;
        while(1)
        {
                Show_Counts_ON_DSY();
                P1=0xff;
                Key_Code=P1;
                //有鍵按下時,數碼管刷新顯示30次,該行代碼同時起到延時作用
                if(Key_Code!=0xff)
                for(i=0;i<30;i++) Show_Counts_ON_DSY();
                switch(Key_Code)
                {
                        case 0xfe:        if(Key_Counts<255) Key_Counts++;
                                                break;
                        case 0xfd:        if(Key_Counts>0) Key_Counts--;
                                                break;
                        case 0xfb:        Key_Counts=0;
                }
                Key_Code=0xff;
        }
}






歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1