//Compiler: ICC-AVR v6.31A
//Target chip: M16
//Clock: 8.0000MHz
/*-------------------------------------------------------------
LCD Pin Definition
1---GND
2---VCC
3---VO
4---RS
5---RW
6---EN
7 to 14--D0-D7
15--Backlight+
16--Backlight-
---------------------------------------------------------------------------------*/
#include
#include
/*---------------------------------------------------------------
Below is the connection information between AVR and LCD
PA2 ->RS
PA3 ->EN
Ground ->RW
PA4 ->D4
PA5 ->D5
PA6 ->D6
PA7 ->D7
To use this driver, just change the following configuration information
-----------------------------------------------------------------*/
#define LCD_EN_PORT PORTA //The following 2 should be set to the same port
#define LCD_EN_DDR DDRA
#define LCD_RS_PORT PORTA //The following 2 should be set to the same port
#define LCD_RS_DDR DDRA
#define LCD_DATA_PORT PORTA //The following 3 should be set to the same port
#define LCD_DATA_DDR DDRA //Must use the high 4 bits
#define LCD_DATA_ PIN PINA
#define LCD_RS (1<
-----------------------------------------------------------------------------*/
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 delay_nus(unsigned int n);
void delay_nms(unsigned int n);
=============================================================================
#include "LCD.h"
void LCD_init(void) //LCD initialization
{
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);
LCD_en_write();
delay_nus(40);
LCD_write_command(0x28); //4-bit display
LCD_write_command(0x0c); //Display on
LCD_write_command(0x01); //Clear screen
delay_nms(2);
}
void LCD_en_write(void) //LCD enable
{
LCD_EN_PORT|=LCD_EN;
delay_nus(1);
LCD_EN_PORT&=~LCD_EN;
}
void LCD_write_command(unsigned char command) //Write command
{
delay_nus(16);
LCD_RS_PORT&=~LCD_RS; //RS=0
LCD_DATA_PORT&=0X0f; //Clear four bits
LCD_DATA_PORT|=command&0xf0; //Write high four bits
LCD_en_write();
command=command<<4; //Move low four bits to high four bits
LCD_DATA_PORT&=0x0f; //Clear high four bits
LCD_DATA_PORT|=command&0xf0; //Write low four bits
LCD_en_write();
}
void LCD_write_data(unsigned char data) //Write 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();
}
void LCD_set_xy( unsigned char x, unsigned char y ) //Write address function
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else address = 0xc0 + x;
LCD_write_command( address);
}
void LCD_write_string(unsigned char Y ) ; //Write address while (*s) //Write display characters
{ LCD_write_data( *s ); s ++; } } void LCD_write_char(unsigned char X, unsigned char Y, unsigned char data ) //Column x=0~15, row y=0,1 { LCD_set_xy ( ======================================================================= void delay_1us(void) //1us delay function { asm("nop"); } void delay_nus(unsigned int n) //N us delay function { unsigned int i=0; for (i=0;i
LCD_write_char(6,0,'8');
}
}
0 0| 0 1 0 0 // 0x04 | 0 0 0| 0 0
1 0 0 // 0x04 | 0 0 0 | 0 1 1 1 0 // 0x00 unsigned
char data[8]={0x04,0x0e,0x15,0x04,0x04,0x04,0x04,0x00};//↑ unsigned char data1[8]={0x04,0x04,0x04,0x04,0x15,0x0e,0x04,0x00};//↓ void my_signs(unsigned char ascii,unsigned char *z)//0x00 { unsigned char address=0,i,temp=0; //ascii is the ascii code value corresponding to the pattern to be defined (0x00 to temp=(ascii&0x07)<<3; //any value between 0x007) for(i=0;i<8;i++) { address = 0x40 +temp+ i; LCD_write_command( address ); delay_nus(1); LCD_write_data ( *(z++)); delay_nus(1); } } //Create pattern void LCD_init(void) //LCD initialization { LCD_DATA_DDR|=LCD_DATA; //Data is output LCD_EN_DDR|=LCD_EN; //Set RS.EN direction LCD_RS_DDR|=LCD_RS; LCD_write_command(0x28); //4-bit display LCD_en_write(); delay_nms(15); LCD_write_command(0x28); //4-bit display LCD_write_command(0x0c); //Display on my_signs(0x00,data);//↑ //Create pattern my_signs(0x01,data1);//↓ LCD_write_command(0x01); //Clear screen } Display custom pattern LCD_write_char(9,0,0x00);//↑ LCD_write_char(9,0,0x01);//↓
Special Tip: If the compilation fails, please delete the header file
Previous article:Programmer Notepad Configuration and AVRGCC Introduction
Next article:AVR infrared sending and receiving header file
- 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
- When processing this signal, how do we calculate Z if we know the coordinates of Z-1, Z0, and Z1?
- Zigbee (CC2530) connected to esp8266 can only send but not receive
- Analysis of the Design Method of DSP and Slow Peripheral Device Interface
- [ST60 short-distance evaluation] Part 1: First release on the Internet! Detailed evaluation!
- How reliable is Dupont wire???
- Q and D values of capacitors
- TI CC3200 WIFI Training Development Kit——by light-s
- HDMI to MIPI universal driver horizontal screen 1080P HD PC Raspberry Pi projector set-top box PS4 camera sub-screen side-transparent monitor TF card
- FPGA-based RGB to YUV422 digital video conversion.pdf
- "Let's practice together in 2021" + the busy year of 2020