The problem of ESP8266 driving lcd1602

Thread Starter

zaizhetian

Joined Aug 30, 2017
6
I used PCF8574+ ESP8266+LCD1602, i2c displayed that program had been changed many times. And the download data from 8266 was not in the display.The screen can be used on other boards,so it is good.

Here is my program.Does anyone know what is the wrong point?

C:
1.# include "ets_sys. H"
2.# include "osapi. H"
3.# include "gpio. H"
4.# include "user_interface. H"
5.# include "driver/uart. H"
6.# define LCD_SDA_H GPIO_OUTPUT_SET (GPIO_ID_PIN (4), 1)
7.# define LCD_SDA_L GPIO_OUTPUT_SET (GPIO_ID_PIN (4), 0)
8.# define LCD_READ_SDA GPIO_INPUT_GET (GPIO_ID_PIN (4))
9.# define LCD_SCL_H GPIO_OUTPUT_SET (GPIO_ID_PIN (5), 1)
10.# define LCD_SCL_L GPIO_OUTPUT_SET (GPIO_ID_PIN (5), 0)
11.Typedef unsigned char uchar;
12.Typedef unsigned int uint;
13.# define X_COLUMN 16
14.# define Y_ROW 2
15.Unsigned char t0 [] = "WELCOME TO MCUSJ";
16.Unsigned char t1 [] = "1234567890 abcdef";
17.Extern void lcd_init ();
18.Extern void display ();
19.Extern void init ();
20.Void delay_ms (uint16 x)
21.{
22.For (; X > 0; X --)
23.{
24.Os_delay_us (1000);
25.}
26.}
27.Void delay_mms ()
28.{; }
29./ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30.* FunctionName: user_init
31.* Description: entry of user application, init user function here
32.* the Parameters: none
33.* Returns: none
34.* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
35.Void user_init (void)
36.{
37.Uart_init (BIT_RATE_115200 BIT_RATE_115200);
38.PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO4_U FUNC_GPIO4); / / set to normal mode
39.PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO5_U FUNC_GPIO5); / / set to normal mode
40.The init ();
41.Lcd_init ();
42.The display ();
43.While (1);
44.}
45.Void start () / / start
46.{
47.LCD_SDA_H;
48.Delay_mms ();
49.LCD_SCL_H;
50.Delay_mms ();
51.LCD_SDA_L;
52.Delay_mms ();
53.}
54.Void stop () / / sto
55.{
56.LCD_SDA_L;
57.Delay_mms ();
58.LCD_SCL_H;
59.Delay_mms ();
60.LCD_SDA_H;
61.Delay_mms ();
62.}
63.Void respons () / / response
64.{
65.Unsigned char I;
66.LCD_SCL_H;
67.Delay_mms ();
68.While ((LCD_READ_SDA = = 1) && (I < i++ 250));
69.LCD_SCL_L;
70.Delay_mms ();
71.}
72.Void init () / / i2c initialization
73.{
74.LCD_SDA_H;
75.Delay_mms ();
76.LCD_SCL_H;
77.Delay_mms ();
78.}
79.Void write_byte (uchar date) / / i2c write a byte
80.{
81.Unsigned char I, temp.
82.Temp = date;
83.For (I = 0; I < 8; I++)
84.{
85.If ((temp & 0 x80) = = 0 x80)
86.{LCD_SDA_H; }
87.else
88.{LCD_SDA_L; }
89.LCD_SCL_L;
90.Delay_mms ();
91.Temp = temp < < 1;
92.LCD_SCL_H;
93.Delay_mms ();
94.}
95.LCD_SCL_L;
96.Delay_mms ();
97.LCD_SDA_H;
98.Delay_mms ();
99.}
100.Uint8 ICACHE_FLASH_ATTR
101.Read_byte () / / i2c reads a byte
102.{
103.Unsigned char I, j;
104.The LOCAL uint8 k;
105.LCD_SCL_L;
106.Os_delay_us (5);
107.LCD_SDA_H;
108.For (I = 0; I < 8; I++)
109.{
110.Os_delay_us (5);
111.LCD_SCL_H;
112.Os_delay_us (5);
113.If (LCD_READ_SDA = = 1)
114.J = 1;
115.else
116.J = 0;
117.K = (k < < 1) | j;
118.LCD_SCL_L;
119.}
120.Os_delay_us (5);
121.The return of k;
122.}
123.Void write_add (unsigned char date) / / write data to PCF8574AT
124.{
125.Start ().
126.Write_byte (0 x7e);
127.Respons ();
128.Write_byte (date);
129.Respons ();
130.Stop ();
131.}
132./ *
133.Uint8 ICACHE_FLASH_ATTR
134.Read_add () / / read data from PCF8574
135.{
136.Uint8 reval = 0;
137.Start ().
138.Write_byte (0 x7f);
139.Respons ();
140.Reval = read_byte ();
141.Stop ();
142.Return reval;
143.Os_delay_us (1000);
144.}
145.* /
146.Void write_com (uchar com) / / write the command function in LCD_1602
147.{
148.Uchar com1, com2,
149.Com1 = com | 0 x0f;
150.Write_add (com1 & 0 XFC); / / RS = 0; RW = 0; EN = 1;
151.Delay_mms ();
152.Write_add (com1 & 0 xf8); / / RS = 0; RW = 0; EN = 0;
153.Com2 = com < < 4;
154.Com2 = com2 | 0 x0f;
155.Write_add (com2 & 0 XFC);
156.Delay_mms ();
157.Write_add (com2 & 0 xf8);
158.}
159.Void write_date (uchar date) / / write data to LCD_1602
160.{
161.Uchar date1 and date2.
162.Date1 = date | 0 x0f;
163.Write_add (date1 & 0 XFD); / / RS = 1; RW = 0; EN = 1;
164.Delay_mms ();
165.Write_add (date1 & 0 xf9); / / RS = 1; RW = 0; EN = 0;
166.Date2 = date < < 4;
167.Date2 = date2 | 0 x0f;
168.Write_add (date2 & 0 XFD);
169.Delay_mms ();
170.Write_add (date2 & 0 xf9);
171.}
172.Void lc
Moderators note: please use code tags for pieces of code.
When using code tags the line numbering is done automaticaly.
 
Last edited by a moderator:
Top