zoukankan      html  css  js  c++  java
  • LCD显示--Ht1621b芯片显示屏驱动

    Ht1621b芯片显示屏驱动


    关于HT1621b芯片的具体信息能够參考数据手冊上的内容:百度文库HT1621b中文资料

    CS : 片选输入接一上拉电阻当/CS 为高电平读写HT1621的数据和命令无效串行接口电路复位当/CS 为低电平和作为输入时读写HT1621的数据和命令有效.

    WR : WRITE脉冲输入接一上拉电阻在/WR 信号的上升沿 DATA线上的数据写到HT1621.

    DATA : 外接上拉电阻的串行数据输入/输出.


    下面为芯片驱动程序(STM8单片机):

    #include "stm8s.h"
    #include "global.h"
    
    /* Private typedef -----------------------------------------------------------*/
    /* Private define ------------------------------------------------------------*/
    //显示芯片HT1621引脚定义
    #define HT1621_CS_PORT                GPIOC
    #define HT1621_CS_PIN                 GPIO_PIN_7
    #define Ht1621CsHigh                  (HT1621_CS_PORT->ODR |= (u8)(HT1621_CS_PIN))
    #define Ht1621CsLow                   (HT1621_CS_PORT->ODR &= (u8)(~HT1621_CS_PIN))
    
    #define HT1621_WR_PORT                GPIOC
    #define HT1621_WR_PIN                 GPIO_PIN_6
    #define Ht1621WrHigh                  (HT1621_WR_PORT->ODR |= (u8)(HT1621_WR_PIN))
    #define Ht1621WrLow                   (HT1621_WR_PORT->ODR &= (u8)(~HT1621_WR_PIN))
    
    #define HT1621_DATA_PORT              GPIOC
    #define HT1621_DATA_PIN               GPIO_PIN_5
    #define Ht1621DataHigh                (HT1621_DATA_PORT->ODR |= (u8)(HT1621_DATA_PIN))
    #define Ht1621DataLow                 (HT1621_DATA_PORT->ODR &= (u8)(~HT1621_DATA_PIN))
    
    //LCD屏背光PWM设定
    #define BLACK_LIGHT_PORT               GPIOD
    #define BLACK_LIGHT_PIN                GPIO_PIN_3
    #define LedPwmDuty(A)                  TIM2->CCR2H = (u8)((A)>> 8);TIM2->CCR2L = (u8)(A); 
    #define LedOn()                        TIM2->CCER1 |= TIM2_CCER1_CC2E  
    #define LedOff()                       TIM2->CCER1 &= (~TIM2_CCER1_CC2E) 
    
    #define  COMMAND_CODE                0x80  //命令码
    #define  WRITE_DATA_CODE             0xa0  //写命令
    #define  READ_DATA_CODE              0xc0  //读命令
    #define  DISPLAY_BEGIN_ADDR          (0X0F << 2) //显示起始地址
    #define  SYS_EN                      0x02
    #define  RC_256K                     0x30
    #define  BIAS_13                     0x52
    #define  TONE_ON                     0x12  //打开声音输出
    #define  TONE_OFF                    0x10
    #define  TONE_2K                     0xc0
    #define  TONE_4K                     0x80
    #define  LCD_ON                      0x06          
    
    /* Private variables ---------------------------------------------------------*/
    void Ht1621_WriteCommand(uint8_t Cmd);
    void Ht1621_WriteNBit(uint8_t BitCnt, uint8_t wData);
    /* Public functions ----------------------------------------------------------*/
    void Ht1621_Init(void);
    void Ht1621_WriteData(const uint8_t *wDataBuf);
    void Ht1621_BuzzerControl(uint8_t RunFlag);
    
    
    /*******************************************************************************
    函数:延时函数 ms 
    參数: 
    返回值:无
    *******************************************************************************/
    void Ht1621_Delay(uint8_t ms)
    {
       unsigned short jj;
       for (jj = 1; jj <= ms; jj++)
       {
          nop();
       }
    }
    
    /*******************************************************************************
    函数:HT1621初始化
    參数: 
    返回值:无
    *******************************************************************************/
    void Ht1621_Init(void)
    {  
       Ht1621_WriteCommand(SYS_EN);   //SYS_EN 打开系统振荡器
       Ht1621_Delay(5);
       
       Ht1621_WriteCommand(RC_256K);   //RC_256K 系统时钟源 片内RC振荡器
       Ht1621_Delay(5);
       
       Ht1621_WriteCommand(BIAS_13);  //BIAS13 4个公共口 
       Ht1621_Delay(5);
       
       Ht1621_WriteCommand(TONE_4K);  //TONE_2KC0  TONE_4K80 
       Ht1621_Delay(5);
       
       Ht1621_WriteCommand(LCD_ON);   //LCD_ON 打开LCD偏压发生器
       Ht1621_Delay(5);
    }
    
    
    /*******************************************************************************
    函数:HT1621 写一字节数据
    參数: 写数据的为位数 和 数据
    返回值:无
    *******************************************************************************/
    void Ht1621_WriteNBit(uint8_t wData , uint8_t BitCnt)
    {
       uint8_t i;
       
       for(i=0; i< BitCnt; i++)
       {
          Ht1621WrLow;
          Ht1621_Delay(2);
          
          if((wData << i) & 0x80)
          {
             Ht1621DataHigh;
          }
          else 
          {
             Ht1621DataLow;
          }
          Ht1621_Delay(2);
          
          Ht1621WrHigh;
          Ht1621_Delay(2);
       }
    }
    
    /*******************************************************************************
    函数:HT1621 写数据操作(连续写  3位写操作命令+6位地址+ ...数据)
    參数: 写数据指针
    返回值:无
    *******************************************************************************/
    void Ht1621_WriteData(const uint8_t *wDataBuf)
    {
       uint8_t i;
          
       Ht1621CsLow;
       Ht1621_Delay(2);
          
       Ht1621_WriteNBit(WRITE_DATA_CODE, 3);
       Ht1621_WriteNBit(DISPLAY_BEGIN_ADDR, 6);            //TODO: 20140820  hzg  注意要相应原理图上的起始地址
       
       for(i=0; i<12; i++)                                 
       {
        Ht1621_WriteNBit(wDataBuf[i], 8);  
       }
       
       Ht1621CsHigh;
       Ht1621_Delay(2);
    }
    
    /*******************************************************************************
    函数:HT1621 写命令操作(12位命令数据)
    參数: 命令值
    返回值:无
    *******************************************************************************/
    void Ht1621_WriteCommand(uint8_t Cmd)
    {
       Ht1621CsLow;
       Ht1621_Delay(2);
       
       Ht1621_WriteNBit(COMMAND_CODE, 4);       
       Ht1621_WriteNBit(Cmd, 8);
       
       Ht1621CsHigh;
       Ht1621_Delay(2);
    }
    
    /*******************************************************************************
    函数:HT1621 蜂鸣器输出控制(12位命令数据)
    參数: 开关标志
    返回值:无
    *******************************************************************************/
    void Ht1621_BuzzerControl(uint8_t RunFlag)
    {
       (RunFlag == 0)?Ht1621_WriteCommand(TONE_OFF):Ht1621_WriteCommand(TONE_ON);
    }
    


  • 相关阅读:
    Javascript MVC学习杂记3
    Backbone.js 0.9.2 源码分析收藏
    Javascript MVC学习杂记2
    Javascript MVC学习杂记1
    C语言string.h中常用字符函数介绍
    10点网页设计要注意的细节
    js日期函数
    结合回调函数介绍下泛型函数
    【转载】互斥量和信号量的区别
    设计模式之Singleton
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4205721.html
Copyright © 2011-2022 走看看