/**************************************************
*
* 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 /
...
Previous article:PWM Operation of MSP430 MCU
Next article:MSP430 MCU Practice---Internal FALSH Operation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Wu Hanming: The future semiconductor production capacity gap may be equivalent to 8 SMICs
- American Internet celebrity man made his own rocket and fell to his death
- Send data to the serial port, and an error message appears.
- Xunwei IMX6 development board Android application-buzzer test
- Lithium-ion battery
- Sound Level Meter MASTECH MS6700 Disassembly Pictures and Information
- Design of Multi-channel Data Acquisition System Based on CPLD
- Could you please tell me what glue is used to stick piezoelectric ceramic sheets to ultrasonic sensors?
- Let's talk about what technologies we can use to help in the face of this pneumonia virus? ? ?
- EEWORLD University Hall----C2000 series new products bring convenience to servo and motor drive systems