⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsp281x之lcd12864 c++程序代码 .txt

📁 DSP281X之LCD12864 C++程序代码 。
💻 TXT
字号:
DSP281X之LCD12864 C++程序代码 


#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[i][j] = ' ';
        }
        RowWriteEnable[i] = 1;//允许此行刷新汉字显示
    }
    Row = 0;
    Col = 0;
}

void LcdObj::DisplayBuffer(void)
{
unsigned char i, j;
      for (i = 0; i < 4; i ++) 
      {//4行汉字
        if (RowWriteEnable[i]) 
        {//允许此行刷新汉字显示
              SendCommand(0x80 + (i & 1) * 16 + (i >> 1) * 8);//移动光标
              for (j = 0; j < 16; j ++) 
              {//每行8个汉字16个字符
                SendData(Buffer[i][j]);//刷新显示字符
              }
              RowWriteEnable[i] = 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[i];
        RowWriteEnable[Row] = 1;//需要显示刷新
      }
}

#i nclude "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;
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -