赞
踩
实现功能:
代码:
- #include<reg52.h>
-
- sbit dula=P2^6; //段选
- sbit wela=P2^7; //位选
-
- sbit K1 = P3^0;
- sbit K2 = P3^1;
- sbit K3 = P3^2;
- sbit K4 = P3^3;
-
- #define uchar unsigned char
- #define uint unsigned int
-
- void delay(uint z)// 延时1ms
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
-
- uchar wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //位表
- uint duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00}; //段表
- uchar ILOVEYOU[]={0x06,0x38,0x3F,0x3E,0x79,0x6E,0x3F,0x3E}; //ILOVEYOU
- uchar xuehao[9];//存放学号各个位上数字
- long int cnt =19011234;//输入学号
- void main()
- {
- unsigned char i,j ;
- for(j=0;j<125;j++)//125x8=1000ms=1s
- {
- for(i=0;i<8;i++)
- {
- P0=ILOVEYOU[i];//显示:ILOVEYOU
- dula=1;//打开段选
- dula=0;//关闭段选
-
- P0=wei[i];//数码管依次点亮
- wela=1;//打开位选
- wela=0;//关闭位选
- delay(1);//延时1ms
- }
- }
- while(1)
- {
- //将学号转为各个位上的数字
- xuehao[0] = (cnt/10000000);
- xuehao[1] = (cnt/1000000)%10;
- xuehao[2] = (cnt/100000)%10;
- xuehao[3] = (cnt/10000)%10;
- xuehao[4] = (cnt/1000)%10;
- xuehao[5] = (cnt/100)%10;
- xuehao[6] = (cnt/10)%10;
- xuehao[7] = cnt%10;
- xuehao[8] = 10;
- for(i=0;i<9;i++)
- {
- P0=duan[xuehao[i]]; //显示学号
- dula=1;//打开段选
- dula=0;//关闭段选
-
- P0=wei[i];//数码管依次点亮
- wela=1;//打开位选
- wela=0;//关闭位选
- delay(1);//延时1ms
- }
- if(K1 == 0)//判断按键K1按下
- {
- delay(20);//消抖
- while(K1 == 0);//检测按键松开
- delay(20);//消抖
- cnt++;//学号加一
-
- }
- if(K2 == 0)
- {
- delay(20);//消抖
- while(K2 == 0);//检测按键松开
- delay(20);//消抖
- cnt--;//学号减一
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。