|
简单计时器,通俗易懂,比较适合初学者,语句简单。
#include<reg51.h>
unsigned char i=0;
unsigned char count=0,count1=0;
sbit P3_2=P3^2;
unsigned char code disptab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d
,0x7d,0x07,0x7f,0x6f};
void timer0(void) interrupt 1
{
i++;
if(i==20)
{
i=0;
count++;
}
if(count==60) {count=0;count1++;};
P1=disptab[count1];
P0=disptab[count/10];
P2=disptab[count%10];
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
|
|