打印

HT1621驱动LCD问题

[复制链接]
2254|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lby2037|  楼主 | 2008-7-17 15:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用AVR单片机控制HT1621驱动LCD,程序烧写后LCD只能全屏都显示,不能够通过更改显存数组中的值来控制LCD中某一段的显示的内容,也不能清屏,请给位帮我看看这个程序是否有问题,谢谢!




#include <iom48v.h>          //AVR头文件

typedef unsigned char            uint8;
typedef unsigned int             uint16;
typedef unsigned long int        uint32;
typedef signed char              sint8;
typedef signed int               sint16; 
typedef signed long int          sint32; 


//Lcd显示定义 

//HT1621的WR引脚对应AVR的PORT口的PIN位置,在具体应用中要修改X
#define LCD_wr             3                

//HT1621的DATA引脚对应AVR的PORT口的PIN位置,在具体应用中要修改X 
#define LCD_data         4                 

//HT1621的CS引脚对应AVR的PORT口PIN的位置,在具体应用中要修改X  
#define LCD_cs             2                

//HT1621的WR引脚对应AVR的PORT口, 在具体应用中要修改X 
#define LCDWRPORT    PORTC         

//HT1621的DATA引脚对应于AVR的PORT口,在具体应用中要修改X
#define LCDDATAPORT  PORTC       

 //HT1621的CS引脚对应于AVR的PORT口,在具体应用中要修改X
#define LCDCSPORT     PORTC        

 //定义LCD显示缓冲区的空间
#define BuffSize 32 

#define SYSEN      0x01
#define LCDOFF     0x02
#define LCDON      0x03
#define BAIS1_2    0X28
#define BAIS1_3    0X29
#define RC256K     0x18
#define TONEON     0x09
#define TONEOFF    0x08
#define TONE4K     0x40
#define TONE2K     0x60 

#define NOP        #asm("nop")                 

//将DATA的高X位写入HT1621
 void SendHBit1621(uint8 data,uint8 x); 

//将DATA的低X位写入HT1621
 void SendLBit1621(uint8 data,uint8 x); 

//写入命令
 void PutLcdCommand(uint8 Command); 

//写入1个地址
 void PutLcdOnedata(uint8 ADD,uint8 DATA); 

//显示LCD缓冲区内容 从start~~end<BuffSize
 void PutLcdAllData(uint8 start,uint8 end); 

//对LCD缓冲区写相同数
 void PutLcdClear(uint8 start,uint8 end,uint8 x); 

//LCD初始化  
 void LCDInit(void);  

//LCD缓冲区
// uint8 LcdBuff[BuffSize]; 

uint8 LcdBuff[BuffSize]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0,0,0,0,0,0,0,0,0,0,
                         0,0,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF};  
 
 
//------------------------------------------------------------------------------ 
//DATA的高X位写入HT1621
void SendHBit1621(uint8 data,uint8 x)
    {
     uint8 i;
     for (i=0;i<x;i++)
        {
         //LCDWRPORT&=(0<<LCD_wr);
         LCDWRPORT&=~(1<<LCD_wr);
         NOP;//
         NOP;//
         NOP;//
         if ((data&0x80)==0){LCDDATAPORT&=~(1<<LCD_data);}
         else {LCDDATAPORT|=(1<<LCD_data);}
         NOP;
         
         NOP;//
         NOP;//
         LCDWRPORT|=(1<<LCD_wr);
         NOP;
         
         NOP;//
         NOP;//
         data<<=1;
         NOP;//
         NOP;//
        }  
     } 
//------------------------------------------------------------------------------
//将DATA的低X位写入HT1621
void SendLBit1621(uint8 data,uint8 x)
    {
     uint8 i;
     for (i=0;i<x;i++)
         {
          LCDWRPORT&=~(1<<LCD_wr);
          NOP;//
          NOP;//
          NOP//
          if ((data&0x01)==0){LCDDATAPORT&=~(1<<LCD_data);}
          else{LCDDATAPORT|=(1<<LCD_data);}
          NOP;
          
          NOP;//
          NOP;//
          LCDWRPORT|=(1<<LCD_wr);
          NOP;
          
          NOP;//
          NOP;//
          data>>=1;
          NOP;//
          NOP;//
       }
     } 
//------------------------------------------------------------------------------
//写入命令
void PutLcdCommand(uint8 Command)
    {
    LCDCSPORT&=~(1<<LCD_cs);       //LCD数据命令有效 
    NOP;//
    NOP;//
    SendHBit1621(0x80,3);   //写入标志码"100"
    SendHBit1621(Command,9);//写入9位数据,前8位为Command命令
                              //后一位任意 
    NOP;//
    NOP;//                          
    LCDCSPORT|=(1<<LCD_cs);      //LCD数据命令无效
    NOP;//
    NOP;//
   } 
//------------------------------------------------------------------------------
//写入1个地址
void PutLcdOnedata(uint8 ADD,uint8 DATA)
    {
    LCDCSPORT&=~(1<<LCD_cs);       //LCD数据命令有效 
    NOP;//
    NOP;//
    SendHBit1621(0xa0,3);   //写入标志码"101"
    SendHBit1621(ADD<<2,6); //写入6位地址
    SendLBit1621(DATA,4);   //写入4位数据 
    NOP;//
    NOP;//
    LCDCSPORT|=(1<<LCD_cs);       //LCD数据命令无效
    NOP;//
    NOP;//
   } 
//------------------------------------------------------------------------------
//显示LCD缓冲区内容 Disp_LcdBuff[starts]~Disp_LcdBuff[end]
void PutLcdAllData(uint8 start,uint8 end)
     {               
      uint8 i;
      LCDCSPORT&=~(1<<LCD_cs);       //LCD数据命令有效
      NOP;//
      NOP;//
      SendHBit1621(0xa0,3);   //写入标志码"101"
      SendHBit1621(0x00,6);   //写入6位起始地址
      for (i=start;i<=end;i++){
           SendLBit1621(LcdBuff,4);}//写入4位数据
      NOP;//
      NOP;//           
      LCDCSPORT|=(1<<LCD_cs);       //LCD数据命令无效
      NOP;//
      NOP;//
     } 
//------------------------------------------------------------------------------
//对LCD缓冲区写相同数
void PutLcdClear(uint8 start,uint8 end,uint8 x)
    {      
     uint8 i;
     for (i=start;i<=end;i++)
          {LcdBuff=x;}
    } 
//------------------------------------------------------------------------------
//LCD初始化  
void LCDInit(void)
     {                                                     
 PutLcdCommand(RC256K);
 PutLcdCommand(SYSEN);        //打开系统振荡器
 PutLcdCommand(BAIS1_3);      //设置偏压和占空比,BAIS1_3为1/3偏压4个公共口
 PutLcdCommand(TONE4K);     
 PutLcdCommand(LCDON);        //打开偏压发生器 LCDON
     } 

//------------------------------------------------------------------------------
    //端口初始化
void port_init(void)
{
PORTC = (1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5)|(1<<PC6);
    DDRC  = (1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5)|(0<<PC6);
}   
//------------------------------------------------------------------------------
     
void main(void)
       {
        //AVR_CPU初始化函数
        port_init();
        LCDInit();//HT1621初始化 
        while(1)
               {
                 //缓冲器赋值函数
                 PutLcdAllData(0,BuffSize);//显示LCD缓冲器内容
               }
       } 

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

9

帖子

0

粉丝