Chapter 20 LCD1602
224
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define RW BASE+1
#define EN BASE+2
#define LED BASE+3
#define D4 BASE+4
#define D5 BASE+5
#define D6 BASE+6
#define D7 BASE+7
int
lcdhd
;
// used to handle LCD
void
printCPUTemperature
(){
// subfunction used to print CPU temperature
FILE
*
fp
;
char
str_temp
[
15
];
float
CPU_temp
;
// CPU temperature data is stored in this directory.
fp
=
fopen
(
"/sys/class/thermal/thermal_zone0/temp"
,
"r"
);
fgets
(
str_temp
,
15
,
fp
);
// read file temp
CPU_temp
=
atof
(
str_temp
)/
1000.0
;
// convert to Celsius degrees
printf
(
"CPU's temperature : %.2f \n"
,
CPU_temp
);
lcdPosition
(
lcdhd
,
0
,
0
);
// set the LCD cursor position to (0,0)
lcdPrintf
(
lcdhd
,
"CPU:%.2fC"
,
CPU_temp
);
// Display CPU temperature on LCD
fclose
(
fp
);
}
void
printDataTime
(){
//used to print system time
time_t rawtime
;
struct
tm
*
timeinfo
;
time
( &
rawtime
);
// get system time
timeinfo
=
localtime
(&
rawtime
);
// convert to local time
printf
(
"%s \n"
,
asctime
(
timeinfo
));
lcdPosition
(
lcdhd
,
0
,
1
);
// set the LCD cursor position to (0,1)
lcdPrintf
(
lcdhd
,
"Time:%d:%d:%d"
,
timeinfo
->
tm_hour
,
timeinfo
->
tm_min
,
timeinfo
->
tm_sec
);
//Display system time on LCD
}
int
main
(
void
){
int
i
;
i f
(
wiringPiSetup
()
= =
-
1
) {
//when initialize wiring failed, print message to screen
printf
(
"setup wiringPi failed !"
) ;
r e turn
1
;
}
pcf8574Setup
(
BASE
,
pcf8574_address
);
// initialize PCF8574
f o r
(
i
=
0
;
i
<
8
;
i
++){
pinMode
(
BASE
+
i
,
OUTPUT
);
// set PCF8574 port to output mode
}
digitalWrite
(
LED
,
HIGH
);
// turn on LCD backlight
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...