MSP430 MCU Practice --- Digital LCD-1602 Display

Publisher:静心悠然Latest update time:2017-01-03 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/**************************************************

* LCD1602 display
* cpu:AVRmega16
*
* Description: 4-line data width, operate Lcd1602
* The first line on the LCD1602 screen displays www.goodmcu.cn 
* The second line displays 13652037001
* If there is no display, please press the reset button and try several more times
*
* Debugging successful (the problem is mainly because the 2K grounding resistor of LCD pin 3 V0 is not connected properly)
*
* Hardware circuit: MSP430F135 core experiment board-Type I
* Hardware connection: 

* MSP430 and LCD connection information 
* LCD1602, 4-bit interface, that is, using D4-D7 data port, D0-D3 is not connected to MCU
* PIN1 --> Ground
* PIN2 --> VCC (must be connected to +5V)
* PIN3 --> 2K resistor --> Ground (must be connected properly, otherwise there will be no display)
* PIN4 --> RS --> P5.0
* PIN5 --> R/W --> GND
* PIN6 --> EN --> P5.1
* PIN7 --> D0 not connected
* PIN8 --> D1 not connected
* PIN9 --> D2 not connected
* PIN10 --> D3 not connected
* PIN11 --> D4 --> P4.4
* PIN12 --> D5 --> P4.5
* PIN13 --> D6 --> P4.6
* PIN14 --> D7 --> P4.7
* PIN15 --> VCC (must be connected to +5V, if you don't want backlight, you can leave it unconnected)
* PIN16 --> Ground

* Debugger: MSP430FET full series JTAG emulator
* Debug software: IAR Embedded Workbench Version: 3.41A Compilation
******************************************************/

#include  
#include 

////Pin definition////////////////////////////////////////////////////////////////////////
#define LCD_EN_PORT P5OUT //The following two should be set to the same port 
#define LCD_EN_DDR P5DIR 
#define LCD_RS_PORT P5OUT //The following two should be set to the same port 
#define LCD_RS_DDR P5DIR 
#define LCD_DATA_PORT P4OUT //The following 3 should be set to the same port 
#define LCD_DATA_DDR P4DIR //Be sure to use the high 4 bits 
#define LCD_RS BIT0
#define LCD_EN BIT1
#define LCD_DATA BIT4|BIT5|BIT6|BIT7

////预定义函数//////////////////////////////////////////////////////////////////
void LCD_init(void); 
void LCD_en_write(void); 
void LCD_write_command(unsigned char command);
void LCD_write_data(unsigned char data); 
void LCD_set_xy (unsigned char x, unsigned char y); 
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s); 
void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data); 
void delay_nus(unsigned int n); 
void delay_nms(unsigned int n);

void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog

LCD_init(); 
LCD_write_string(1,0," www.goodmcu.cn "); 
LCD_write_string(2,1,"13652037001"); 
delay_nms(50);
LCD_write_command(0x01); //Clear screen
delay_nms(50);
LCD_write_char(2,1,'1');
delay_nms(50);
LCD_write_char(3,1,'3');
delay_nms(50);
LCD_write_char(4, 1,'6');
delay_nms(50);
LCD_write_char(5,1,'5');
delay_nms(50);
LCD_write_char(6,1,'2');
delay_nms(50);
LCD_write_char(7,1, '0');
delay_nms(50);
LCD_write_char(8,1,'3');
delay_nms(50);
LCD_write_char(9,1,'7'); 
delay_nms(50);
LCD_write_char(10,1,'0');
delay_nms(50);
LCD_write_char( 11,1,'0');
delay_nms(50);
LCD_write_char(12,1,'1');
}
//LCD liquid crystal operation function////////////////// ////////////////////////////////////////////////
//LCD1602 LCD initialization 
void LCD_init(void) 

LCD_DATA_DDR|=LCD_DATA; //Data port direction is output
LCD_EN_DDR|=LCD_EN; //Set EN direction to output
LCD_RS_DDR|=LCD_RS; //Set RS direction to output

LCD_write_command(0x28); //4-bit data interface
delay_nus(40); 
LCD_write_command(0x28); //4-bit display
LCD_write_command(0x0c); //Display on
LCD_write_command(0x01); //Clear delay_nms
(2); 

//LCD enable 
void LCD_en_write(void) 

LCD_EN_PORT|=LCD_EN; 
delay_nus(1); 
LCD_EN_PORT&=~LCD_EN; 

//Write command 
void LCD_write_command(unsigned char command) 

delay_nus(16) ; 
LCD_RS_PORT&=~LCD_RS; //RS=0 
LCD_DATA_PORT&=0X0f; //Clear high four bits 
LCD_DATA_PORT|=command&0xf0; //Write high four bits 
LCD_en_write(); 
command=command<<4; //Move the lower four bits to the upper four bits 
LCD_DATA_PORT&=0x0f; //Clear the upper four bits 
LCD_DATA_PORT|=command&0xf0; //Write the lower four bits 
LCD_en_write(); 

//Write data 
void LCD_write_data(unsigned char data) 

delay_nus(16) ; 
LCD_RS_PORT|=LCD_RS; //RS=1 
LCD_DATA_PORT&=0X0f; //Clear high four bits 
LCD_DATA_PORT|=data&0xf0; //Write high four bits 
LCD_en_write(); 
data=data<<4; //Move low four bits to high four bits LCD_DATA_PORT 
&=0X0f; //Clear high four bits 
LCD_DATA_PORT|=data&0xf0; //Write low four bits 
LCD_en_write(); 

//Write address function 
void LCD_set_xy( unsigned char x, unsigned char y )

unsigned char address; 
if (y == 0) address = 0x80 + x; 
else address = 0xc0 + x; 
LCD_write_command( address); 

//LCD writes a string at any position
//column x = 0~15, row y = 0,1 
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) 

LCD_set_xy( X, Y ); //write addresswhile 
(*s) //write display characters 

LCD_write_data( *s ); 
s ++; 
}
}
//LCD writes characters at any position
//column x=0~15, row y=0,1 
void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) 

LCD_set_xy( X, Y ); //write addressLCD_write_data 
( data); 
}

//
Delay function /
... ​​​ ​​​​​​​ ​​​​​​ ​​​​​























Keywords:MSP430 Reference address:MSP430 MCU Practice --- Digital LCD-1602 Display

Previous article:PWM Operation of MSP430 MCU
Next article:MSP430 MCU Practice---Internal FALSH Operation

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号