中科因仑“3+1”工程特种兵精英论坛
标题:
独立按键实现数码管0到9递增
[打印本页]
作者:
胡二波
时间:
2018-7-25 08:17
标题:
独立按键实现数码管0到9递增
[qq]896795262[/qq]
#include <STC15F2K60S2.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
uchar code seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit key1=P0^0;
bit duan,chang;
#define LED1 P1
uint n;
void delayms(uint ms){
uint i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void main(){
P1M0=0XFF;
P1M1=0X00;
n=0;
while(1){
if (key1==0){
delayms(800);
if(key1==0){
duan=1;
chang=0;
delayms(3000);
if(key1==0){
chang=1;
duan=0;
n=1;
}
while(!key1);
}
}
if (duan){
duan=0;
LED1=seg[n];
while(!key1);
n++;
if(n>9)
n=0;
}
if(chang){
chang=0;
LED1=seg[0];
}
}
}
复制代码
欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/)
Powered by Discuz! X3.4