標題: BCD譯碼的2位數碼管的數字掃描顯示代碼 [打印本頁]
作者: 快樂肥宅水 時間: 2018-6-6 16:38
標題: BCD譯碼的2位數碼管的數字掃描顯示代碼
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar sec=0;
uchar count;
void delay(uint i)
{
uint j;
for(;i>0;i--)
for(j=0;j<125;j++);
}
void System_Init(void)
{
TMOD=0X01;
TH0=0X3C;
TL0=0XB0;
ET0=1;
EA=1;
TR0=1;
}
void display(uchar tmp)
{
P3=0xfe;
P2=tmp;
delay(1);
P3=0xfd;
P2=tmp<<4;
delay(1);
}
void main(void)
{
System_Init();
while(1)
{
display(sec);
}
}
Time(void) interrupt 1
{
TH0=0X3C;
TL0=0XB0;
count++;
if(count==20)
{
count=0;
sec++;
if(sec==10)
sec=0;
}
}
| 歡迎光臨 (http://m.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |