51单片机 仿真电路 单片机
仿真电路图(没画最小系统)
#include
unsigned char seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
//共阳极断码表
unsigned char num=0,count=0;
***it K0=P3^2;
***it K1=P3^3;
int i=0;
void dis_play();
void intittimer();
void main()
{
intittimer();
while(1)
{
dis_play();
}
}
void intittimer()
{
TMOD=0x01;
TH0=(65536-50000)/256; //50ms=50000us
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=0;
IT0=1;
EX0=1;
IT1=1;
EX1=1;
}
void dis_play()
{
if(num==100)
{
num=0;
}
P2=seg[num/10];
P1=seg[num%10];
}
void a() interrupt 0
{
TR0=~TR0;
num=num;
}
void b()interrupt 2
{
TR0=0;
num=0;
}
void timer_isr() interrupt 1
{
TH0=(65536-50000)/256; //50ms=50000us 256=2^8 初值>>8
TL0=(65536-50000)%256;
count++;
if(count==20)
{
num++;
count=0;
}
}
更多回帖