在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3038|回复: 0

[原创] DSP281X之LCD12864 C++程序代码

[复制链接]
发表于 2008-5-22 22:24:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 cjsb37 于 2013-4-29 09:07 编辑

hotpower 发表于 2008-4-17 02:24 DSP 技术 ←返回版面

楼主: DSP281X之LCD12864 C++程序代码

//本程序在http://www.study-kit.com/list.asp?ProdId=NO052上通过测试
//HotPower@126.com 2008.4.17 2:28

#include "lcd.h"

LcdObj:cdObj(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:isplayBuffer(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:isplay(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;
}








您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-3-14 13:52 , Processed in 0.014318 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表