|
單片機C語言實例-400-綜合實例
#include<reg52.h>
sbit P24=P2^4;
sbit P25=P2^5;
sbit P26=P2^6;
sbit P27=P2^7;
unsigned int js;
unsigned int count;
unsigned char code LEDDis[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,0xBF};
void Delay(unsigned int ii)
{
unsigned int jj;
for(;ii>0;ii--)
for(jj=0;jj<125;jj++)
{;}
}
void main()
{
EA = 1; //允許CPU中斷
ET0 = 1; //定時器0中斷打開
ET1=1; //定時器1中斷打開
TMOD = 0x11; //設(shè)定時器0 1為模式1,16位模式
TH0=0xB8;
TL0=0x00; //設(shè)定時值為(20ms)
TH1=0xdc; //設(shè)定時值為(10ms)
TL1=0x00;
TR0 = 1;
TR1=1;
while(1);
}
//定時器0中斷外理中鍵掃描和顯示
void Key_Time0(void) interrupt 1 using 2
{
TH0=0xb8;
TL0=0x00;//設(shè)定時值為20000us(20ms)
count++;
if(count==50){
count=0;
js++;
}
if(js==9999){
js=0;
}
}
void Dis_Time1(void) interrupt 3 using 3
{
TH1=0xdc;
TL1=0x00;//設(shè)定時值為20000us(20ms)
P0=LEDDis[js/1000];
P24=0;
Delay(2);
P24=1;
P0=LEDDis[(js%1000)/100];
P25=0;
Delay(2);
P25=1;
P0=LEDDis[(js%100)/10];
P26=0;
Delay(2);
P26=1;
P0=LEDDis[js%10];
P27=0;
Delay(2);
P27=1;
}
更多詳情參考附件文檔
+08:00C147聯(lián)盟網(wǎng)2081.png (22.38 KB, 下載次數(shù): 192)
下載附件
保存到相冊
2022-4-19 10:32 上傳
|
|