本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员  
 
×
 
#include <msp430x24x.h> 
#ifndef _HLCD_H_ 
#define _HLCD_H_ 
 
#define LCDSTD BIT1 //宏定义LCD接口 
#define LCDSCLK BIT2 
#define LCDCS BIT0 
 
void Lcd_Io(); 
void WriteBit(char B); 
void WriteByte(char B,char I); 
void LCD_init(void); 
void LCDWriteLine(int Line,unsigned int HZCode[10]); 
void Delay(); 
 
//------------------------对LCD所用的端口进行初始化------------------------ 
void Lcd_Io() 
{ 
 P2SEL&=~(BIT0+BIT1+BIT2);//5.0,5.1,5.127接LCD显示 
 P2DIR|=(BIT0+BIT1+BIT2);//5.0--CS,5.1--STD,5.2--SCLK 
  
 P2SEL&=~BIT4;//5.4接背光,初始为灭 
 P2DIR|=BIT4; 
 P2OUT&=~BIT4; 
} 
//---------------------------------延时函数----------------------------------- 
void Delay(unsigned int De) 
{ 
 while(De--); 
} 
 
//------------------------------LCD位书写函数------------------------------ 
//书写一位信息,对应时序图上CLK一个脉冲的操作 
void WriteBit(char B) 
{ 
 int De; 
 if(B!=0)P2OUT|=LCDSTD;//STD=1 
 else P2OUT&=~LCDSTD; 
  
 P2OUT|=LCDSCLK;//SCLK=1 
 De=18;while(De--); 
 P2OUT&=~LCDSCLK;//SCLK=0 
}  
 
//-----------------------------LCD字节书写函数----------------------------- 
//书写一个字节,用此函数可以向LCD写机内码位一个字节的字符,如果要书写机内码为 
//16位的字符,应该连续调用此函数两次 
void WriteByte(char B,char I) 
{ 
 int De,i; 
  
 P2OUT|=LCDCS;//片选有效CS=1 
  
 for(i=1;i<6;i++)WriteBit(1);//5个空脉冲,数据为1 
  
 WriteBit(0);//RW=0 
 De=15;while(De--); 
 WriteBit(I);//写指令还是数据? 
 De=15;while(De--); 
 WriteBit(0);//写一个0 
 De=15;while(De--); 
  
 WriteBit(B&0x0080);//写第7位 
 De=15;while(De--); 
 WriteBit(B&0x0040);//写第6位 
 De=15;while(De--); 
 WriteBit(B&0x0020);//写第5位 
 De=15;while(De--); 
 WriteBit(B&0x0010);//写第4位 
 De=15;while(De--); 
 
 for(i=1;i<5;i++) WriteBit(0);//4个空脉冲,数据为0 
 De=15;while(De--); 
 
 WriteBit(B&0x0008);//写第3位 
 De=15;while(De--); 
 WriteBit(B&0x0004);//写第2位 
 De=15;while(De--); 
 WriteBit(B&0x0002);//写第1位 
 De=15;while(De--); 
 WriteBit(B&0x0001);//写第0位 
 De=15;while(De--); 
 
 for(i=1;i<5;i++) WriteBit(0);//4个空脉冲,数据为0 
 De=15;while(De--); 
  
 P2OUT&=~LCDCS;//片选无效 CS=0 
} 
 
//-------------------------------LCD初始化函数-------------------------------- 
void LCD_init(void) 
{  
 Lcd_Io(); 
 Delay(3);  
 WriteByte(0x30,0);Delay(2);//8比特控制,基本指令集 
 WriteByte(0x01,0);Delay(2);//清屏 
 WriteByte(0x06,0);Delay(2);//光标自动右移一位,整屏不移动 
 WriteByte(0x0c,0);Delay(2); 
} 
 
//-------------------------------LCD行书写函数-------------------------------- 
//对LCD一行进行写操作,入口参数Line为写操作目标行,HZCode为一行字符的机内码 
void LCDWriteLine(int Line,unsigned int HZCode[8]) 
{ 
 int i; 
 switch (Line) 
 { 
 case 1:Line=0x80;break; 
 case 2:Line=0x90;break; 
 case 3:Line=0x88;break; 
 case 4:Line=0x98;break; 
 } 
 WriteByte(Line,0); 
 Delay(1000); 
 for (i=0;i<8;i++) 
 { 
 WriteByte((HZCode&0xff00)>>8,1); 
 WriteByte(HZCode&0x00ff,1); 
 } 
} 
 
#endif 
#define uchar unsigned char 
void int_clk() 
{ 
 uchar i;  
 BCSCTL1&=~XT2OFF;//XT 
 BCSCTL2|=SELM1+SELS; 
 do 
 { 
 IFG1 &=~OFIFG; 
 for(i=0;i<100;i++) 
  
 _NOP(); 
 } 
 while((IFG1&OFIFG)!=0); 
 IFG1&=~OFIFG; 
} 
main() 
{ 
 WDTCTL=WDTPW+WDTHOLD;//关闭看门狗 
 int Line=1; 
 unsigned int HZCode[8]={0xd611,0xd611,0xd611,0xd611,0xd611,0xd611,0xd611,0xd611}; 
 int_clk(); 
 LCD_init(); 
 Lcd_Io(); 
 LCDWriteLine(Line,HZCode); 
 
} 
 |