/****************************************************
文件名称:LCD_串行
摘 要:以凌阳61做为控制器,
LCD的控制器为STC7920
IOB0 ------LCD_CS
IOB1-------LCD_STD
IOB2-------LCD_SCLK
当前版本:1.1
完成日期:2007.7.31
替代版本:1.0
完成日期:2007.7.27
****************************************************/
#include "SPCE061A.h"
#define LCD_WIDTH 15 //LCD width
#define LCD_NextLine LCDSendCmd(0x00,0x90)
#define LCD_Data *P_IOB_Data
/*************************************
*****************串口函数库***********
*************************************/
//延时,时间精度不确定
void Delay(unsigned int t)
{
unsigned int i;
while (i = 1000,t --)
while (i --)
;
}
//发送数据
void LCDSendByte(unsigned char dat)
{
unsigned char i = 0;
unsigned char a = 0;
LCD_Data |= 0x0001;
for ( ;i < 8;i ++)
{
if(dat & 0x80)
LCD_Data |= 0x0002;
else
LCD_Data &= 0xFFFD;
LCD_Data |= 0x0004;
LCD_Data &= 0xFFFB;
dat <<= 1;
for (a = 0;a < 10;a ++)
;
}
LCD_Data &= 0xFFFE;
}
//发送命令
void LCDSendCmd(unsigned char cmd,unsigned char param)
{
unsigned char a;
a = cmd;
cmd &= 0x02;
a &= 0x01;
a <<= 2;
cmd |= a;
cmd |= 0xF8;
LCDSendByte(cmd);
a= param;
a &= 0xF0;
param <<= 4;
param &= 0xF0;
LCDSendByte(a);
LCDSendByte(param);
LCD_Data &= 0xFFFE;
}
//显示字符
void LCDSendChar(unsigned char ch)
{
if (ch == '\n')
LCD_NextLine;
else
LCDSendCmd(0x02,ch);
}
//显示字符串
void LCDSendString(unsigned char *s)
{
unsigned int i = 0;
while (s)
{
if (s == '\n')
//LCD_NextLine;
LCDSendCmd(0x00,0x90);
else
LCDSendCmd(0x02,s);
i ++;
if (i % 20 ==0)
//LCD_NextLine;
LCDSendCmd(0x00,0x90);
};
}
//显示数字
void LCDSendNum2(unsigned char num)
{
unsigned char a;
unsigned char b;
unsigned char c;
a = num / 100;
b = (num % 100) / 10;
c = num % 10;
if (a != 0 )
LCDSendCmd(0x02,a + '0');
if (b != 0)
LCDSendCmd(0x02,b + '0');
LCDSendCmd(0x02,c + '0');
}
//LCD清屏
void LCDCls(void)
{
*P_IOB_Dir |= 0x000F;
*P_IOB_Attrib |= 0x000F;
*P_IOB_Data &= 0xFFF0;
LCDSendCmd(0x00,0x01);
}
//LCD初始化
void LCDInit(unsigned char mode)
{
LCDSendCmd(0x00,0x30);
LCDSendCmd(0x00,0x01);
LCDSendCmd(0x00,0x06);
LCDSendCmd(0x00,0x0C);
if (mode == 0){
LCDSendCmd(0x00,0x30);
LCDSendCmd(0x00,0x80);
}
}
int main()
{
/**********************
*P_IOB_Dir = 0xFFFF;
*P_IOB_Attrib = 0xFFFF;
*P_IOB_Data = 0x0000;
***********************/
LCDInit(0);
LCDCls();
LCDSendCmd(0x00,0x81);
LCDSendString("悬挂控制系统菜单");
LCDSendCmd(0x00,0x90);
LCDSendChar(0x3E);
LCDSendCmd(0x00,0x91);
LCDSendString("历史的天空时湛蓝的");
//Delay(100);
for (;;)
{
*P_Watchdog_Clear = 1;
}
}
用户1319271 2007-8-15 14:48
是可以直接显示中文,LCD用的是带汉字库的,LCDSendCmd()是写控制字,LCDSendString()是显示字符串。
用户374863 2007-8-8 10:34
LCDSendString("悬挂控制系统菜单");
LCDSendCmd(0x00,0x90);
LCDSendChar(0x3E);
LCDSendCmd(0x00,0x91);
LCDSendString("历史的天空时湛蓝的");
这些是什么意思啊,可以直接引用中文??不是用编码???
我试了一下好象不行,没什么显示