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;
}
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include<intrins.h>
#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<k*2;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<k;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;
}
}
一周热门 更多>