我想写一个按键按一下,屏幕数字变化一下的单片机程序,下载后,12864屏幕能显示数字,按键按了却不能变
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintsbitkey1=P3^4;sbitdula...
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P3^7;
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^4;
uchar numt0,num;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void zhi(uchar com)
{
rs = 0;
rw = 0;
en = 0;
P0 = com;
delayms(5);
en = 1;
delayms(5);
en = 0;
}
void shu(uchar dat)
{
rs = 1;
rw = 0;
en = 0;
P0 = dat;
delayms(5);
en = 1;
delayms(5);
en = 0;
}
void init()
{
zhi(0x30);
delayms(5);
zhi(0x0C);
delayms(5);
zhi(0x01);
delayms(5);
num=0;
}
void display(uchar num)
{
uchar shi,ge;
shi=num/10;
ge=num%10;
wela=0;
dula=0;
delayms(10);
zhi(0x80);
shu(0x30+shi);
zhi(0x81);
shu(0x30+ge);
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==24)
num=0;
display(num);
while(!key1);
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
这是我写的程序,请大神帮忙看一下呀~!感激不尽! 展开
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P3^7;
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^4;
uchar numt0,num;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void zhi(uchar com)
{
rs = 0;
rw = 0;
en = 0;
P0 = com;
delayms(5);
en = 1;
delayms(5);
en = 0;
}
void shu(uchar dat)
{
rs = 1;
rw = 0;
en = 0;
P0 = dat;
delayms(5);
en = 1;
delayms(5);
en = 0;
}
void init()
{
zhi(0x30);
delayms(5);
zhi(0x0C);
delayms(5);
zhi(0x01);
delayms(5);
num=0;
}
void display(uchar num)
{
uchar shi,ge;
shi=num/10;
ge=num%10;
wela=0;
dula=0;
delayms(10);
zhi(0x80);
shu(0x30+shi);
zhi(0x81);
shu(0x30+ge);
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==24)
num=0;
display(num);
while(!key1);
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
这是我写的程序,请大神帮忙看一下呀~!感激不尽! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询