while(1)
if(key1==0)
{
delay_ms(1);
if(key1==0)
{
while(!key1);
k++;
}
}
if(key2==0)
{
delay_ms(1);
if(key2==0)
{
while(!key2);
k--;
}
}
switch(k)
{
case 1:display1();break;
case 2:display2();break;
case 3:display3();break;
}
在做12864液晶屏翻页,想按一下k1翻到上一页,按k2翻到下一页,这样怎么实现不了
#include
#include
#define uchar unsigned char
#define uint unsigned int
#include "4.h"
uchar table []=" 4.c "; //oo×ÖÕ¼óÃ2×Ö½ú
uchar table1[]=" asdasdas ";
uchar table2[]=" SDASDSDD ";
uchar table3[]=" ò»¶tèyËÄ ";
uchar k;
uchar key1num,key2num;
sbit LCD_SID=P0^6;
sbit LCD_SCLK=P0^5;
sbit key1=P1^1;
sbit key2=P1^3;
void delay_ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void sendbyte(unsigned char bbyte) //·¢Ëíò»¸ö×Ö½ú
{
unsigned char i;
for(i=0;i<8;i++)
{
LCD_SID=bbyte&0x80; //è¡3ö×î¸ßλ
LCD_SCLK=1;
LCD_SCLK=0;
bbyte<<=1; //×óòÆ
}
}
void write(bit start, unsigned char ddata) //D′Ö¸áî»òêy¾Y
{
unsigned char start_data,Hdata,Ldata;
if(start==0)
start_data=0xf8; //D′Ö¸áî
else
start_data=0xfa; //D′êy¾Y
Hdata=ddata&0xf0; //衸ßËÄλ
Ldata=(ddata<<4)&0xf0; //è¡μíËÄλ
sendbyte(start_data); //·¢ËíÆeê¼DÅoÅ
delay_ms(1); //Ñóê±
sendbyte(Hdata); //·¢Ëí¸ßËÄλ
delay_ms(1);
sendbyte(Ldata); //·¢ËíμíËÄλ
delay_ms(1);
}
/***********ò»DDÏÔê¾8¸öoo×Ö***********
***************oo×ÖÏÔê¾***************
***XÎaDDYÎaáD,KÎa×Öμĸöêy,*PÎaêy×é*
*************************************/
void chinese(uchar x,uchar y,uchar k,uchar *p)
{
uchar hang,out,i;
y=y-1;
switch(x)
{
case 1:hang=0x80;break;
case 2:hang=0x90;break;
case 3:hang=0x88;break;
case 4:hang=0x98;break;
}
out=hang+y;
write(0,out);
for(i=0;i
write(1,*p);
p++;
}
//write(1,p);
}
/**********ò»DDÏÔê¾16¸ö×Öĸ***********
***********ó¢ÎÄêy×ÖÏÔê¾***************
***XÎaDDYÎaáD,KÎa×Öμĸöêy,*PÎaêy×é*
*************************************/
void english(uchar x,uchar y,uchar k,uchar *p)
{
uchar hang,out,i;
y=y-1;
switch(x)
{
case 1:hang=0x80;break;
case 2:hang=0x90;break;
case 3:hang=0x88;break;
case 4:hang=0x98;break;
}
out=hang+y;
write(0,out);
for(i=0;i
write(1,*p);
p++;
}
// write(1,p);
}
void lcd_init()
{
write(0,0x30); //8λ½éÃæ,»ù±¾Ö¸áî¼ˉ
write(0,0x0F); //ÏÔê¾′ò¿a,1a±ê¿a
write(0,0x01); //ÇåÆá,½«DDRAMμØÖ·¼ÆêyÆ÷1éáã
delay_ms(10);
}
void display1()
{
write(0,0x01);
english(1,1,15,table);
english(2,1,15,table);
english(3,1,15,table);
english(4,1,15,table);
}
void display2()
{
write(0,0x01);
english(1,1,15,table2);
english(2,1,15,table2);
english(3,1,15,table2);
english(4,1,15,table2);
}
void display3()
{
write(0,0x01);
english(1,1,15,table3);
english(2,1,15,table3);
english(3,1,15,table3);
english(4,1,15,table3);
}
void main()
{
lcd_init();
while(1)
if(key1==0)
{
delay_ms(1);
if(key1==0)
{
while(!key1);
k++;
}
}
if(key2==0)
{
delay_ms(1);
if(key2==0)
{
while(!key2);
k--;
}
}
switch(k)
{
case 1:display1();break;
case 2:display2();break;
case 3:display3();break;
}
}
-
4.c
(2018-4-24 18:01 上传)
3.53 KB, 下载次数: 1
利用不同的key在中断里切换显示页面的内容就行。或者中断里做标志后处理。
代码写的 不规范。主函数里的while 都不加大括号。这样很容易出问题。多参考一下别人的代码。避免这类问题的出现。