//本程序在http://www.study-kit.com/list.asp?ProdId=NO052上通过测试
//HotPower@126.com 2008.4.17 2:28
#include "lcd.h"
LcdObj:: LcdObj(void)
{
Init();
}
void LcdObj::Init(void)
{
SendCommand(0x30);//发送功能设定控制命令(8位)
SendCommand(0x30);//发送功能设定控制命令(8位)
SendCommand(0x01);//发送清除显示命令
SendCommand(0x06);//发送进入点命令0x06
SendCommand(0x0a);//发送开关显示关光标命令
SendCommand(0x0c);//发送开显示关光标命令
SendCommand(0x02);//发送位址归位命令,设定DDRAM位址计数器为0
SendCommand(0x17);//游标或显示移位控制
SendCommand(0x80);//发送设定DDRAM地址0x00命令,光标定位到(0,0)
ClearBuffer();//清空LCD显示缓冲区
DisplayBuffer();
}
void LcdObj::delay(unsigned int t)
{
while(t>0)
{
t--;
for (int i = 0; i < 150; i++);
}
}
void LcdObj::SendCommand(char cCommand)
{
LcdComH = cCommand;
LcdComL = cCommand;
if (cCommand == 0x01)//清除显示命令,需要等待时间相对较长
{
delay(1600);//st7920要求等待1.6mS
// DSP28x_usDelay(1600);//st7920要求等待1.6mS
}
else
{
delay(72);//st7920要求等待72uS
// DSP28x_usDelay(72);//st7920要求等待72uS
}
}
void LcdObj::SendData(char cData)
{
LcdDatH = cData;
LcdDatL = cData;
delay(72);//st7920要求等待72uS
// DSP28x_usDelay(72);//st7920要求等待72uS
}
void LcdObj::ClearBuffer(void)
{
unsigned char i, j;
for (i = 0;i < 4;i ++)
{
for (j = 0;j < 16; j ++)
{
Buffer[j] = ' ';
}
RowWriteEnable = 1;//允许此行刷新汉字显示
}
Row = 0;
Col = 0;
}
void LcdObj:: DisplayBuffer(void)
{
unsigned char i, j;
for (i = 0; i < 4; i ++)
{//4行汉字
if (RowWriteEnable)
{//允许此行刷新汉字显示
SendCommand(0x80 + (i & 1) * 16 + (i >> 1) * 8);//移动光标
for (j = 0; j < 16; j ++)
{//每行8个汉字16个字符
SendData(Buffer[j]);//刷新显示字符
}
RowWriteEnable = 0;//过后不允许此行刷新汉字显示
}
}
}
void LcdObj::SetDisplayPos(unsigned char row, unsigned char col)
{
Row = row & 0x03;//4行
Col = col & 0x0f;//16列
}
void LcdObj:: Display(const char *string)
{
char len, i;
len = strlen(string);
if ((Row < 4) && ((Col + len) <= 16))
{
if (len == 0)
{
while(Col < 16)
{
Buffer[Row][Col ++] = ' ';
}
}
else
for (i = 0; i < len; i ++) Buffer[Row][Col ++] = string;
RowWriteEnable[Row] = 1;//需要显示刷新
}
}
#include "main.h"
class SystemObj System;
class TimerObj Timer;//系统时间类
class LcdObj Lcd;
class KeyboardObj Keyboard;
int main(void)
{
Lcd.SetDisplayPos(0, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示12");
Lcd.SetDisplayPos(1, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示34");
Lcd.SetDisplayPos(2, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示56");
Lcd.SetDisplayPos(3, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示78");
EALLOW;
// PieCtrlRegs.PIEACK.all = 0xFFFF;//PIEACK_GROUP1;
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
EDIS;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
asm(" nop");
// Reset the watchdog counter
KickDog();
}
}
interrupt void ISRTimer0(void)
{
Lcd.DisplayBuffer();//定时刷新LCD显示(只刷新新行字符)
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
// PieCtrlRegs.PIEIFR1.bit.INTx7 = 1;
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//HotPower@126.com 2008.4.17 2:28
#include "lcd.h"
LcdObj:: LcdObj(void)
{
Init();
}
void LcdObj::Init(void)
{
SendCommand(0x30);//发送功能设定控制命令(8位)
SendCommand(0x30);//发送功能设定控制命令(8位)
SendCommand(0x01);//发送清除显示命令
SendCommand(0x06);//发送进入点命令0x06
SendCommand(0x0a);//发送开关显示关光标命令
SendCommand(0x0c);//发送开显示关光标命令
SendCommand(0x02);//发送位址归位命令,设定DDRAM位址计数器为0
SendCommand(0x17);//游标或显示移位控制
SendCommand(0x80);//发送设定DDRAM地址0x00命令,光标定位到(0,0)
ClearBuffer();//清空LCD显示缓冲区
DisplayBuffer();
}
void LcdObj::delay(unsigned int t)
{
while(t>0)
{
t--;
for (int i = 0; i < 150; i++);
}
}
void LcdObj::SendCommand(char cCommand)
{
LcdComH = cCommand;
LcdComL = cCommand;
if (cCommand == 0x01)//清除显示命令,需要等待时间相对较长
{
delay(1600);//st7920要求等待1.6mS
// DSP28x_usDelay(1600);//st7920要求等待1.6mS
}
else
{
delay(72);//st7920要求等待72uS
// DSP28x_usDelay(72);//st7920要求等待72uS
}
}
void LcdObj::SendData(char cData)
{
LcdDatH = cData;
LcdDatL = cData;
delay(72);//st7920要求等待72uS
// DSP28x_usDelay(72);//st7920要求等待72uS
}
void LcdObj::ClearBuffer(void)
{
unsigned char i, j;
for (i = 0;i < 4;i ++)
{
for (j = 0;j < 16; j ++)
{
Buffer[j] = ' ';
}
RowWriteEnable = 1;//允许此行刷新汉字显示
}
Row = 0;
Col = 0;
}
void LcdObj:: DisplayBuffer(void)
{
unsigned char i, j;
for (i = 0; i < 4; i ++)
{//4行汉字
if (RowWriteEnable)
{//允许此行刷新汉字显示
SendCommand(0x80 + (i & 1) * 16 + (i >> 1) * 8);//移动光标
for (j = 0; j < 16; j ++)
{//每行8个汉字16个字符
SendData(Buffer[j]);//刷新显示字符
}
RowWriteEnable = 0;//过后不允许此行刷新汉字显示
}
}
}
void LcdObj::SetDisplayPos(unsigned char row, unsigned char col)
{
Row = row & 0x03;//4行
Col = col & 0x0f;//16列
}
void LcdObj:: Display(const char *string)
{
char len, i;
len = strlen(string);
if ((Row < 4) && ((Col + len) <= 16))
{
if (len == 0)
{
while(Col < 16)
{
Buffer[Row][Col ++] = ' ';
}
}
else
for (i = 0; i < len; i ++) Buffer[Row][Col ++] = string;
RowWriteEnable[Row] = 1;//需要显示刷新
}
}
#include "main.h"
class SystemObj System;
class TimerObj Timer;//系统时间类
class LcdObj Lcd;
class KeyboardObj Keyboard;
int main(void)
{
Lcd.SetDisplayPos(0, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示12");
Lcd.SetDisplayPos(1, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示34");
Lcd.SetDisplayPos(2, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示56");
Lcd.SetDisplayPos(3, 0);//汉字定位到上行左端
Lcd.Display("汉字显示演示78");
EALLOW;
// PieCtrlRegs.PIEACK.all = 0xFFFF;//PIEACK_GROUP1;
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
EDIS;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
asm(" nop");
// Reset the watchdog counter
KickDog();
}
}
interrupt void ISRTimer0(void)
{
Lcd.DisplayBuffer();//定时刷新LCD显示(只刷新新行字符)
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
// PieCtrlRegs.PIEIFR1.bit.INTx7 = 1;
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}