用T0计数器工作方式1,用一根导线一端连接GND,另一端接触P3.4引脚,每接触一次,计数器加1显示到数码管,满100清0.使用中断方法
我是这样写的然而每给一个低电平并没有+1,求高手指导!
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
sbit P34=P3^4;
uchar shi,ge,t0;
uint num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x05;
TH0=0;
TL0=0;
EA=1;
ET0=1;
TR0=1;
}
void display(uchar shi,uchar ge)
{
shi=num/10;
ge=num%10;
wela=0;
P0=0xfe;
wela=1;
wela=0;
P0=0xff;
dula=0;
P0=table[shi];
dula=1;
dula=0;
delay(5);
wela=0;
P0=0xfd;
wela=1;
wela=0;
P0=0xff;
dula=0;
P0=table[ge];
dula=1;
dula=0;
delay(5);
}
void main()
{
init();
while(1)
{
display(shi,ge);
}
}
void T0_time() interrupt 1
{
TH0=0;
TL0=0;
t0++;
if(P34)
{
t0=0;
num++;
if(num>=100)
num=0;
}
}
|