單片機控制四位數碼管左邊兩個自加右邊兩個熄滅該怎么修改程式 這個程式好像只能從個位開始加 不知道該怎么定位到百位開始逐漸自加
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define ziwei P2
#define ziduan P0
uchar code Led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code hang[]={0x01,0x02,0x00,0x00};
uchar buffer[4];
uint count;
uint oldCount;
unsigned char i;
void delay()
{ unsigned char i; for(i=0;i<0x40;i++);
}
void num()
{
buffer[0]=count/1000%10;
buffer[1]=count/100%10;
}
void xianshi()
{
uchar i;
for(i=0;i<4;i++)
{
ziwei=~hang[i];
ziduan=Led[buffer[i]] ;
delay();
ziduan=0xff;
}
}
void main()
{ count=0;
oldCount=oldCount+1;
TMOD=0x01;
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
EA=1;
ET0=1;
i=0;
TR0=1;
while(1)
{ if(oldCount!=count)
{
oldCount=count ;
num();
} xianshi();
}
}
void time0_int(void) interrupt 1 {
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
i++;
if (i>=50) {
i=0;
if(count>=19)count=0;
count++;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/228610.html
標籤:單片機/工控
