
lab 3
Dependencies: mbed mbed-rtos tsi_sensor SLCD
NKC_LCD.h@0:78b84e1ce9df, 2020-02-18 (annotated)
- Committer:
- wstapleton
- Date:
- Tue Feb 18 21:16:23 2020 +0000
- Revision:
- 0:78b84e1ce9df
- Child:
- 1:03ee5f19d879
Lab2 hint 2/18/2020
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 | 0:78b84e1ce9df | 22 | target_baud=baud; |
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 | 0:78b84e1ce9df | 28 | return(NKC_BAUD[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 | 0:78b84e1ce9df | 64 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 65 | } |
wstapleton | 0:78b84e1ce9df | 66 | lcd.baud(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 67 | return(NKC_BAUD[target_baud]); |
wstapleton | 0:78b84e1ce9df | 68 | } |
wstapleton | 0:78b84e1ce9df | 69 | |
wstapleton | 0:78b84e1ce9df | 70 | void lcd_on() |
wstapleton | 0:78b84e1ce9df | 71 | { |
wstapleton | 0:78b84e1ce9df | 72 | lcd.printf("\xFE\x41"); |
wstapleton | 0:78b84e1ce9df | 73 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 74 | } |
wstapleton | 0:78b84e1ce9df | 75 | |
wstapleton | 0:78b84e1ce9df | 76 | void lcd_off() |
wstapleton | 0:78b84e1ce9df | 77 | { |
wstapleton | 0:78b84e1ce9df | 78 | lcd.printf("\xFE\x42"); |
wstapleton | 0:78b84e1ce9df | 79 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 80 | } |
wstapleton | 0:78b84e1ce9df | 81 | |
wstapleton | 0:78b84e1ce9df | 82 | void lcd_ddram_address(int address) |
wstapleton | 0:78b84e1ce9df | 83 | { |
wstapleton | 0:78b84e1ce9df | 84 | lcd.printf("\xFE\x45%c",address); |
wstapleton | 0:78b84e1ce9df | 85 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 86 | } |
wstapleton | 0:78b84e1ce9df | 87 | |
wstapleton | 0:78b84e1ce9df | 88 | int lcd_cursor(int row, int column) |
wstapleton | 0:78b84e1ce9df | 89 | { |
wstapleton | 0:78b84e1ce9df | 90 | int row_offsets[4]={0x00, 0x40, 0x13, 0x53}; |
wstapleton | 0:78b84e1ce9df | 91 | int address; |
wstapleton | 0:78b84e1ce9df | 92 | if( row < 0 || row > 3 || column < 0 || column > 19) {return(-1);} |
wstapleton | 0:78b84e1ce9df | 93 | address = row_offsets[row]+column; |
wstapleton | 0:78b84e1ce9df | 94 | lcd.printf("\xFE\x45%c",address); |
wstapleton | 0:78b84e1ce9df | 95 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 96 | return(address); |
wstapleton | 0:78b84e1ce9df | 97 | } |
wstapleton | 0:78b84e1ce9df | 98 | |
wstapleton | 0:78b84e1ce9df | 99 | void lcd_home() |
wstapleton | 0:78b84e1ce9df | 100 | { |
wstapleton | 0:78b84e1ce9df | 101 | lcd.printf("\xFE\x46"); |
wstapleton | 0:78b84e1ce9df | 102 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 103 | } |
wstapleton | 0:78b84e1ce9df | 104 | |
wstapleton | 0:78b84e1ce9df | 105 | void lcd_underline_on() |
wstapleton | 0:78b84e1ce9df | 106 | { |
wstapleton | 0:78b84e1ce9df | 107 | lcd.printf("\xFE\x47"); |
wstapleton | 0:78b84e1ce9df | 108 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 109 | } |
wstapleton | 0:78b84e1ce9df | 110 | |
wstapleton | 0:78b84e1ce9df | 111 | void lcd_underline_off() |
wstapleton | 0:78b84e1ce9df | 112 | { |
wstapleton | 0:78b84e1ce9df | 113 | lcd.printf("\xFE\x48"); |
wstapleton | 0:78b84e1ce9df | 114 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 115 | } |
wstapleton | 0:78b84e1ce9df | 116 | |
wstapleton | 0:78b84e1ce9df | 117 | int lcd_underline(int select) |
wstapleton | 0:78b84e1ce9df | 118 | { |
wstapleton | 0:78b84e1ce9df | 119 | if(select) |
wstapleton | 0:78b84e1ce9df | 120 | { |
wstapleton | 0:78b84e1ce9df | 121 | lcd_underline_on(); |
wstapleton | 0:78b84e1ce9df | 122 | return(true); |
wstapleton | 0:78b84e1ce9df | 123 | } |
wstapleton | 0:78b84e1ce9df | 124 | else |
wstapleton | 0:78b84e1ce9df | 125 | { |
wstapleton | 0:78b84e1ce9df | 126 | lcd_underline_off(); |
wstapleton | 0:78b84e1ce9df | 127 | return(false); |
wstapleton | 0:78b84e1ce9df | 128 | } |
wstapleton | 0:78b84e1ce9df | 129 | } |
wstapleton | 0:78b84e1ce9df | 130 | |
wstapleton | 0:78b84e1ce9df | 131 | void lcd_backspace() |
wstapleton | 0:78b84e1ce9df | 132 | { |
wstapleton | 0:78b84e1ce9df | 133 | lcd.printf("\xFE\x4E"); |
wstapleton | 0:78b84e1ce9df | 134 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 135 | } |
wstapleton | 0:78b84e1ce9df | 136 | |
wstapleton | 0:78b84e1ce9df | 137 | void lcd_clear() |
wstapleton | 0:78b84e1ce9df | 138 | { |
wstapleton | 0:78b84e1ce9df | 139 | lcd.printf("\xFE\x51"); |
wstapleton | 0:78b84e1ce9df | 140 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 141 | } |
wstapleton | 0:78b84e1ce9df | 142 | |
wstapleton | 0:78b84e1ce9df | 143 | void lcd_blink_on() |
wstapleton | 0:78b84e1ce9df | 144 | { |
wstapleton | 0:78b84e1ce9df | 145 | lcd.printf("\xFE\x4B"); |
wstapleton | 0:78b84e1ce9df | 146 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 147 | } |
wstapleton | 0:78b84e1ce9df | 148 | |
wstapleton | 0:78b84e1ce9df | 149 | void lcd_blink_off() |
wstapleton | 0:78b84e1ce9df | 150 | { |
wstapleton | 0:78b84e1ce9df | 151 | lcd.printf("\xFE\x4C"); |
wstapleton | 0:78b84e1ce9df | 152 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 153 | } |
wstapleton | 0:78b84e1ce9df | 154 | |
wstapleton | 0:78b84e1ce9df | 155 | int lcd_blink(int select) |
wstapleton | 0:78b84e1ce9df | 156 | { |
wstapleton | 0:78b84e1ce9df | 157 | if(select) |
wstapleton | 0:78b84e1ce9df | 158 | { |
wstapleton | 0:78b84e1ce9df | 159 | lcd_blink_on(); |
wstapleton | 0:78b84e1ce9df | 160 | return(true); |
wstapleton | 0:78b84e1ce9df | 161 | } |
wstapleton | 0:78b84e1ce9df | 162 | else |
wstapleton | 0:78b84e1ce9df | 163 | { |
wstapleton | 0:78b84e1ce9df | 164 | lcd_blink_off(); |
wstapleton | 0:78b84e1ce9df | 165 | return(false); |
wstapleton | 0:78b84e1ce9df | 166 | } |
wstapleton | 0:78b84e1ce9df | 167 | } |
wstapleton | 0:78b84e1ce9df | 168 | |
wstapleton | 0:78b84e1ce9df | 169 | void lcd_move_left() |
wstapleton | 0:78b84e1ce9df | 170 | { |
wstapleton | 0:78b84e1ce9df | 171 | lcd.printf("\xFE\x49"); |
wstapleton | 0:78b84e1ce9df | 172 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 173 | } |
wstapleton | 0:78b84e1ce9df | 174 | |
wstapleton | 0:78b84e1ce9df | 175 | void lcd_move_right() |
wstapleton | 0:78b84e1ce9df | 176 | { |
wstapleton | 0:78b84e1ce9df | 177 | lcd.printf("\xFE\x4A"); |
wstapleton | 0:78b84e1ce9df | 178 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 179 | } |
wstapleton | 0:78b84e1ce9df | 180 | |
wstapleton | 0:78b84e1ce9df | 181 | void lcd_shift_left() |
wstapleton | 0:78b84e1ce9df | 182 | { |
wstapleton | 0:78b84e1ce9df | 183 | lcd.printf("\xFE\x55"); |
wstapleton | 0:78b84e1ce9df | 184 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 185 | } |
wstapleton | 0:78b84e1ce9df | 186 | |
wstapleton | 0:78b84e1ce9df | 187 | void lcd_shift_right() |
wstapleton | 0:78b84e1ce9df | 188 | { |
wstapleton | 0:78b84e1ce9df | 189 | lcd.printf("\xFE\x56"); |
wstapleton | 0:78b84e1ce9df | 190 | wait(2E-3); |
wstapleton | 0:78b84e1ce9df | 191 | } |
wstapleton | 0:78b84e1ce9df | 192 | |
wstapleton | 0:78b84e1ce9df | 193 | #endif //NKC_LCD_H |