标题:独立按键p1.0和p1.1
P1.1键为数字加1键 P1.0为数字减1键
使LED显现数据从000到999之间一次加一或减一
解决方案:(C言语编程)
#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar bai,shi,ge,num;
uint shu;
sbit uk= P1^1;
sbit dk= P1^0;
sbit le=P3^6;
void delay(uint a);
void display(uchar ba,uchar sh,uchar g);
uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x86,0xc7,0xc7,0xc0,0xff};
uchar code tablewe[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void init()
{
shu=0;
bai=0;
shi=0;
ge=0;
}
void main()
{
init();
while(1){
if(uk==0){
delay(5);
if(uk==0){
if(shu==999)
shu=0;
shu++;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
}
while(!uk) ;
}
if(dk==0){
delay(5);
if(dk==0){
if(shu==0)
shu=999;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
shu–;
}
while(!dk) ;
}
display(bai,shi,ge);
}
}
void display(uchar ba,uchar sh,uchar g)
{
le=1;
P2=tablewe[1];
le=0;
le=1;
P0=tabledu[ba];
le=0;
delay(5);
le=1;
P2=tablewe[2];
le=0;
le=1;
P0=tabledu[sh];
le=0;
delay(5);
le=1;
P2=tablewe[3];
le=0;
le=1;
P0=tabledu[g];
le=0;
delay(5);
}
void delay(uint a) {
uint i,j;
for(j=a;j>0;j–)
for(i=250;i>0;i–);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/moni/260991.html