TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430 HT1621液晶驱动程序

MSP430的HT1621液晶驱动程序,C源码,IAR开发平台,调试成功。

灰小子:

//—————————————————————————————–// msp430g2553 ht1621_lcd test//—————————————————————————————–#include  "msp430g2553.h"#include <stdio.h>

#define uint  unsigned int#define uchar unsigned char

#define  BIAS     0x52             //0b1000 0101 0010  1/3duty 4com #define  SYSDIS   0X00             //0b1000 0000 0000  关振系统荡器和LCD偏压发生器 #define  SYSEN    0X02             //0b1000 0000 0010 打开系统振荡器 #define  LCDOFF   0X04             //0b1000 0000 0100  关LCD偏压 #define  LCDON    0X06             //0b1000 0000 0110  打开LCD偏压 #define  XTAL     0x28             //0b1000 0010 1000 外部接时钟 #define  RC256    0X30             //0b1000 0011 0000  内部时钟 #define  TONEON   0X12             //0b1000 0001 0010  打开声音输出 #define  TONEOFF  0X10             //0b1000 0001 0000 关闭声音输出 #define  WDTDIS1  0X0A            //0b1000 0000 1010  禁止看门狗

////////////////////////////////////////////////////////////////////////////////

void Ht1621_CS_0() { P2OUT &= ~0x20;}  // define P2.5 —> CSvoid Ht1621_CS_1() { P2OUT |= 0x20;}

void Ht1621_WR_0() { P2OUT &= ~0x10;}  // define P2.4 —> WRvoid Ht1621_WR_1() { P2OUT |= 0x10;}

void Ht1621_DO_0() { P2OUT &= ~0x08;}  // define P2.3 —> DATvoid Ht1621_DO_1() { P2OUT |= 0x08;}

////////////////////////////////////////////////////////////////////////////////

//—————————————————————————————–//函数名称:Delay()//功    能:延时子程序//—————————————————————————————–void Delay(uchar us)  //5,7,9 {   while(–us);  }

//—————————————————————————————–//函数名称:Delayms()//—————————————————————————————–void Delayms(uint ims) {   uint i,j;     for(i=0;i<ims;i++)       for(j=0;j<65;j++) { Delay(1); }}

//—————————————————————————————–//函数名称:Ht1621Wr_Data()  //—————————————————————————————–void Ht1621Wr_Data(uchar Data,uchar cnt) {   uchar i;   for (i=0;i<cnt;i++)    {       Ht1621_WR_0();    if((Data & 0x80)==0x80) { Ht1621_DO_1(); }    else { Ht1621_DO_0(); }    Ht1621_WR_1();     Data<<=1;     } } //—————————————————————————————–//函数名称:void Ht1621WrCmd(uchar Cmd) //—————————————————————————————–void Ht1621WrCmd(uchar Cmd) {    Ht1621_CS_0();   //CS   Ht1621Wr_Data(0x80,4);               //写入命令标志100    Ht1621Wr_Data(Cmd,8);                //写入命令数据    Ht1621_CS_1();} //—————————————————————————————–//函数名称:void Ht1621WrOneData(uchar Addr,uchar Data) //—————————————————————————————–void Ht1621WrOneData(uchar Addr,uchar Data) {   Ht1621_CS_0();    Ht1621Wr_Data(0xa0,3);              //写入数据标志101    Ht1621Wr_Data(Addr<<2,6);           //写入地址数据    Ht1621Wr_Data(Data<<4,4);           //写入数据    Ht1621_CS_1();   } //—————————————————————————————–//函数名称:void Ht1621WrAllData() //—————————————————————————————–void Ht1621WrAllData(void) {    uchar i;

   Ht1621_CS_0();   Ht1621Wr_Data(0xa0,3);            //写入数据标志101    Ht1621Wr_Data(0x00<<2,6);         //写入地址数据    for (i=0;i<16;i++) { Ht1621Wr_Data(0x00,8); }    Ht1621_CS_1();   } //—————————————————————————————–//函数名称:void Ht1621_Init(void)  //—————————————————————————————–void Ht1621_Init(void) {    Ht1621_CS_0();   Ht1621_WR_0();   Ht1621_DO_0();     Delay(100);                     //延时使LCD工作电压稳定    Ht1621WrCmd(BIAS);    Ht1621WrCmd(RC256);              //使用内部振荡器    Ht1621WrCmd(SYSDIS);    Ht1621WrCmd(WDTDIS1);    Ht1621WrCmd(SYSEN);    Ht1621WrCmd(LCDON); } //—————————————————————————————–//函数名称:Initial()//功    能:初始化子程序//—————————————————————————————–void Initial(void){  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer  P1DIR = 0xFF;                             // All P1.x outputs  P1OUT = 0;                                // All P1.x reset  P2DIR = 0xFF;                             // All P2.x outputs  P2OUT = 0;                                // All P2.x reset}void write_num(unsigned char i,unsigned char data){  switch(i)  {   case 0:    {    switch(data)    {      case 0:       {        Ht1621WrOneData(0,0x0e);        Ht1621WrOneData(1,0x0b);      }break;      case 1:       {        Ht1621WrOneData(0,0×06);      }break;      case 2:       {        Ht1621WrOneData(0,0x0c);        Ht1621WrOneData(1,0×07);      }break;      case 3:       {        Ht1621WrOneData(0,0x0e);        Ht1621WrOneData(1,0×05);      }break;      case 4:       {        Ht1621WrOneData(0,0×06);        Ht1621WrOneData(1,0x0c);      }break;      case 5:       {        Ht1621WrOneData(0,0x0a);        Ht1621WrOneData(1,0x0d);      }break;      case 6:       {        Ht1621WrOneData(0,0x0a);        Ht1621WrOneData(1,0x0f);      }break;      case 7:       {        Ht1621WrOneData(0,0x0e);      }break;      case 8:       {        Ht1621WrOneData(0,0x0e);        Ht1621WrOneData(1,0x0f);      }break;      case 9:       {        Ht1621WrOneData(0,0x0e);        Ht1621WrOneData(1,0x0d);      }break;      case 10:      {        Ht1621WrOneData(0,0×01);      }      defualt:break;     }    }break;  case 1: break;  }}

void write_du_shudian(unsigned char j,unsigned char data){  switch(data)  {   case 0x01:   {    switch(j)    {      case 0:       {        Ht1621WrOneData(0,0×01);      }break;      case 2:       {        Ht1621WrOneData(2,0×02);      }break;      case 4:       {        Ht1621WrOneData(4,0×01);      }break;      case 6:       {        Ht1621WrOneData(6,0×01);      }break;      case 8:       {        Ht1621WrOneData(0,0×01);      }break;      case 10:       {        Ht1621WrOneData(10,0×01);      } defualt:break;    }   }break; }}

void clear(){  Ht1621_Init();          Delay(100);            Ht1621WrAllData();  }//—————————————————————————————–//函数名称:main()//—————————————————————————————–void main(void){ // uchar i,j,t;

  Initial();            //初始化子程序  Ht1621_Init();        //上电初始化LCD   Delay(100);          //延时一段时间   Ht1621WrAllData();       while(1)  {      Ht1621WrOneData(10,0×01);//   write_num(0,0);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,1);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,2);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,3);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,4);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,5);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,6);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,7);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,8);//   Delayms(1000);//   Ht1621_Init();        //上电初始化LCD //   Delay(100);          //延时一段时间 //   Ht1621WrAllData(); //   write_num(0,9);//   Delayms(1000);   //   Ht1621WrOneData(0,0×02);//   Ht1621WrOneData(0,0×04);//   Ht1621WrOneData(0,0×08);//   Ht1621WrOneData(1,0×01);//   Ht1621WrOneData(1,0×02);//   Ht1621WrOneData(1,0×04);//   Ht1621WrOneData(1,0×08);////   //   Ht1621WrOneData(2,0×01);//   Ht1621WrOneData(3,0×01); // while(1);//      for(i=0;i<16;i++)        //SEG0-SEG31//       { //       t=0x01; //       for(j=0;j<4;j++)    //COM0 – COM3//        { //         Ht1621WrOneData(i,t); //         t<<=1; //         t++;         //         Delayms(10);//        } //    }    } }

 

 

 

 

 

 

Susan Yang:

谢谢分享!

赞(0)
未经允许不得转载:TI中文支持网 » MSP430 HT1621液晶驱动程序
分享到: 更多 (0)