|
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <wiringPi.h>
- #include <lcd.h>
- /*
- cc -o lcd lcd.c -lwiringPi -lwiringPiDev
- lcd
- lcd line1 line2
- 1602LCD PI
- VSS --- 5V
- VDD --- Gnd
- V0 --- Volume
- RS --- Pin#16
- RW --- Gnd
- E --- Pin#18
- D0
- D1
- D2
- D3
- D4 --- Pin#11
- D5 --- Pin#12
- D6 --- Pin#13
- D7 --- Pin#15
- */
- #define DEBUG 0
- int main(int argc, char **argv) {
- int fd_lcd;
- int stlen;
- int i;
- int line;
- char string1[17];
- char string2[17];
- if(wiringPiSetup() == -1) {
- printf("Setup Fail\n");
- exit(1);
- }
- fd_lcd = lcdInit(2,16,4,4,5,0,1,2,3,0,0,0,0);
- if(DEBUG)printf("argc=%d\n",argc);
- memset(string1,0,sizeof(string1));
- memset(string2,0,sizeof(string1));
- if(argc == 1) {
- lcdClear(fd_lcd);
- } else if (argc == 2) {
- } else if (argc == 3) {
- stlen=strlen(argv[1]);
- if(DEBUG)printf("stlen=%d\n",stlen);
- if (stlen < 17) {
- strcpy(string1,argv[1]);
- } else {
- strncpy(string1,argv[1],16);
- }
- stlen=strlen(argv[2]);
- if(DEBUG)printf("stlen=%d\n",stlen);
- if (stlen < 17) {
- strcpy(string2,argv[2]);
- } else {
- strncpy(string2,argv[2],16);
- }
- lcdPosition(fd_lcd,0,0);
- lcdPuts(fd_lcd,string1);
- lcdPosition(fd_lcd,0,1);
- lcdPuts(fd_lcd,string2);
- }
- }
Copy code
Clear LCD
$sudo ./lcd
Show LCD
$sudo ./lcd Line1 Lne2
|
|