开机后显示数值“00”,此后每单击1次按钮BUT,数码管的显示值便增1,直至99后自动从1开始,无限循环。程序在附件
单片机源程序如下:
- #include<reg51.h>
- unsigned char code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char count;
- void delay(unsigned int time)
- {
- unsigned int j = 0;
- for(;time>0;time--)
- for(j=0;j<125;j++);
- }
- key0() interrupt 0
- {
- delay(10);
- count++;
- if(count==100)
- count=0;
- P0=table[count/10];
- P2=table[count%10];
- }
- void display_mode()
- {
- P2 = 0x00;
- delay(500);
- P2 = 0x3f;
- delay(500);
- }
- void main(void)
- {
- EA = 1;
- EX0 = 1;
- IT0 = 1;
- P0 = table[0];
- P2 = table[0];
- display_mode();
- while(1)
- {
-
- }
- }
复制代码
所有资料51hei提供下载:
51黑论坛_计数器.zip
(56.95 KB, 下载次数: 54)
|