- #include<reg52.h>
- #define DataPort P0
- sbit LATCH1=P2^2;
- sbit LATCH2=P2^3;
- //unsigned char code dofly[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
- unsigned char code dofly_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 共阴显示段码值0~9
- unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
- void Display(unsigned char FirstBit,unsigned char Num);
- unsigned char TempData[8];
- void delay();
- void main(void)
- {
- unsigned char i;
- TMOD = 0X01;
- TH0 = 0X3C;
- TL0 = 0XB0;
- TR0 = 1;
- while(1)
- {
- i++;
- if(i == 10)
- i = 0;
- TempData[0] = dofly_DuanMa[i];
- Display(7,1);
- }
- }
- void delay()
- {
- unsigned char i;
- for(i = 0; i < 20; i++)
- {
- while(!TF0);
- TF0 = 0;
- TH0 = 0X3C;
- TL0 = 0XB0;
- }
- }
- void Display(unsigned char FirstBit,unsigned char Num)
- {
- unsigned char i;
- for(i=0;i<Num;i++)
- {
- DataPort=0;
- LATCH1=1;
- LATCH1=0;
- DataPort=dofly_WeiMa[i+FirstBit];
- LATCH2=1;
- LATCH2=0;
- DataPort = TempData[i];
- LATCH1=1;
- LATCH1=0;
- delay();
- }
- }
延时一秒delay_1s
最新推荐文章于 2022-09-23 10:30:56 发布