求一个单片机程序:三个按键,一个启动设置,一个加,一个减。
答案:1 悬赏:60
解决时间 2021-02-16 09:05
- 提问者网友:精神病院里
- 2021-02-15 21:25
求一个单片机程序:三个按键,一个启动设置,一个加,一个减。
最佳答案
- 二级知识专家网友:醉吻情书
- 2021-02-15 23:02
#include
#define uchar unsigned char
#define uint unsigned int
sbit aj1=P3^4;
sbit aj2=P3^5;
sbit aj3=P3^6;
sbit aj4=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x00};
void delay(uint z);
void init();
void shumaguan(uchar shu);
void anjian();
uchar aa,shu;
void main()
{
init();
while(1)
{
anjian();
shumaguan(shu);
}
}
void init()
{
shu=0;
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
//TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void dingshiqi0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
aa++;
if(aa==20)
{
aa=0;
shu++;
if(shu==60)
shu=0;
}
}
void shumaguan(uchar shu)
{
uchar shi,ge;
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
shi=shu/10;
ge=shu%10;
}
void anjian()
{
if(aj1==0)
{
delay(10);
if(aj1==0)
{
shu++;
if(shu==60)
shu=0;
while(!aj1)
shumaguan(shu);
while(!aj1);
}
}
if(aj2==0)
{
delay(10);
if(aj2==0)
{
if(shu==0)
shu=60;
shu--;
while(!aj2)
shumaguan(shu);
while(!aj2);
}
}
if(aj3==0)
{
delay(10);
if(aj3==0)
{
shu=0;
while(!aj3)
shumaguan(shu);
while(!aj3);
}
}
if(aj4==0)
{
delay(10);
if(aj4==0)
{
TR0=~TR0;
while(!aj4)
shumaguan(shu);
while(!aj4);
}
}
}
这是我以前写得4个按键的 要不用不上 你就把aj3去掉那个是清零的你这问题补充的 先前怎么不一起加上不知道你的IO口的定义你这样吧 你把液晶的 地址 数据 设置好 然后用定时器 控制1秒++;在按键里面 和你要显示的液晶的 指令和数据 分解加上 就可以了
#define uchar unsigned char
#define uint unsigned int
sbit aj1=P3^4;
sbit aj2=P3^5;
sbit aj3=P3^6;
sbit aj4=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x00};
void delay(uint z);
void init();
void shumaguan(uchar shu);
void anjian();
uchar aa,shu;
void main()
{
init();
while(1)
{
anjian();
shumaguan(shu);
}
}
void init()
{
shu=0;
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
//TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void dingshiqi0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
aa++;
if(aa==20)
{
aa=0;
shu++;
if(shu==60)
shu=0;
}
}
void shumaguan(uchar shu)
{
uchar shi,ge;
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
shi=shu/10;
ge=shu%10;
}
void anjian()
{
if(aj1==0)
{
delay(10);
if(aj1==0)
{
shu++;
if(shu==60)
shu=0;
while(!aj1)
shumaguan(shu);
while(!aj1);
}
}
if(aj2==0)
{
delay(10);
if(aj2==0)
{
if(shu==0)
shu=60;
shu--;
while(!aj2)
shumaguan(shu);
while(!aj2);
}
}
if(aj3==0)
{
delay(10);
if(aj3==0)
{
shu=0;
while(!aj3)
shumaguan(shu);
while(!aj3);
}
}
if(aj4==0)
{
delay(10);
if(aj4==0)
{
TR0=~TR0;
while(!aj4)
shumaguan(shu);
while(!aj4);
}
}
}
这是我以前写得4个按键的 要不用不上 你就把aj3去掉那个是清零的你这问题补充的 先前怎么不一起加上不知道你的IO口的定义你这样吧 你把液晶的 地址 数据 设置好 然后用定时器 控制1秒++;在按键里面 和你要显示的液晶的 指令和数据 分解加上 就可以了
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |