求51单片机控制2个数码管的程序
两只数码管段码分别由P0,P2输出控制,P0是十位,P2是个位。P3.2,P3.4分别接两只按键,P32.清0,P3.4计数。
以上程序来自《单片机C语言程序设计实训100例——基于8051+Proteus仿真》
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar DSY_CODE[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
uchar Count = 0;
void main()
{
P0 = 0x00;
P2 = 0x00;
TMOD = 0x06;
TH0=255;
TL0=255;
ET0=1;
EX0=1;
EA =1;
IP =0x02;
IT0=1;
TR0=1;
while(1)
{
P0 = DSY_CODE[Count/10];
P2 = DSY_CODE[Count%10];
}
}
void Clear_Counter() interrupt 0
{
Count = 0;
}
void Key_Counter() interrupt 1
{
Count = (Count + 1) %100;
}