发表于:2006/5/27 17:06:00
#0楼
小弟编写的键盘显示程序,在调用液晶显示语句时,显示为 ll ,不管调用什么语句都显示那个字符 ll ,得不到所要字符.都快急死了,请求帮助,小弟不胜感激.显示器为TS1620.
附程序:
#include <reg51.h>
#include <math.h>
#include <intrins.h>
#include <absacc.h>
#define COM8255 XBYTE[0xBFFF]
#define PA8255 XBYTE[0x8FFF]
#define PB8255 XBYTE[0x9FFF]
#define PC8255 XBYTE[0xAFFF]
sbit RSPIN = P3^0;
sbit RWPIN = P3^1;
sbit EPIN = P3^5;
sbit INT_0=P3^2;
unsigned char XPOS=0,YPOS=0x00;
unsigned char idata key_code;
unsigned int xdata a,b,c,h=0,p=0,Q;
float xdata Diameter,d,L,W,t,xq,xh,xz;
unsigned int *zs;
unsigned int xdata s[5]={20,20,20,20,20};
//函数声明
void system_init(void);
void INT0_SCANkey();
unsigned char scan_key();
void delay(unsigned int N);
void manage_key0(void);
void manage_key1(void);
void manage_key2(void);
void manage_key3(void);
void manage_key4(void);
void manage_key5(void);
void manage_key6(void);
void manage_key7(void);
void manage_key8(void);
void manage_key9(void);
void manage_keyDot(void);
void manage_keyDiameter(void);
void manage_keydiameter1(void);
void manage_keyL(void);
void manage_keyW(void);
void manage_keyGo(void);
void manage_keyback(void);
void manage_keyrun(void);
void manage_keystop(void);
void manage_keyyuan(void);
void manage_keyjuxing(void);
void manage_keyhc(void);
void manage_keyqp(void);
void manage_keyAHH(void);
void key_manage(unsigned char keycode);
void lcdwaitidle(void);
void lcdwcn(unsigned char k);
void lcdwc(unsigned char k);
void lcdwd(unsigned char d);
void lcdpos(void);
void lcdreset() ;
void lcdfill(unsigned char f);
//延时子程序
void delay(unsigned int N)
{ unsigned int i,j;
for(i=0;i<N;i++)
for(j=0;j<10;j++);
}
//检测忙信号
void lcdwaitidle(void)
{ P0=0xFF;
RSPIN=0;
RWPIN=1;
EPIN=1;
while((P0&0x80)==0x80);
EPIN=0;
}
//写指令
void lcdwcn(unsigned char k)
{ RSPIN=0;
RWPIN=0;
P0=k;
EPIN=1;
_nop_();
EPIN=0;
}
void lcdwc(unsigned char k)
{ lcdwaitidle();
lcdwcn(k);
}
//写字符
void lcdwd(unsigned char d)
{ lcdwaitidle();
RSPIN=1;
RWPIN=0;
P0=d;
EPIN=1;
_nop_();
EPIN=0;
}
//光标位置
void lcdpos(void)
{ XPOS&=0x0f;
YPOS&=0x03;
if(YPOS==0x00)
lcdwc(XPOS|0x80);
else if(YPOS==0x01)
lcdwc((XPOS+0x40)|0x80);
}
//初始化
void lcdreset()
{ delay(150); lcdwcn(0x38);
delay(50); lcdwcn(0x38);
delay(50); lcdwcn(0x38);
lcdwc(0x38);
lcdwc(0x08);
lcdwc(0x01);
lcdwc(0x06);
lcdwc(0x0c);
}
void lcdfill(unsigned char f)
{
XPOS++;
lcdpos();
lcdwd(f);
}
//定时器设定
void system_init(void)
{ IT0=0;
EX0=1;
PA8255=0xFF;
EA=1;
}
//中断处理
void INT0_SCANkey() interrupt 0 using 1
{ key_code=0;
EA=0;
scan_key();
EA=1;
}
//键码获取
unsigned char scan_key()
{unsigned char code keyv[8]={1,2,4,8,16,32,64,128};
unsigned char code scan[3]={0x06,0x05,0x03};
unsigned char i,j,k;
PA8255=0xfd;
PC8255=0x00;
if(PA8255!=0xFF)
{ delay(1000);
for(i=0;i<3;i++)
{PC8255=scan[i];
j=PA8255;
if(j!=0xff)
break;
}
if((i<3)&&(j!=0xff))
{ j=~j;
i=i<<3;
for(k=0;i<8;i++)
if(j==keyv[k]){i=i+k;break;}
}
}
key_manage(i);
}
//键盘散转
void key_manage(unsigned char keycode)
{ switch(keycode)
{case 16:manage_key0();break;
case 9:manage_key1();break;
case 8:manage_key2();break;
case 1:manage_key3();break;
case 2:manage_key4();break;
case 11:manage_key5();break;
case 4:manage_key6();break;
case 5:manage_key7();break;
case 21:manage_key8();break;
case 6:manage_key9();break;
case 14:manage_keyDot();break;
case 12:manage_keyGo();break;
case 13:manage_keyback();break;
case 19:manage_keyyuan();break;
case 3:manage_keyjuxing();break;
case 0:manage_keyL();break;
case 10:manage_keyW();break;
case 18:manage_keystop();break;
case 17:manage_keyrun();break;
case 7:manage_keyDiameter();break;
case 20:manage_keydiameter1();break;
case 23:manage_keyhc();break;
case 15:manage_keyqp();break;
case 22:manage_keyAHH();break;
default:break; }
}
//数据处理
float SJCL()
{if(s[1]==10)
{a=s[0];b=s[2];
t=a+b/10;
}
else
if(s[2]==10)
{a=s[0];b=s[1];c=s[3];
t=10*a+b+c/10;
}
return(t);
}
//赋值判断
void datajudge()
{switch(h)
{case 1:Diameter=t; break;
case 2:d=t;break;
case 3:L=t;break;
case 4:W=t;break;
case 5:xq=t;break;
case 6:xh=t;break;
case 7:xz=t; break;
default:break;}
}
//按键0处理程序
void manage_key0(void)
{ lcdfill(0x30);
delay(100);
if(*zs!=20)zs++;
*zs=0;
}
//按键1处理程序
void manage_key1(void)
{ lcdfill(0x31);
delay(100);
if(*zs!=20)zs++;
*zs=1;
}
//按键2处理程序
void manage_key2(void)
{ lcdfill(0x32);
delay(100);
if(*zs!=20)zs++;
*zs=2;
}
//按键3处理程序
void manage_key3(void)
{ lcdfill(0x33);
delay(100);
if(*zs!=20)zs++;
*zs=3;
}
//按键4处理程序
void manage_key4(void)
{ lcdfill(0x34);
delay(100);
if(*zs!=20)zs++;
*zs=4;
}
//按键5处理程序
void manage_key5(void)
{ lcdfill(0x35);
delay(100);
if(*zs!=20)zs++;
*zs=5;
}
//按键6处理程序
void manage_key6(void)
{ lcdfill(0x36);
delay(100);
if(*zs!=20)zs++;
*zs=6;
}
//按键7处理程序
void manage_key7(void)
{ lcdfill(0x37);
delay(100);
if(*zs!=20)zs++;
*zs=7;
}
//按键8处理程序
void manage_key8(void)
{ lcdfill(0x38);
delay(100);
if(*zs!=20)zs++;
*zs=8;
}
//按键9处理程序
void manage_key9(void)
{ lcdfill(0x39);
delay(100);
if(*zs!=20)zs++;
*zs=9;
}
//按键Dot处理程序
void manage_keyDot(void)
{ lcdfill(0x1E);
delay(100);
if(*zs!=20)zs++;
*zs=10;
}
//按键D处理程序
void manage_keyDiameter(void)
{ lcdfill(0x44);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x72);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=1;
}
//按键d处理程序
void manage_keydiameter1(void)
{ lcdfill(0x54);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x72);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=2;
}
//按键run处理程序
void manage_keyrun(void)
{p=1;
}
//按键stop处理程序
void manage_keystop(void)
{
}
//按键圆模式处理程序
void manage_keyyuan(void)
{Q=1;
}
//按键矩形模式处理程序
void manage_keyjuxing(void)
{Q=2;
}
//按键Go处理程序
void manage_keyGo(void)
{ lcdfill(0x47);delay(100);
lcdfill(0x6F);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=5;
}
//按键back处理程序
void manage_keyback(void)
{ lcdfill(0x62);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x63);delay(100);
lcdfill(0x6B);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=6;
}
//按键L处理程序
void manage_keyL(void)
{ lcdfill(0x4C);delay(100);
lcdfill(0x6F);delay(100);
lcdfill(0x6E);delay(100);
lcdfill(0x67);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=3;
}
//按键W处理程序
void manage_keyW(void)
{ lcdfill(0x57);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x64);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x68);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=4;
}
//按键hc处理程序
void manage_keyhc(void)
{lcdfill(0x02);delay(100);
YPOS=1;XPOS=0;
t=SJCL();
datajudge();
t=0;
h=0;
s[0]=20;
s[1]=20;
s[2]=20;
s[3]=20;
s[4]=20;
zs=&s[0];
}
//按键qp处理程序
void manage_keyqp(void)
{lcdfill(0x01);delay(100);
YPOS=0;XPOS=0;
t=SJCL();
datajudge();
t=0;
h=0;
s[0]=20;
s[1]=20;
s[2]=20;
s[3]=20;
s[4]=20;
zs=&s[0];
}
//按键AHH处理程序
void manage_keyAHH(void)
{ lcdfill(0x41);delay(100);
lcdfill(0x48);delay(100);
lcdfill(0x48);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0xDF);delay(100);
lcdfill(0x3A);delay(100);
h=7;
Q=0;
}
main()
{EPIN=0;
lcdreset();
COM8255=0x88;
zs=&s[0];
system_init();
INT_0=0;
while(1);
}
附程序:
#include <reg51.h>
#include <math.h>
#include <intrins.h>
#include <absacc.h>
#define COM8255 XBYTE[0xBFFF]
#define PA8255 XBYTE[0x8FFF]
#define PB8255 XBYTE[0x9FFF]
#define PC8255 XBYTE[0xAFFF]
sbit RSPIN = P3^0;
sbit RWPIN = P3^1;
sbit EPIN = P3^5;
sbit INT_0=P3^2;
unsigned char XPOS=0,YPOS=0x00;
unsigned char idata key_code;
unsigned int xdata a,b,c,h=0,p=0,Q;
float xdata Diameter,d,L,W,t,xq,xh,xz;
unsigned int *zs;
unsigned int xdata s[5]={20,20,20,20,20};
//函数声明
void system_init(void);
void INT0_SCANkey();
unsigned char scan_key();
void delay(unsigned int N);
void manage_key0(void);
void manage_key1(void);
void manage_key2(void);
void manage_key3(void);
void manage_key4(void);
void manage_key5(void);
void manage_key6(void);
void manage_key7(void);
void manage_key8(void);
void manage_key9(void);
void manage_keyDot(void);
void manage_keyDiameter(void);
void manage_keydiameter1(void);
void manage_keyL(void);
void manage_keyW(void);
void manage_keyGo(void);
void manage_keyback(void);
void manage_keyrun(void);
void manage_keystop(void);
void manage_keyyuan(void);
void manage_keyjuxing(void);
void manage_keyhc(void);
void manage_keyqp(void);
void manage_keyAHH(void);
void key_manage(unsigned char keycode);
void lcdwaitidle(void);
void lcdwcn(unsigned char k);
void lcdwc(unsigned char k);
void lcdwd(unsigned char d);
void lcdpos(void);
void lcdreset() ;
void lcdfill(unsigned char f);
//延时子程序
void delay(unsigned int N)
{ unsigned int i,j;
for(i=0;i<N;i++)
for(j=0;j<10;j++);
}
//检测忙信号
void lcdwaitidle(void)
{ P0=0xFF;
RSPIN=0;
RWPIN=1;
EPIN=1;
while((P0&0x80)==0x80);
EPIN=0;
}
//写指令
void lcdwcn(unsigned char k)
{ RSPIN=0;
RWPIN=0;
P0=k;
EPIN=1;
_nop_();
EPIN=0;
}
void lcdwc(unsigned char k)
{ lcdwaitidle();
lcdwcn(k);
}
//写字符
void lcdwd(unsigned char d)
{ lcdwaitidle();
RSPIN=1;
RWPIN=0;
P0=d;
EPIN=1;
_nop_();
EPIN=0;
}
//光标位置
void lcdpos(void)
{ XPOS&=0x0f;
YPOS&=0x03;
if(YPOS==0x00)
lcdwc(XPOS|0x80);
else if(YPOS==0x01)
lcdwc((XPOS+0x40)|0x80);
}
//初始化
void lcdreset()
{ delay(150); lcdwcn(0x38);
delay(50); lcdwcn(0x38);
delay(50); lcdwcn(0x38);
lcdwc(0x38);
lcdwc(0x08);
lcdwc(0x01);
lcdwc(0x06);
lcdwc(0x0c);
}
void lcdfill(unsigned char f)
{
XPOS++;
lcdpos();
lcdwd(f);
}
//定时器设定
void system_init(void)
{ IT0=0;
EX0=1;
PA8255=0xFF;
EA=1;
}
//中断处理
void INT0_SCANkey() interrupt 0 using 1
{ key_code=0;
EA=0;
scan_key();
EA=1;
}
//键码获取
unsigned char scan_key()
{unsigned char code keyv[8]={1,2,4,8,16,32,64,128};
unsigned char code scan[3]={0x06,0x05,0x03};
unsigned char i,j,k;
PA8255=0xfd;
PC8255=0x00;
if(PA8255!=0xFF)
{ delay(1000);
for(i=0;i<3;i++)
{PC8255=scan[i];
j=PA8255;
if(j!=0xff)
break;
}
if((i<3)&&(j!=0xff))
{ j=~j;
i=i<<3;
for(k=0;i<8;i++)
if(j==keyv[k]){i=i+k;break;}
}
}
key_manage(i);
}
//键盘散转
void key_manage(unsigned char keycode)
{ switch(keycode)
{case 16:manage_key0();break;
case 9:manage_key1();break;
case 8:manage_key2();break;
case 1:manage_key3();break;
case 2:manage_key4();break;
case 11:manage_key5();break;
case 4:manage_key6();break;
case 5:manage_key7();break;
case 21:manage_key8();break;
case 6:manage_key9();break;
case 14:manage_keyDot();break;
case 12:manage_keyGo();break;
case 13:manage_keyback();break;
case 19:manage_keyyuan();break;
case 3:manage_keyjuxing();break;
case 0:manage_keyL();break;
case 10:manage_keyW();break;
case 18:manage_keystop();break;
case 17:manage_keyrun();break;
case 7:manage_keyDiameter();break;
case 20:manage_keydiameter1();break;
case 23:manage_keyhc();break;
case 15:manage_keyqp();break;
case 22:manage_keyAHH();break;
default:break; }
}
//数据处理
float SJCL()
{if(s[1]==10)
{a=s[0];b=s[2];
t=a+b/10;
}
else
if(s[2]==10)
{a=s[0];b=s[1];c=s[3];
t=10*a+b+c/10;
}
return(t);
}
//赋值判断
void datajudge()
{switch(h)
{case 1:Diameter=t; break;
case 2:d=t;break;
case 3:L=t;break;
case 4:W=t;break;
case 5:xq=t;break;
case 6:xh=t;break;
case 7:xz=t; break;
default:break;}
}
//按键0处理程序
void manage_key0(void)
{ lcdfill(0x30);
delay(100);
if(*zs!=20)zs++;
*zs=0;
}
//按键1处理程序
void manage_key1(void)
{ lcdfill(0x31);
delay(100);
if(*zs!=20)zs++;
*zs=1;
}
//按键2处理程序
void manage_key2(void)
{ lcdfill(0x32);
delay(100);
if(*zs!=20)zs++;
*zs=2;
}
//按键3处理程序
void manage_key3(void)
{ lcdfill(0x33);
delay(100);
if(*zs!=20)zs++;
*zs=3;
}
//按键4处理程序
void manage_key4(void)
{ lcdfill(0x34);
delay(100);
if(*zs!=20)zs++;
*zs=4;
}
//按键5处理程序
void manage_key5(void)
{ lcdfill(0x35);
delay(100);
if(*zs!=20)zs++;
*zs=5;
}
//按键6处理程序
void manage_key6(void)
{ lcdfill(0x36);
delay(100);
if(*zs!=20)zs++;
*zs=6;
}
//按键7处理程序
void manage_key7(void)
{ lcdfill(0x37);
delay(100);
if(*zs!=20)zs++;
*zs=7;
}
//按键8处理程序
void manage_key8(void)
{ lcdfill(0x38);
delay(100);
if(*zs!=20)zs++;
*zs=8;
}
//按键9处理程序
void manage_key9(void)
{ lcdfill(0x39);
delay(100);
if(*zs!=20)zs++;
*zs=9;
}
//按键Dot处理程序
void manage_keyDot(void)
{ lcdfill(0x1E);
delay(100);
if(*zs!=20)zs++;
*zs=10;
}
//按键D处理程序
void manage_keyDiameter(void)
{ lcdfill(0x44);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x72);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=1;
}
//按键d处理程序
void manage_keydiameter1(void)
{ lcdfill(0x54);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x65);delay(100);
lcdfill(0x72);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=2;
}
//按键run处理程序
void manage_keyrun(void)
{p=1;
}
//按键stop处理程序
void manage_keystop(void)
{
}
//按键圆模式处理程序
void manage_keyyuan(void)
{Q=1;
}
//按键矩形模式处理程序
void manage_keyjuxing(void)
{Q=2;
}
//按键Go处理程序
void manage_keyGo(void)
{ lcdfill(0x47);delay(100);
lcdfill(0x6F);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=5;
}
//按键back处理程序
void manage_keyback(void)
{ lcdfill(0x62);delay(100);
lcdfill(0x61);delay(100);
lcdfill(0x63);delay(100);
lcdfill(0x6B);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=6;
}
//按键L处理程序
void manage_keyL(void)
{ lcdfill(0x4C);delay(100);
lcdfill(0x6F);delay(100);
lcdfill(0x6E);delay(100);
lcdfill(0x67);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=3;
}
//按键W处理程序
void manage_keyW(void)
{ lcdfill(0x57);delay(100);
lcdfill(0x69);delay(100);
lcdfill(0x64);delay(100);
lcdfill(0x74);delay(100);
lcdfill(0x68);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x6D);delay(100);
lcdfill(0x3A);delay(100);
h=4;
}
//按键hc处理程序
void manage_keyhc(void)
{lcdfill(0x02);delay(100);
YPOS=1;XPOS=0;
t=SJCL();
datajudge();
t=0;
h=0;
s[0]=20;
s[1]=20;
s[2]=20;
s[3]=20;
s[4]=20;
zs=&s[0];
}
//按键qp处理程序
void manage_keyqp(void)
{lcdfill(0x01);delay(100);
YPOS=0;XPOS=0;
t=SJCL();
datajudge();
t=0;
h=0;
s[0]=20;
s[1]=20;
s[2]=20;
s[3]=20;
s[4]=20;
zs=&s[0];
}
//按键AHH处理程序
void manage_keyAHH(void)
{ lcdfill(0x41);delay(100);
lcdfill(0x48);delay(100);
lcdfill(0x48);delay(100);
lcdfill(0x2F);delay(100);
lcdfill(0xDF);delay(100);
lcdfill(0x3A);delay(100);
h=7;
Q=0;
}
main()
{EPIN=0;
lcdreset();
COM8255=0x88;
zs=&s[0];
system_init();
INT_0=0;
while(1);
}