1 2 3 4 5 6 7 8 9 10 11 12 13 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | //------------------------------------------------------------------------------------------------------------ // // ODROID-C 16x2 LCD / LED / Button Test Application. // // Defined port number is wiringPi port number. // // Compile : gcc -o <create excute file name> <source file name> -lwiringPi -lwiringPiDev -lpthread // Run : sudo ./<created excute file name> // //------------------------------------------------------------------------------------------------------------ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <unistd.h> #include <string.h> #include <time.h> #include <wiringPi.h> #include <wiringPiI2C.h> #include <wiringSerial.h> #include <lcd.h> //------------------------------------------------------------------------------------------------------------ // // Global handle Define // //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ // // LCD: // //------------------------------------------------------------------------------------------------------------ #define LCD_ROW 2 // 16 Char #define LCD_COL 16 // 2 Line #define LCD_BUS 4 // Interface 4 Bit mode #define LCD_UPDATE_PERIOD 300 // 300ms static unsigned char lcdFb[LCD_ROW][LCD_COL] = {0, }; static int lcdHandle = 0; static int lcdDispPos = 0; #define PORT_LCD_RS 7 // GPIOY.BIT3(#83) #define PORT_LCD_E 0 // GPIOY.BIT8(#88) #define PORT_LCD_D4 2 // GPIOX.BIT19(#116) #define PORT_LCD_D5 3 // GPIOX.BIT18(#115) #define PORT_LCD_D6 1 // GPIOY.BIT7(#87) #define PORT_LCD_D7 4 // GPIOX.BIT7(#104) const unsigned char lcdDispString[LCD_ROW][LCD_COL] = { //1234567890123456 " Hello! ODROID! ", " - HardKernel - ", }; //------------------------------------------------------------------------------------------------------------ // // Button: // //------------------------------------------------------------------------------------------------------------ #define PORT_BUTTON1 5 // GPIOX.BIT5(#102) #define PORT_BUTTON2 6 // GPIOX.BIT6(#103) //------------------------------------------------------------------------------------------------------------ // // LED: // //------------------------------------------------------------------------------------------------------------ static int ledPos = 0; const int ledPorts[] = { 21, // GPIOX.BIT4(#101) 22, // GPIOX.BIT3(#100) 23, // GPIOX.BIT11(#108):PWM_B 24, // GPIOX.BIT0(#97) 11, // GPIOX.BIT21(#118) 26, // GPIOX.BIT2(#99) 27, // GPIOX.BIT1(#98) }; #define MAX_LED_CNT sizeof(ledPorts) / sizeof(ledPorts[0]) //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ // // LCD Update Function: // //------------------------------------------------------------------------------------------------------------ static void lcd_update (void) { int i, j; memset((void *)&lcdFb, ' ', sizeof(lcdFb)); if(lcdDispPos) lcdDispPos %= LCD_COL; // LCD Display Shift if(lcdDispPos < 0) { strncpy(&lcdFb[0][abs(lcdDispPos)], &lcdDispString[0][0], LCD_COL - abs(lcdDispPos)); strncpy(&lcdFb[1][abs(lcdDispPos)], &lcdDispString[1][0], LCD_COL - abs(lcdDispPos)); } else { strncpy(&lcdFb[0][0], &lcdDispString[0][lcdDispPos], LCD_COL - lcdDispPos); strncpy(&lcdFb[1][0], &lcdDispString[1][lcdDispPos], LCD_COL - lcdDispPos); } for(i = 0; i < LCD_ROW; i++) { lcdPosition (lcdHandle, 0, i); for(j = 0; j < LCD_COL; j++) lcdPutchar(lcdHandle, lcdFb[i][j]); } } //------------------------------------------------------------------------------------------------------------ // // system init // //------------------------------------------------------------------------------------------------------------ int system_init(void) { int i; // LCD Init lcdHandle = lcdInit (LCD_ROW, LCD_COL, LCD_BUS, PORT_LCD_RS, PORT_LCD_E, PORT_LCD_D4, PORT_LCD_D5, PORT_LCD_D6, PORT_LCD_D7, 0, 0, 0, 0); if(lcdHandle < 0) { fprintf(stderr, "%s : lcdInit failed!\n", __func__); return -1; } // GPIO Init(LED Port ALL Output) for(i = 0; i < MAX_LED_CNT; i++) { pinMode (ledPorts[i], OUTPUT); pullUpDnControl (PORT_BUTTON1, PUD_OFF); } // Button Pull Up Enable. pinMode (PORT_BUTTON1, INPUT); pullUpDnControl (PORT_BUTTON1, PUD_UP); pinMode (PORT_BUTTON2, INPUT); pullUpDnControl (PORT_BUTTON2, PUD_UP); return 0; } //------------------------------------------------------------------------------------------------------------ // // board data update // //------------------------------------------------------------------------------------------------------------ void boardDataUpdate(void) { int i; // LED Control for(i = 0; i < MAX_LED_CNT; i++) digitalWrite (ledPorts[i], 0); // LED All Clear digitalWrite(ledPorts[ledPos++], 1); if(ledPos) ledPos %= MAX_LED_CNT; // button status read if(!digitalRead (PORT_BUTTON1)) lcdDispPos++; if(!digitalRead (PORT_BUTTON2)) lcdDispPos--; } //------------------------------------------------------------------------------------------------------------ // // Start Program // //------------------------------------------------------------------------------------------------------------ int main (int argc, char *argv[]) { int timer = 0 ; wiringPiSetup (); if (system_init() < 0) { fprintf (stderr, "%s: System Init failed\n", __func__); return -1; } for(;;) { if (millis () < timer) continue ; timer = millis () + LCD_UPDATE_PERIOD; // All Data update boardDataUpdate(); // lcd update lcd_update(); } return 0 ; } //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ |