1460 views|0 replies

3836

Posts

19

Resources
The OP
 

msp430g2553 displays source program on LCD1602 [Copy link]

The MCU source program is as follows:
#include<msp430.h> /* Necessary operation: Connect 1602 correctly */
#define LCD_OUT P1OUT //Define the data port of LCD1602 as P1
#define CLR_RS P2OUT&=~BIT0; //Set P2.3 bit to zero, that is, set RS to zero
#define SET_RS P2OUT|=BIT0; //Set P2.3 bit to one, that is, set RS to one
#define CLR_RW P2OUT&=~BIT1; //Set P2.4 bit to zero, that is, set RW to zero
#define SET_RW P2OUT|=BIT1; //Set P2.4 bit to one, that is, set RW to one
#define CLR_EN P2OUT&=~BIT2; //Set P2.5 bit to zero, that is, set EN to zero
#define SET_EN P2OUT|=BIT2; //Set P2.5 bit to one, that is, set EN to one
unsigned char busy; //1602 busy flag
void busy_1602(void) //Query busy flag signal program
{
do
{
CLR_EN;
SET_RW;
CLR_RS;
busy=LCD_OUT;
SET_EN;
_delay_cycles(1000);
CLR_EN;
_delay_cycles(1000);
}
while(busy&&0x10==1);
}
void LCD_Write_com(unsigned char com) //Write instruction to LCM program
{
busy_1602();
CLR_EN;
CLR_RW;
CLR_RS;
LCD_OUT=com;
_nop();
SET_EN;
_nop();
CLR_EN;
}
void lcd_write_data(unsigned char data) //Write data to LCM program
{
busy_1602();
CLR_EN;
CLR_RW;
SET_RS;
LCD_OUT=data;
_nop();
SET_EN;
_nop();
CLR_EN;
}
void init_1602(void) //Start the LCM program
{
LCD_Write_com(0x38);
LCD_Write_com(0x0c);
LCD_Write_com(0x06);
}
void lcd_clear(void) //Clear screen function
{
LCD_Write_com(0x01);
_nop();
_nop();
p();
}
void lcd_write_string(unsigned char x, unsigned char y, unsigned char *s) //String display function
{
if (y==0)
{
LCD_Write_com(0x80 + x);
}
else
{
LCD_Write_com(0xC0 + x);
}
while(*s)
{
lcd_write_data(*s);
s++;
}
}

/* //字符显示函数 */
void lcd_write_char(unsigned char x,unsigned char y, unsigned char Data)
{
if(y==0)
{
LCD_Write_com(0x80 + x);
}
else
{
LCD_Write_com(0xC0 + x);
}
lcd_write_data(Data);
}
void main(void) //主程序开始
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR=0xFF;
P2DIR=0xFF;
init_1602();
while(1)
{
lcd_write_string(0,0,"WARRNING!!!");

}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list