单片机源程序如下:
- #include <REG52.H>
- #define uchar unsigned char
- #define uint unsigned int
- uint count_km; //记录里程数
- uchar count0,count1,count2,count3;//用于分离里程数的各位数字
- sbit P20=P2^0;
- sbit P21=P2^1;
- sbit P22=P2^2;
- sbit P23=P2^3;
- const uchar table0[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//显示码显示数字0~9
- void delay()
- {
- uint i;
- for(i=0;i<256;i++);
- }
- void timer0isr(void) interrupt 1 using 1
- {
- count_km=count_km + 1500;
- if(count_km>9999)
- count_km=9999;
- }
- void main(void)
- {
- TMOD = 0x06; //设定T/C0工作在计数器,工作方式2
- TH0 = 0xFB;
- TL0 = 0xFB; //装载计数初值
- EA = 1; //开总中断
- ET0 = 1; //开T/C0中断
- TR0 = 1; //启动T/C0
- while(1)
- {
- count0=count_km%10;
- count1=count_km/10%10;
- count2=count_km/100%10;
- count3=count_km/1000%10;
- P1=table0[count0];
- P23=1;delay();P23=0;
- P1=table0[count1];
- P22=1;delay();P22=0;
- P1=table0[count2];
- P21=1;delay();P21=0;
- P1=table0[count3];
- P20=1;delay();P20=0;
- }
- }
复制代码
所有资料51hei提供下载:
简易车辆里程表.rar
(60.91 KB, 下载次数: 91)
|