
lab 5a
Dependencies: mbed mbed-rtos tsi_sensor SLCD
NKC_LCD.h@1:03ee5f19d879, 2020-02-19 (annotated)
- Committer:
- wstapleton
- Date:
- Wed Feb 19 01:26:00 2020 +0000
- Revision:
- 1:03ee5f19d879
- Parent:
- 0:78b84e1ce9df
minor fixes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wstapleton | 0:78b84e1ce9df | 1 | #ifndef NKC_LCD_H |
wstapleton | 0:78b84e1ce9df | 2 | #define NKC_LCD_H |
wstapleton | 0:78b84e1ce9df | 3 | |
wstapleton | 0:78b84e1ce9df | 4 | Serial lcd(PTD3,NC); |
wstapleton | 0:78b84e1ce9df | 5 | |
wstapleton | 0:78b84e1ce9df | 6 | int NKC_BAUD[9]={0,300,1200,2400,9600,14400,19200,57600,115200}; |
wstapleton | 0:78b84e1ce9df | 7 | |
wstapleton | 0:78b84e1ce9df | 8 | int lcd_baud_decode(int baud) |
wstapleton | 0:78b84e1ce9df | 9 | { |
wstapleton | 0:78b84e1ce9df | 10 | int target_baud; |
wstapleton | 0:78b84e1ce9df | 11 | target_baud=0; |
wstapleton | 0:78b84e1ce9df | 12 | if(baud >= 1 && baud <= 8) |
wstapleton | 0:78b84e1ce9df | 13 | { |
wstapleton | 0:78b84e1ce9df | 14 | target_baud=baud; |
wstapleton | 0:78b84e1ce9df | 15 | } |
wstapleton | 0:78b84e1ce9df | 16 | else |
wstapleton | 0:78b84e1ce9df | 17 | { |
wstapleton | 0:78b84e1ce9df | 18 | for(int i = 1; i <=8; i++) |
wstapleton | 0:78b84e1ce9df | 19 | { |
wstapleton | 0:78b84e1ce9df | 20 | if(baud == NKC_BAUD[i]) |
wstapleton | 0:78b84e1ce9df | 21 | { |
wstapleton | 1:03ee5f19d879 | 22 | target_baud=i; |
wstapleton | 0:78b84e1ce9df | 23 | } |
wstapleton | 0:78b84e1ce9df | 24 | } |
wstapleton | 0:78b84e1ce9df | 25 | } |
wstapleton | 0:78b84e1ce9df | 26 | if(target_baud >0) |
wstapleton | 0:78b84e1ce9df | 27 | { |
wstapleton | 1:03ee5f19d879 | 28 | return(target_baud); |
wstapleton | 0:78b84e1ce9df | 29 | } |
wstapleton | 0:78b84e1ce9df | 30 | else |
wstapleton | 0:78b84e1ce9df | 31 | { |
wstapleton | 0:78b84e1ce9df | 32 | return(-1); |
wstapleton | 0:78b84e1ce9df | 33 | } |
wstapleton | 0:78b84e1ce9df | 34 | } |
wstapleton | 0:78b84e1ce9df | 35 | |
wstapleton | 0:78b84e1ce9df | 36 | int lcd_baud(int baud) |
wstapleton | 0:78b84e1ce9df | 37 | { |
wstapleton | 0:78b84e1ce9df | 38 | int target_baud; |
wstapleton | 0:78b84e1ce9df | 39 | target_baud=lcd_baud_decode(baud); |
wstapleton | 0:78b84e1ce9df | 40 | if(target_baud > 0) |
wstapleton | 0:78b84e1ce9df | 41 | { |
wstapleton | 0:78b84e1ce9df | 42 | lcd.baud(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 43 | return(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 44 | } |
wstapleton | 0:78b84e1ce9df | 45 | else |
wstapleton | 0:78b84e1ce9df | 46 | { |
wstapleton | 0:78b84e1ce9df | 47 | return(-1); |
wstapleton | 0:78b84e1ce9df | 48 | } |
wstapleton | 0:78b84e1ce9df | 49 | } |
wstapleton | 0:78b84e1ce9df | 50 | |
wstapleton | 0:78b84e1ce9df | 51 | int lcd_default_baud(int baud) |
wstapleton | 0:78b84e1ce9df | 52 | { |
wstapleton | 0:78b84e1ce9df | 53 | int target_baud; |
wstapleton | 0:78b84e1ce9df | 54 | target_baud=lcd_baud_decode(baud); |
wstapleton | 0:78b84e1ce9df | 55 | if(target_baud < 0) |
wstapleton | 0:78b84e1ce9df | 56 | { |
wstapleton | 0:78b84e1ce9df | 57 | return(-1); |
wstapleton | 0:78b84e1ce9df | 58 | } |
wstapleton | 0:78b84e1ce9df | 59 | for(int i=1; i<=8; i++) |
wstapleton | 0:78b84e1ce9df | 60 | { |
wstapleton | 0:78b84e1ce9df | 61 | lcd.baud(NKC_BAUD[i]); |
wstapleton | 0:78b84e1ce9df | 62 | lcd.printf("\xFE\x61%1i",target_baud); |
wstapleton | 0:78b84e1ce9df | 63 | |
wstapleton | 1:03ee5f19d879 | 64 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 65 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 66 | } |
wstapleton | 0:78b84e1ce9df | 67 | lcd.baud(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 68 | return(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 69 | } |
wstapleton | 0:78b84e1ce9df | 70 | |
wstapleton | 0:78b84e1ce9df | 71 | void lcd_on() |
wstapleton | 0:78b84e1ce9df | 72 | { |
wstapleton | 0:78b84e1ce9df | 73 | lcd.printf("\xFE\x41"); |
wstapleton | 1:03ee5f19d879 | 74 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 75 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 76 | } |
wstapleton | 0:78b84e1ce9df | 77 | |
wstapleton | 0:78b84e1ce9df | 78 | void lcd_off() |
wstapleton | 0:78b84e1ce9df | 79 | { |
wstapleton | 0:78b84e1ce9df | 80 | lcd.printf("\xFE\x42"); |
wstapleton | 1:03ee5f19d879 | 81 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 82 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 83 | } |
wstapleton | 0:78b84e1ce9df | 84 | |
wstapleton | 0:78b84e1ce9df | 85 | void lcd_ddram_address(int address) |
wstapleton | 0:78b84e1ce9df | 86 | { |
wstapleton | 0:78b84e1ce9df | 87 | lcd.printf("\xFE\x45%c",address); |
wstapleton | 1:03ee5f19d879 | 88 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 89 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 90 | } |
wstapleton | 0:78b84e1ce9df | 91 | |
wstapleton | 0:78b84e1ce9df | 92 | int lcd_cursor(int row, int column) |
wstapleton | 0:78b84e1ce9df | 93 | { |
wstapleton | 0:78b84e1ce9df | 94 | int row_offsets[4]={0x00, 0x40, 0x13, 0x53}; |
wstapleton | 0:78b84e1ce9df | 95 | int address; |
wstapleton | 0:78b84e1ce9df | 96 | if( row < 0 || row > 3 || column < 0 || column > 19) {return(-1);} |
wstapleton | 0:78b84e1ce9df | 97 | address = row_offsets[row]+column; |
wstapleton | 0:78b84e1ce9df | 98 | lcd.printf("\xFE\x45%c",address); |
wstapleton | 1:03ee5f19d879 | 99 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 100 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 101 | return(address); |
wstapleton | 0:78b84e1ce9df | 102 | } |
wstapleton | 0:78b84e1ce9df | 103 | |
wstapleton | 0:78b84e1ce9df | 104 | void lcd_home() |
wstapleton | 0:78b84e1ce9df | 105 | { |
wstapleton | 0:78b84e1ce9df | 106 | lcd.printf("\xFE\x46"); |
wstapleton | 1:03ee5f19d879 | 107 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 108 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 109 | } |
wstapleton | 0:78b84e1ce9df | 110 | |
wstapleton | 0:78b84e1ce9df | 111 | void lcd_underline_on() |
wstapleton | 0:78b84e1ce9df | 112 | { |
wstapleton | 0:78b84e1ce9df | 113 | lcd.printf("\xFE\x47"); |
wstapleton | 1:03ee5f19d879 | 114 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 115 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 116 | } |
wstapleton | 0:78b84e1ce9df | 117 | |
wstapleton | 0:78b84e1ce9df | 118 | void lcd_underline_off() |
wstapleton | 0:78b84e1ce9df | 119 | { |
wstapleton | 0:78b84e1ce9df | 120 | lcd.printf("\xFE\x48"); |
wstapleton | 1:03ee5f19d879 | 121 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 122 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 123 | } |
wstapleton | 0:78b84e1ce9df | 124 | |
wstapleton | 0:78b84e1ce9df | 125 | int lcd_underline(int select) |
wstapleton | 0:78b84e1ce9df | 126 | { |
wstapleton | 0:78b84e1ce9df | 127 | if(select) |
wstapleton | 0:78b84e1ce9df | 128 | { |
wstapleton | 0:78b84e1ce9df | 129 | lcd_underline_on(); |
wstapleton | 0:78b84e1ce9df | 130 | return(true); |
wstapleton | 0:78b84e1ce9df | 131 | } |
wstapleton | 0:78b84e1ce9df | 132 | else |
wstapleton | 0:78b84e1ce9df | 133 | { |
wstapleton | 0:78b84e1ce9df | 134 | lcd_underline_off(); |
wstapleton | 0:78b84e1ce9df | 135 | return(false); |
wstapleton | 0:78b84e1ce9df | 136 | } |
wstapleton | 0:78b84e1ce9df | 137 | } |
wstapleton | 0:78b84e1ce9df | 138 | |
wstapleton | 0:78b84e1ce9df | 139 | void lcd_backspace() |
wstapleton | 0:78b84e1ce9df | 140 | { |
wstapleton | 0:78b84e1ce9df | 141 | lcd.printf("\xFE\x4E"); |
wstapleton | 1:03ee5f19d879 | 142 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 143 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 144 | } |
wstapleton | 0:78b84e1ce9df | 145 | |
wstapleton | 0:78b84e1ce9df | 146 | void lcd_clear() |
wstapleton | 0:78b84e1ce9df | 147 | { |
wstapleton | 0:78b84e1ce9df | 148 | lcd.printf("\xFE\x51"); |
wstapleton | 1:03ee5f19d879 | 149 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 150 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 151 | } |
wstapleton | 0:78b84e1ce9df | 152 | |
wstapleton | 0:78b84e1ce9df | 153 | void lcd_blink_on() |
wstapleton | 0:78b84e1ce9df | 154 | { |
wstapleton | 0:78b84e1ce9df | 155 | lcd.printf("\xFE\x4B"); |
wstapleton | 1:03ee5f19d879 | 156 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 157 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 158 | } |
wstapleton | 0:78b84e1ce9df | 159 | |
wstapleton | 0:78b84e1ce9df | 160 | void lcd_blink_off() |
wstapleton | 0:78b84e1ce9df | 161 | { |
wstapleton | 0:78b84e1ce9df | 162 | lcd.printf("\xFE\x4C"); |
wstapleton | 1:03ee5f19d879 | 163 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 164 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 165 | } |
wstapleton | 0:78b84e1ce9df | 166 | |
wstapleton | 0:78b84e1ce9df | 167 | int lcd_blink(int select) |
wstapleton | 0:78b84e1ce9df | 168 | { |
wstapleton | 0:78b84e1ce9df | 169 | if(select) |
wstapleton | 0:78b84e1ce9df | 170 | { |
wstapleton | 0:78b84e1ce9df | 171 | lcd_blink_on(); |
wstapleton | 0:78b84e1ce9df | 172 | return(true); |
wstapleton | 0:78b84e1ce9df | 173 | } |
wstapleton | 0:78b84e1ce9df | 174 | else |
wstapleton | 0:78b84e1ce9df | 175 | { |
wstapleton | 0:78b84e1ce9df | 176 | lcd_blink_off(); |
wstapleton | 0:78b84e1ce9df | 177 | return(false); |
wstapleton | 0:78b84e1ce9df | 178 | } |
wstapleton | 0:78b84e1ce9df | 179 | } |
wstapleton | 0:78b84e1ce9df | 180 | |
wstapleton | 0:78b84e1ce9df | 181 | void lcd_move_left() |
wstapleton | 0:78b84e1ce9df | 182 | { |
wstapleton | 0:78b84e1ce9df | 183 | lcd.printf("\xFE\x49"); |
wstapleton | 1:03ee5f19d879 | 184 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 185 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 186 | } |
wstapleton | 0:78b84e1ce9df | 187 | |
wstapleton | 0:78b84e1ce9df | 188 | void lcd_move_right() |
wstapleton | 0:78b84e1ce9df | 189 | { |
wstapleton | 0:78b84e1ce9df | 190 | lcd.printf("\xFE\x4A"); |
wstapleton | 1:03ee5f19d879 | 191 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 192 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 193 | } |
wstapleton | 0:78b84e1ce9df | 194 | |
wstapleton | 0:78b84e1ce9df | 195 | void lcd_shift_left() |
wstapleton | 0:78b84e1ce9df | 196 | { |
wstapleton | 0:78b84e1ce9df | 197 | lcd.printf("\xFE\x55"); |
wstapleton | 1:03ee5f19d879 | 198 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 199 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 200 | } |
wstapleton | 0:78b84e1ce9df | 201 | |
wstapleton | 0:78b84e1ce9df | 202 | void lcd_shift_right() |
wstapleton | 0:78b84e1ce9df | 203 | { |
wstapleton | 0:78b84e1ce9df | 204 | lcd.printf("\xFE\x56"); |
wstapleton | 1:03ee5f19d879 | 205 | //wait(2E-3); |
wstapleton | 1:03ee5f19d879 | 206 | wait_us(2000); |
wstapleton | 0:78b84e1ce9df | 207 | } |
wstapleton | 0:78b84e1ce9df | 208 | |
wstapleton | 0:78b84e1ce9df | 209 | #endif //NKC_LCD_H |