223
Chapter 20 LCD1602
Code
This code will get the CPU temperature and system time of RPi, display them on LCD1602.
C Code 20.1.1 I2CLCD1602
First observe the project result, and then analyze the code.
1.
Use cd command to enter 20.1.1_ I2CLCD1602 directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/20.1.1_I2CLCD1602
2.
Open the file I2CLCD1602.c, and find the macro definition "pcf8574_address". If your serial-to-parallel
module uses chip PCF8574, set the macro "pcf8574_address" value to 0x27.If your serial-to-parallel
module uses chip PCF8574A, set the macro "pcf8574_address" value to 0x3F.
3.
Use following command to compile “I2CLCD1602.c” and generate executable file “I2CLCD1602”.
gcc I2CLCD1602.c -o I2CLCD1602 -lwiringPi -lwiringPiDev
4.
Then run the generated file “I2CLCD1602”.
sudo ./ I2CLCD1602
After the program is executed, LCD1602 screen will display current CPU temperature and system time.
If there is no display or the display is not clear, rotate white knob in back of LCD to adjust the contrast
of LCD1602 until the screen can display clearly.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>
#include <pcf8574.h>
#include <lcd.h>
#include <time.h>
//#define pcf8574_address 0x27 // default I2C address of Pcf8574
#define pcf8574_address 0x3F
// default I2C address of Pcf8574A
#define BASE 64
// BASE is not less than 64
//////// Define the output pins of the PCF8574, which are directly connected to the
LCD1602 pin.
#define RS BASE+0
Содержание Ultimate Starter Kit
Страница 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Страница 116: ...Chapter 9 Potentiometer RGBLED 116 www freenove com support freenove com Circuit Schematic diagram ...
Страница 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Страница 136: ...Chapter 12 Joystick 136 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Страница 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Страница 182: ...Chapter 17 74HC595 LEDBar Graph 182 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 197: ...197 Chapter 18 74HC595 7 segment display www freenove com support freenove com Circuit Schematic diagram ...
Страница 198: ...Chapter 18 74HC595 7 segment display 198 www freenove com support freenove com Hardware connection ...
Страница 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Страница 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...
Страница 270: ...Chapter 26 WebIOPi IOT 270 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...