- #include "reg51.h" //包含头文件reg51.h,定义了51单片机的专用寄存器
- sbit k1=P2^7;
- sbit k2=P2^6;
- sbit k3=P2^5;
- sbit k4=P2^4;
- sbit k5=P2^3;
- sbit k6=P2^2;
- sbit k7=P2^1;
- sbit k8=P2^0;
- char code table1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//阳极静态数码管的16进制编码
- char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x83,0xc6,0xa1,0x86,0x8e};//阴极动态数码管的16进制编码
- //附属函数专区开始
- void yanchi(unsigned int ms) //延时代码 - 函数定义
- {
- unsigned int x,y;
- for(x=ms;x>0;x--)
- for(y=110;y>0;y--);
- }
- void main() //主函数
- { unsigned char i=0;
- P0=0x00;
- while(1)
- {
- if(k1==0)//按下按键k1
- {
- yanchi(10);
- if(k1==0) //确认按下按键k1
- {
- i++;
- }while(!k1);
- }
- if(k2==0)//按下按键k2
- {
- yanchi(10);
- if(k2==0) //确认按下按键k2
- {
- i--;
-
- }while(!k2);
- }P0=table[i];
- }
- }
复制代码
|