当用MSP430F5310控制液晶CH240128B显示中文字符时显示出错,如:直接输入字符串“深圳”显示为其他的中文字符;但是当输入“深圳”在GB中的编码(0xB5,0xA1,0xDB,0xDA)时,显示正确。分析后认为是调用中文字库时地址出错,但是不知道原因是什么,是不是CCS5编译器的问题呢?这个问题困扰了好长时间,有谁遇到过这种问题?求大神帮忙解答一下,谢谢。如果可以QQ570338612解答下就更加感激不尽了!!!
灰小子:
能否提供下代码?
这个问题一般是程序问题。能通过GB编码显示汉子说明硬件没问题
Ken Wang:
要看你的液晶控制器对字符的支持,同时需要注意一下,发送数据和存储数据的高低字节位。看看是否有大小端的问题。
谢谢
yu fang1:
回复 灰小子:
好的,帮忙看下,谢谢!
#include "msp430F5310.h"
#define CLR_RST P5OUT&=~BIT1 //rst=0;复位信号,低电平有效
#define SET_RST P5OUT|=BIT1 //rst=1;
#define CLR_CS1 P5OUT&=~BIT0 //cs1=0;使能信号,低电平有效
#define SET_CS1 P5OUT|=BIT0 //cs1=1;
#define CLR_RS P6OUT&=~BIT1 //rs=0;数据选择
#define SET_RS P6OUT|=BIT1 //rs=1;命令选择
#define CLR_WR P6OUT&=~BIT2 //wr=0;写数据信号,低电平有效,上升沿锁存
#define SET_WR P6OUT|=BIT2 //wr=1;
#define CLR_RD P6OUT&=~BIT3 //rd=0;读数据信号,低电平有效
#define SET_RD P6OUT|=BIT3 //rd=1;
#define LCD_DatePort P1OUT //数据端口DB0~DB7
#define LCD_KEY P4IN //控制按键
unsigned char tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
unsigned char var1[]={0xC9,0xEE,0xDB,0xDA,0xB4,0xA8,0xBA,0xBD,0xB5,0xE7,0xD7,0xD3,0xBF,0xC6,0xBC,0xBC,0xD3,0xD0,0xCF,0xDE, 0xB9,0xAB,0xCB,0xBE,0xD2,0xBA,0xBE,0xA7,0xC6,0xC1};//深圳川航电子科技有限公司液晶屏
//延时
void delay_nms(unsigned int n)
{
unsigned int i,j;
asm("NOP");
for(i=n;i>0;i–)
{
for(j=125;j>0;j–)
{
}
}
}
//LCD软件复位
void softrst()
{
delay_nms(2);
CLR_RST;//rst=0;
delay_nms(5);
SET_RST;//rst=1;
delay_nms(5);
}
//写命令
void LCD_CmdWrite(unsigned char cmdaddr)//8080
{
P1DIR=0xff;
CLR_CS1;//cs1=0;
SET_RD;//rd=1;
SET_RS;//rs=1;
CLR_WR;//wr=0;
LCD_DatePort=cmdaddr;//BUS=cmdaddr;
delay_nms(5);
SET_WR;//wr=1;
SET_CS1;//cs1=1;
}
//写数据
void LCD_DataWrite(unsigned char wrdata)
{
P1DIR=0xff;
CLR_CS1;//cs1=0;
SET_RD;//rd=1;
CLR_RS;//rs=0;
CLR_WR;//wr=0;
LCD_DatePort=wrdata;//BUS=wrdata;
delay_nms(5);
SET_WR;//wr=1;
SET_CS1;//cs1=1;
}
//读数据
unsigned char LCD_CmdRead(unsigned char Addr)
{
unsigned char Data;
P1DIR=0xff;
CLR_CS1;//cs1=0;
SET_RS;//rs=1;
SET_RD;//rd=1;
CLR_WR;//wr=0;
LCD_DatePort=Addr;//BUS=Addr;
delay_nms(15);
SET_WR;//wr=1;
P1DIR=0x00;
delay_nms(5);
CLR_RS;//rs=0;
SET_WR;//wr=1;
SET_RD;//rd=1;
CLR_RD;//rd=0;
delay_nms(15);
Data=P1IN;//Data=BUS;
delay_nms(5);
return Data;
}
//消除雪花模式
void clearsnow(void) //在文本方式下,无法使用消除雪花模式,在图形模式下梢杂�
{ unsigned char temp;
temp=LCD_CmdRead(0x01);
temp|=0x80;
LCD_CmdWrite(0x01);
LCD_DataWrite(temp);
}
//不消除雪花模式–正常模式
void noclearsnow(void)
{ unsigned char temp; //在文本方式下,无法使用消除雪花模式
temp=LCD_CmdRead(0x01);
temp&=0x7f;
LCD_CmdWrite(0x01);
LCD_DataWrite(temp);
}
//绘图模式
void LCD_Graphic(void)
{ unsigned char temp;
temp=LCD_CmdRead(0x00);
temp&=0xf7;
LCD_CmdWrite(0x00);
LCD_DataWrite(temp);
clearsnow(); //开启消除雪花功能
}
//*************文字模式**************************
void LCD_Text(void)
{ unsigned char temp;
temp=LCD_CmdRead(0x00);
temp|=0x08;
LCD_CmdWrite(0x00);
LCD_DataWrite(temp);//BIT3
noclearsnow(); //关闭消除雪花功能
}
/////////////////清屏子程序//////////////////////////
void clear(void)
{
LCD_Graphic(); //选择绘图模式
noclearsnow(); //关闭消除雪花功能
LCD_CmdWrite(0xe0);
LCD_DataWrite(0x00);
delay_nms(5);
LCD_CmdWrite(0xf0);
LCD_DataWrite(0xa8);
delay_nms(5);
}
//******************X,Y坐标定位******************
void LCD_GotoXY(unsigned char xx,unsigned char yy)
{ LCD_CmdWrite(0x60);
LCD_DataWrite(xx);
LCD_CmdWrite(0x70);
LCD_DataWrite(yy);
}
//LCD初始化:相应寄存器配置
void lcd_inital()
{
LCD_CmdWrite(0x00); //WLCR[00H] , Default –> 0x00
LCD_DataWrite(0x04); //屏幕显示开启 disp_off输出high
delay_nms(5);
LCD_CmdWrite(0x01); //MISC[01H] , Default –> 0x00
LCD_DataWrite(0x04);
delay_nms(5);
LCD_CmdWrite(0x03); //ADSR[03H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x0F); //INTR[0FH] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x10); //WCCR[10H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x11); //CHWI[11H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x12); //MAMR[12H] , Default –> 0x11
LCD_DataWrite(0x11);
delay_nms(5);
LCD_CmdWrite(0x20); //AWRR[20H] , Default –> 0x27
LCD_DataWrite(29);
LCD_CmdWrite(0x21); //DWWR[21H] , Default –> 0x27
LCD_DataWrite(29);
LCD_CmdWrite(0x30); //AWBR[30H] , Default –> 0xEF
LCD_DataWrite(127);
LCD_CmdWrite(0x31); //DWHR[31H] , Default –> 0xEF
LCD_DataWrite(127);
delay_nms(5);
LCD_CmdWrite(0x40); //AWLR[40H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x50); //AWTR[50H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x60); //CURX[60H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x61); //BGSG[61H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x62); //EDSG[62H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x70); //CURY[70H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x71); //BGCM[71H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x72); //EDCM[72H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x80); //BTMR[80H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0x90); //ITCR[90H] , Default –> 0x00 对比度不好可以改此参数
LCD_DataWrite(0x00);
LCD_CmdWrite(0xE0); //PNTR[E0H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0xF0); //FNCR[F0H] , Default –> 0x00
LCD_DataWrite(0x00);
LCD_CmdWrite(0xF1); //FVHT[F1H] , Default –> 0x00
LCD_DataWrite(0x00);
}
//C程序初始化
void IO_inital()
{
P1SEL=0;//普通IO口
P1DIR=0xFF;//#define BUS P1;
P1OUT=0x00;
P5SEL=0;//普通IO口
P5DIR|=0x03;
P5OUT=0x00;
P6SEL=0;//普通IO口
P6DIR|=0x0F;
P6OUT&=~BIT0;//power_reset=0,TPS76833Q使能
//按键
P4SEL=0;
P4DIR=0x00;
P4IN=0xFF;
}
/////////////显示中文字库和字符////////////////////
void display_word(unsigned char *cha, int count )
{
unsigned int i=0;
LCD_Text(); //选择文本模式
LCD_CmdWrite(0xb0);//写数据模式
for(i=0;i<count;i++)
{
LCD_DataWrite(*cha++);
delay_nms(5);
delay_nms(2);
}
}
/////////////在指定的坐标处显示字符串////////////////////
void LCD_ShowStr(char *text)//unsigned
{
LCD_Text(); //选择文本模式
LCD_CmdWrite(0xb0);
while(*text != '\0')
{
LCD_DataWrite(*text++);
delay_nms(5);
delay_nms(2);
}
}
//主函数
void main (void)
{
WDTCTL=WDTPW+WDTHOLD;//关看门狗
_DINT();
IO_inital();
softrst();
lcd_inital();
clear();
delay_nms(20);
while(1)
{
LCD_GotoXY(0x00,0x00);
LCD_ShowStr("welcome to use CH240128B");
delay_nms(10);
LCD_GotoXY(0x00,0x20);
display_word(tab,10);
delay_nms(10);
LCD_GotoXY(0x00,0x40);
LCD_ShowStr("深圳川航电子科技有限公司液晶屏");
delay_nms(10);
LCD_GotoXY(0x00,0x60);
display_word(var1,30);
delay_nms(10);
if((LCD_KEY & BIT2)==0)
{
delay_nms(10);
LCD_GotoXY(0x00,0x70);
LCD_ShowStr("请选择:");
delay_nms(10);
}
}
}
yu fang1:
回复 Ken Wang:
已经内置中文字库。高低位问题我也怀疑过,仔细检查后,应该不存在。现在没办法了,只能通过GB编码来间接显示中文了!不过还是感谢你的回答~~