使用
的是keil4和proteus7.8
如圖,p2口驅動7段LED數(shù)碼管模塊,而p1.0與p1.1為兩位數(shù)7段LED數(shù)碼管模塊的掃描信號,其中p1.0為個位數(shù)掃描信號,p1.1為十位數(shù)掃描信號。
單片機源程序:
#include<reg51.h>
#define SEG P2
#define SCANP P1
sbit LED=P0^7;
#define count_M1 50000
#define TH_M1 (65536-count_M1)/256
#define TL_M1 (65536-count_M1)%256
int count_T0=0;
#define count_M2 250
#define TH_M2 (256-count_M2)
#define TL_M2 (256-count_M2)
char count_T1=0;
char TAB[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
char disp[2]={0xc0,0xc0};
char seconds=0;
char scan=0;
main()
{
IE=0x8a;
TMOD=0x21;
TH0=TH_M1;TL0=TL_M1;
TR0=1;
TH1=TH_M2;TL1=TL_M2;
TR1=1;
LED=1;
while(1);
}
void T0_1S(void) interrupt 1
{
TH0=TH_M1;TL0=TL_M1;
if(++count_T0==20)
{
count_T0=0;
seconds++;
if(seconds==60)
{
seconds=0;
LED=~LED;
}
}
disp[1]=TAB[seconds/10];
disp[0]=TAB[seconds%10];
}
void T1_8ms(void) interrupt 3
{
if(++count_T1==32)
{
count_T1=0;
if(++scan==3) scan=1;
SEG=0xff;
SCANP=~scan;
SEG=disp[scan-1];
}
}
全部資料51hei下載地址:
單片機.zip
(18.3 KB, 下載次數(shù): 7)
2018-12-9 13:19 上傳
點擊文件名下載附件
|