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

MSP430G2553 LCD12864静态显示程序【分享】

#include <msp430g2553.h>#define SENDCOMM 0XF8     //0XF1000

#define SENDDATA 0XFA     //0XF1010

#define E_CLK_0  P1OUT &= ~BIT6

#define E_CLK_1  P1OUT |=BIT6

#define RW_SID_0  P1OUT &= ~BIT4

#define RW_SID_1  P1OUT |= BIT4

void LCD_send_byte(unsigned char a);

unsigned char LCD_read_byte(void);

void LCD_comm(unsigned char comm);void LCD_setxy(unsigned char x,unsigned char y);void LCD_WriteStr(unsigned char dis_addr_x,unsigned char dis_addr_y,char* str);

void LCD_init(void);/*********************主函数************************/

void main() {WDTCTL = WDTPW + WDTHOLD;

 P1DIR = 0xFF;

P1OUT = 0x00;

LCD_init();LCD_WriteStr(3,1,"^_^");

LCD_WriteStr(3,2,"哟西~!!");

while(1);

}/****************发送字节函数*****************/

void LCD_send_byte(unsigned char a) {unsigned char i; for(i=8;i>0;i–)     {   if(a&(0x01<<(i-1)))     RW_SID_1;    else    RW_SID_0;   _delay_cycles(100);    E_CLK_1;   _delay_cycles(100);    E_CLK_0;   _delay_cycles(100);     } }/****************读取字节函数*****************/

 unsigned char LCD_read_byte(void) {

unsigned char i,dat=0; for(i=8;i>0;i–) {   E_CLK_1;   _delay_cycles(100);    if(RW_SID_1)    dat|=(0x01<<(i-1));    E_CLK_0;   _delay_cycles(100); }return dat; }/****************写指令函数*****************/

void LCD_comm(unsigned char comm) {unsigned char temp; _delay_cycles(100);LCD_send_byte(SENDCOMM);

 temp=comm&0XF0;

LCD_send_byte(temp);temp=((comm&0X0F)<<4)&0XF0;

 LCD_send_byte(temp);

 _delay_cycles(100); }

/****************写数据函数*****************/ void LCD_data(unsigned char lcd_data) //写数据 {unsigned char temp;

 _delay_cycles(100);LCD_send_byte(SENDDATA);

 temp=lcd_data&0xf0;

 LCD_send_byte(temp);temp=(lcd_data&0X0F)<<4;

LCD_send_byte(temp);

 _delay_cycles(100); }

/****************  设置显示坐标函数*****************/void LCD_setxy(unsigned char x,unsigned char y)  //设置显示位置    X(1~16),Y(1~4)

 {switch(y) {   case 1:LCD_comm(0X7F+x);    break;   case 2:LCD_comm(0X8F+x);

    break;   case 3:LCD_comm(0X87+x);    break;   case 4:LCD_comm(0X97+x);    break; } }

/****************显示函数函数*****************/void LCD_WriteStr(unsigned char dis_addr_x,unsigned char dis_addr_y,char* str)// 在指定位置显示字符串

 {    unsigned char LCD_temp;    LCD_setxy(dis_addr_x,dis_addr_y);    

LCD_temp=*str;    while(LCD_temp != 0x00)    

 {        LCD_data(LCD_temp);  //LCD_WriteStr(1,1,"方向设定:正转");       

  LCD_temp=*(++str);     } }/****************LCD初始化函数*****************/ void LCD_init(void) {_delay_cycles(500);;LCD_comm(0x30);//一次送8位数据LCD_comm(0x0C);//整体显示,游标off,游标位置off

 LCD_comm(0x01);//清DDRAMLCD_comm(0x02);//DDRAM地址归位LCD_comm(0x80);//设定DDRAM 7位地址000,0000到地址计数器AC }

Susan Yang:

谢谢分享!

赞(0)
未经允许不得转载:TI中文支持网 » MSP430G2553 LCD12864静态显示程序【分享】
分享到: 更多 (0)