The microcontroller drives the 1602/2004 LCD through the PCF8574T module. Friends in need can take a look. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
//#define L1 0x80 // The first line write address
//#define L2 0xc0 // The second line write address
sbit SCL = P2^0;
sbit SDA = P2^1;
//char ADDR = 0x4E; // The address code of the PCF8574 T module
char ADDR = 0x7e; // The address code of the PCF8574 AT module
//***************************** Delay y ms ***************************************************
void delay1(int y) //
{
;
while(y--)
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
}
//******************************** IIC serial port starts********************************************
void IIC_start(void)
{
SDA=1;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_ (
);
_nop_(); _nop_()
;
SCL=0;
}
//********************************** IIC serial port writes 1 byte******************************************
void IIC_writeByte(char temp)
{
char i;
for(i=0;i<8;i++)
{
SDA=(bit)(temp & 0x80); // According to the regulations, the highest bit of 1602 data must be 1
temp <<=1;
_nop_();
_nop_();
SCL=1; _nop_
(); _nop_(); _nop_(); _nop_(); _nop_(); SCL=0; } _nop_(); _nop_(); _nop_(); _nop_(); SDA=1; _nop_(); _nop_(); _nop_(); _nop_(); SCL=1; _nop_(); _nop_(); _nop_(); while(SDA); _nop_(); SCL=0; }
//******************************** 1602 write command********************************************
void LCD_write_command(char comm)
{
char tmp;
IIC_start(); // Serial port starts
IIC_writeByte(ADDR); // Select the address of PCF 8574T first (it should be equivalent to the meaning of selection)
tmp = comm & 0xF0; // and 0xf0 should mean taking the fourth bit
tmp |= 0x0C; //Retain the upper 4 bits as the upper 4 bits of the instruction, and the lower 4 bits are RS = 0, RW = 0, EN = 1 IIC_writeByte
(tmp); //Send
delay1(20) from the serial port;
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (comm & 0x0F) << 4 ; //Send the lower 4 bits of the instruction to the high position for storage
tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay1(20);
tmp &= 0xFB; // Make EN = 0
IIC_writeByte(tmp);
}
//******************************** 1602 write data********************************************
void LCD_write_data(char data1)
{
char tmp;
IIC_start();
IIC_writeByte(ADDR); // Select the address of PCF 8574T first (it should be equivalent to the meaning of selection)
tmp = data1 & 0xF0;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay1(20);
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (data1 & 0x0F) << 4 ;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay1(20);
tmp &= 0xFB ; // Make EN = 0
IIC_writeByte(tmp);
}
//******************************** 1602 Initialization********************************************
void Init_Lcd(void)
{
LCD_write_command(0x33); //Convert 8-bit bus to 4-bit bus
delay1(50);
LCD_write_command(0x32); //
delay1(50);
LCD_write_command(0x28); // 4-bit data line, display 2 lines, 5*7 dot matrix characters! If it is 0x38, it is 8-bit data line, display 2 lines, 5*7 dot matrix characters
delay1(50);
LCD_write_command(0x0C); // Turn on display, turn off cursor, no blinking
delay1(50);
LCD_write_command(0x06); // Set input mode, increment without displacement
delay1(50);
LCD_write_command(0x01); // Clear screen
delay1(50);
}
//*************************************** Display the string at the specified position ******************************************
void Write_LCD(int x, int y, char *str)
{
char addr;
if(x < 0)
{
x = 0;
}
if(x > 15)
{
x = 15;
}
if(y<0)
{
s++;
} } //********************************* Display a character at the specified position *************************************** / *
void Print_Char (unsigned char line ,unsigned char num,unsigned char date) { LCD_write_command ( line + num ) ; LCD_write_data ( date); } * / // Display a character at the specified position ( for 1602 LCD ) -used in temperature displayvoid DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData) { Y &= 0x1; X &= 0xF; //Limit X not to be greater than 15, Y not to be greater than 1 if (Y) X |= 0x40; //When the second line is to be displayed, the address code + 0x40; X |= 0x80; //Calculate the command code LCD_write_command(X); //Do not detect the busy signal here, send the address code LCD_write_data(DData); }
Previous article:Design of DHT11 temperature and humidity detection control system based on 51 single chip microcomputer
Next article:Analysis of the working selection mode of the register TMOD of the MCS-51 single-chip microcomputer
- 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
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Unboxing: ESP32-S2-KALUGA-1, k210
- Error message when burning uniflash
- Keyi Review: Programmable Linear Constant Voltage Source Based on GP8102
- I saw a short video of a ragpicker hammering an electron tube, and then the person who filmed it quickly bought it!
- WBBSW Silk Screen
- 6ull test
- 【ST NUCLEO-H743ZI Review】(2)Converting serial port and Ethernet port data under LWIP
- RSL10 official information summary -- Baidu Cloud Disk Sharing
- The Evolution of Positioning Technology: The Road to UWB
- GSA: The number of 5G devices exceeds 600