单片机源程序如下:
- #include <reg51.h>
- sbit key = P1 ^ 0;
- sbit key1 = P1 ^ 4;
- unsigned char le[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x3f};
- unsigned char i;
- void delay (unsigned char p)
- {
- while(p--);
- }
- main()
- {
- while(1)
- {
- if(key == 0)
- {
- delay(100);
- while(key == 0);
- i++;
- if(i >= 10)
- i = 0;
- }
- if(key1 == 0)
- {
- delay(100);
- while(key1 == 0);
- if(i > 0)
- i--;
- }
- P2 = le[i];
- }
- }
复制代码
|