技术源于采集,成功源于倒塌!

  • 《HotPower的水潭》21IC主站
  • 《HotPower的水潭》EDN副站
  • 《HotPower的水潭》dianyuan副站
  • 《HotPower的水潭》MCUBLOG副站
  • 设为首页加入收藏联系匠人管理入口21IC首页21IC博客21IC社区侃单片机回复的贴参与的贴

    天气预报
    菜农日历

    绿色蔬菜

    载入中...

    农家信息

    载入中...

    水潭流量
    (2006-10-21开始)

     
     

    芯片专题

    器件专题

    软件专题

    硬件专题

    综合专题

    项目专题

    原创专题

    LCD LED
    按键 触摸键
    E2PROM
    电池 电机
    电阻 电容 电感

    滤波算法
    串行通讯

    I2C
    红外遥控
    充电技术

    匠人手记
    匠人夜话
    网络心路

    DSP281X之LCD12864 C++程序代码
    雁塔菜农 发表于 2008-4-17 2:47:00

    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

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

    * - 本贴最后修改时间:2007-6-2 2:50:09 修改者:hotpower

    http://www.study-kit.com/list.asp?ProdId=NO052
    点击看大图


    阅读全文 | 回复(0) | 引用通告 | 编辑
     


    发表评论:
    载入中...

    菜贩子摊位 [投放]

     



    站内搜索

    站外搜索


    百度  google
    mp3  歌词 
    图片  FLASH 
    知道  文档
    新闻  词典 
    地图  mp3 
    软件  天网 
    雅虎  爱问 
    搜狗  讯雷 
    网讯  华军 
    天空 

    21IC器件搜索
    匠人代理商品

    学习板、开发板、编程器、下载器、仿真器(查看详情……)

    匠人广告位 [投放]

    新鲜蔬菜

    匠人写书近况

    匠人团队精华

    匠人往日酷贴

    社区热点 更多>>

    载入中...

    2007年匠人的新目标是写书。书名:《匠人手记——一个单片机工作者的实践与思考》。
    感谢各位网友的关注、支持和鼓励!(点击查看写书详情和近况)

     

    匠人写书调查

    匠人栏目调查

    匠人原创

    农友评论

    农友留言

    载入中...

    载入中...



    大千八卦

    菜地友情连接

    新浪新闻:
    新浪财经:
    AK58新闻:
    新浪股票:
    新浪股票:
    证券之星:

     [更多酷站连接]

     

     

    [欢迎交换连接]

    [百宝箱之与非门分舵]

    [电脑圈圈的家当]

    [柔月阁]

     

     

     

     

     

    MCU博客-中国电子工程师博客网 

    大学生电子网 

     

     

     

     

     

    《HotPower的水潭》