本帖最后由 1054586 于 2018-3-20 20:14 编辑
1秒定时器0-9文件
#include<reg52.h> sbit we=P2^7; sbit du=P2^6; unsigned char code seg7ca[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsignedint cnt = 0; unsigned char flag1s = 0; unsigned char i = 0; void main() { P0=0xfe; TMOD= 0x01; TH0= 0xFC; TL0= 0x67; TR0= 1; EA= 1; ET0= 1; while(1) { if(flag1s == 1) { flag1s = 0; i++; P1=0x48; we=1; we=0; du=1; P0=seg7ca; if(i>=9) { i=0; } } } } void InterruptTime0() interrupt 1 { TH0 = 0xFC; TL0 = 0x67; cnt++; if(cnt >= 1000) { cnt= 0; flag1s= 1; } }
|