标题: (共享程序)按下独立1个独立键盘LED灯自动加1程序 [打印本页]

作者: mafu    时间: 2015-5-6 09:55
标题: (共享程序)按下独立1个独立键盘LED灯自动加1程序
#include <reg52.h>
#define uchar  unsigned char
#define uint   unsigned int
uchar num;
sbit key18=P1^4;
sbit D1=P2^0;
uchar code shu[]={ 0xc0,0xf9,0xa4,0xb0,  //共阳数码管段码 0,1,2,3
                0x99,0x92,0x82,0xf8,  //共阳数码管段码 4,5,6,7
                0x80,0x90             //共阳数码管段码 8,9,全灭,横杠       
              };
void delay(char z)
{
        char x,y;
        for(x=100;x>0;x--)
                for(y=z;y>0;y--);
}
void main()
{
        while(1)
        {
                P2=0x7f;
                P0=0xff;
                P1=0xff;
                if(key18==0)
                {
                delay(5);
                if(key18==0)
                {
                         D1=0;
                         num++;
                         if(num==10)
                         {
                                 num=0;       
                         }
                                   P2=0x7f;
                                P0=shu[num];
                }
                while(key18!=1);
                delay(5);
                while(key18!=1);
                }
                       
                else
                {
                        D1=1;       
                }
                 
        }

}






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1