/*
*功能:开关key1控制实现每按一次,数码管数字加1,实现00-99的循环
*开关key2实现随时清零
*/
- #include<reg52.h>
- sbit SEG1 = P1^0; //定义显示十位的数码管
- sbit SEG2 = P2^0; //定义显示个位的数码管
- sbit key1 = P3^2; //定义实现数码管加1的开关key1
- sbit key2 = P3^3; //定义实现清零的开关key2
- typedef unsigned int uint;
- uint i,j;
- uint sum = 0;
- unsigned char code DSY_CODE[] = {0xC0,0xF9,0xA4,
- 0xB0,0x99,0x92,
- 0x82,0xF8,0x80,0x90}; //共阳极数码管
- void display(uint i,uint j); //数码管显示函数
- void main()
- {
- IE = 0X85;
- IT0 = 1;
- IT1 = 1;
- while(1)
- {
- display(i,j);
- }
-
- }
- void EX0_INT(void) interrupt 0 // 外部中断0,实现按键按一下数码管数字加一
- {
- sum++;
- }
- void EX1_INT(void) interrupt 2//外部中断1,实现清零
- {
- sum = 0;
- }
- void display(uint i,uint j) //数码管显示数字
- {
- i = sum/10; //数码管显示十位数字
- j = sum%10; //数码管显示个位数字
- if(sum == 100)
- sum = 0;
- P1 = DSY_CODE[i];
- P2 = DSY_CODE[j];
- }
复制代码
|