使用
的是keil4和proteus7.8
如图,p2口驱动7段LED数码管模块,而p1.0与p1.1为两位数7段LED数码管模块的扫描信号,其中p1.0为个位数扫描信号,p1.1为十位数扫描信号。
单片机源程序:
#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, 下载次数: 7)
|