The LCD module controls the LCD screen on the UI board. More...
Go to the source code of this file.
Defines | |
#define | LCD_BOTTOM_LINE 0xA0 |
Instruction: hift to write on the second line. | |
#define | LCD_CLEAR 0x01 |
Instruction: clear screen. | |
#define | LCD_CURSOR_SHIFT_L 0x10 |
Instruction: shift cursor to left. | |
#define | LCD_CURSOR_SHIFT_R 0x14 |
Instruction: shift cursor to right. | |
#define | LCD_DISPLAY_OFF 0x08 |
Instruction: display, cursor, blink off. | |
#define | LCD_DISPLAY_ON 0x0C |
Instruction: display on. | |
#define | LCD_DISPLAY_SHIFT_L 0x18 |
Instruction: shift display to left. | |
#define | LCD_DISPLAY_SHIFT_R 0x1C |
Instruction: shift display to right. | |
#define | LCD_ENTRY_MODE 0x06 |
Instruction: don't increase cursor by one, no display shift. | |
#define | LCD_FUNCTION_SET 0x38 |
Instruction: 8 bit, 2 line display, 5x8 dot character. | |
#define | LCD_HOME 0x02 |
Instruction: return home. | |
#define | LCD_LENGTH (100) |
Length of the ring buffer. | |
#define | LCD_TOP_LINE 0x80 |
Instruction: shift to write to the top line. | |
#define | QUAD_NUM (4) |
Number of quads. | |
Functions | |
void | lcd_init (VOID_VOID_F overflowfunc) |
Initializes the LCD module and the screen. | |
void | lcd_isr (void) |
The interrupt service routine of the LCD module. | |
int | lcd_pop (LCD_CHAR *c) |
Pops the next character off of the ring buffer. | |
void | lcd_print (char *string, unsigned int length, unsigned int start_pos) |
Prints a string to the LCD. | |
void | lcd_print_char (char ch, unsigned int pos) |
Prints a character to the LCD screen. | |
int | lcd_push (LCD_CHAR *c) |
Pushes a char onto the ring buffer. | |
void | lcd_set_quad1 (char c1, char c2, char c3, char c4) |
Prints 4 characters to quad 1. | |
void | lcd_set_quad2 (char c1, char c2, char c3, char c4) |
Prints 4 characters to quad 2. | |
void | lcd_set_quad3 (char c1, char c2, char c3, char c4) |
Prints 4 characters to quad 3. | |
void | lcd_set_quad4 (char c1, char c2, char c3, char c4) |
Prints 4 characters to quad 4. | |
void | lcd_us_delay (long unsigned int delay_time_us) |
A simple blocking delay. | |
void | lcd_write_bit (unsigned int db, unsigned int bit) |
Writes a bit to data output. | |
void | lcd_write_data (unsigned char data) |
Writes a byte of data to the lcd D0-D7. | |
void | lcd_write_instruction (unsigned char instruction) |
Write the given byte instruction to the LCD controller. | |
Variables | |
unsigned int | lcd_head [QUAD_NUM] = {0,0,0,0} |
All of the head variables. | |
VOID_VOID_F | lcd_overflowfunc = voidvoid |
Function called when the timer overflows. | |
unsigned int | lcd_period |
unsigned int | lcd_quad = 0 |
The next buffer to check when popping data. | |
LCD_CHAR | lcd_ring [QUAD_NUM][LCD_LENGTH] |
The ring buffer (or 4 of them?). | |
LCD_STATE | lcd_state = LCD_IDLE |
unsigned int | lcd_tail [QUAD_NUM] = {0,0,0,0} |
LCD_CHAR | lcd_target_char |
int | lcd_wait = 0 |
The LCD module controls the LCD screen on the UI board.
Example hardware setup for pins:
// ******************************************************************************* // Initialize LCD // ******************************************************************************* PINSEL0 &= ~(0xFFFF); //Pins P0.0-P0.7 GPIO (D0-D7 on LCD controller) PINSEL0 &= ~(((unsigned int)3)<<30); //P0.15 GPIO (RS) PINSEL0 &= ~(3<<20); //P0.10 GPIO (R/~W) PINSEL0 &= ~(3<<22); //P0.11 GPIO (EN) FIO0DIR |= 0x8CFF; //set above pins as output FIO0MASK &= ~(0xFF); //zero fiomask //Timer stuff T0PR = 0;//no prescaling T0MR0 = 60000000/20000;//Match Register for scheduler interrupts T0TCR = 1;//enabled for counting T0CTCR = 0;//simple timer T0MCR = (1)|(1<<1);//interrupt (bit0) and reset (bit1) on MR0
Example interrupt setup:
//LCD Timer VICVectAddr1 = (unsigned long)lcd_isr; VICVectCntl1 = (1<<5) | VIC_TIMER1; VICIntEnable = 1<<VIC_TIMER1;
Definition in file lcd.c.
#define LCD_DISPLAY_ON 0x0C |
Instruction: display on.
Cursor and blink off
Definition at line 48 of file lcd.c.
Referenced by lcd_init().
#define LCD_LENGTH (100) |
Length of the ring buffer.
Definition at line 57 of file lcd.c.
Referenced by lcd_pop(), and lcd_push().
void lcd_init | ( | VOID_VOID_F | overflowfunc | ) |
Initializes the LCD module and the screen.
overflowfunc | A void(void) function which is called when the Timer driving the LCD module overflows due to a match. |
Definition at line 341 of file lcd.c.
References LCD_CLEAR, LCD_DISPLAY_ON, LCD_ENTRY_MODE, LCD_FUNCTION_SET, LCD_HOME, lcd_overflowfunc, lcd_us_delay(), and lcd_write_instruction().
00342 { 00343 lcd_period = 60000000 / ((T1MR0 + 1) * 1000); //in ms 00344 lcd_overflowfunc = overflowfunc; 00345 lcd_write_instruction(LCD_FUNCTION_SET); 00346 lcd_us_delay(200); 00347 lcd_write_instruction(LCD_DISPLAY_ON); 00348 lcd_us_delay(200); 00349 lcd_write_instruction(LCD_ENTRY_MODE); 00350 lcd_us_delay(200); 00351 lcd_write_instruction(LCD_CLEAR); 00352 lcd_us_delay(3000); 00353 lcd_write_instruction(LCD_HOME); 00354 lcd_us_delay(3000); 00355 }
void lcd_isr | ( | void | ) |
The interrupt service routine of the LCD module.
Uses a timer to interrupt every ms. Decides the next instruction to give to the LCD screen by a state machine.
Definition at line 297 of file lcd.c.
References LCD_CHAR::data, lcd_overflowfunc, lcd_pop(), lcd_write_data(), lcd_write_instruction(), and LCD_CHAR::pos.
00298 { 00299 //executed every lcd_period ms, so decrement msec wait counter by that much 00300 lcd_wait -= lcd_period; 00301 00302 // ****** EXECUTE IF ALLOWED ****** 00303 if (lcd_wait <= 0){ 00304 // ****** ACT ACCORDING TO STATE ****** 00305 switch (lcd_state){ 00306 case LCD_MOVE: 00307 lcd_write_instruction(0x80 | ((lcd_target_char.pos/8)*0x40)+(lcd_target_char.pos%8)); 00308 lcd_state = LCD_DISPLAY; 00309 break; 00310 case LCD_DISPLAY: 00311 lcd_write_data(lcd_target_char.data); 00312 00313 00314 if (lcd_pop(&lcd_target_char)){ 00315 // lcd_target_char = lcd_pop(); 00316 lcd_state = LCD_MOVE; 00317 } else { 00318 lcd_state = LCD_IDLE; 00319 } 00320 break; 00321 case LCD_IDLE: 00322 if (lcd_pop(&lcd_target_char)){ 00323 // lcd_target_char = lcd_pop(); 00324 lcd_state = LCD_MOVE; 00325 } 00326 break; 00327 } 00328 } 00329 00330 lcd_overflowfunc(); 00331 00332 T1IR = 0xFFFFFFFF; // Clear ALL Timer1 interrupt flags. 00333 VICVectAddr = 0; 00334 }
int lcd_pop | ( | LCD_CHAR * | c | ) |
Pops the next character off of the ring buffer.
The next character is the oldest one.
c | Pointer to the LCD_CHAR struct that will be filled with the popped info. |
Definition at line 186 of file lcd.c.
References lcd_head, LCD_LENGTH, and lcd_ring.
Referenced by lcd_isr().
00187 { 00188 //int i; 00189 //for(i = 0; i < 4; i++){ //check all buffers 00190 if (lcd_tail[0] != lcd_head[0]){ //buffer not empty 00191 *c = lcd_ring[0][lcd_tail[0] % LCD_LENGTH]; 00192 lcd_tail[0]++; 00193 return 1; 00194 } 00195 //} 00196 if (lcd_tail[1] != lcd_head[1]){ //buffer not empty 00197 *c = lcd_ring[1][lcd_tail[1] % LCD_LENGTH]; 00198 lcd_tail[1]++; 00199 return 1; 00200 } 00201 if (lcd_tail[2] != lcd_head[2]){ //buffer not empty 00202 *c = lcd_ring[2][lcd_tail[2] % LCD_LENGTH]; 00203 lcd_tail[2]++; 00204 return 1; 00205 } 00206 if (lcd_tail[3] != lcd_head[3]){ //buffer not empty 00207 *c = lcd_ring[3][lcd_tail[3] % LCD_LENGTH]; 00208 lcd_tail[3]++; 00209 return 1; 00210 } 00211 return 0; //empty 00212 }
void lcd_print | ( | char * | string, | |
unsigned int | length, | |||
unsigned int | start_pos | |||
) |
Prints a string to the LCD.
string | The string of characters to display. | |
length | The length of the string array. | |
start_pos | The start of the string when it is displayed on the LCD, 0 to 15. |
Definition at line 136 of file lcd.c.
References lcd_print_char().
00137 { 00138 int i; 00139 for (i = 0; i < length; i++){ 00140 lcd_print_char(string[i], start_pos + i); 00141 } 00142 }
void lcd_print_char | ( | char | ch, | |
unsigned int | pos | |||
) |
Prints a character to the LCD screen.
ch | The character to display. | |
pos | The position on the screen to display the char, 0-15. |
Definition at line 149 of file lcd.c.
References LCD_CHAR::data, lcd_push(), LCD_CHAR::pos, and LCD_CHAR::quad_num.
Referenced by lcd_print(), lcd_set_quad1(), lcd_set_quad2(), lcd_set_quad3(), and lcd_set_quad4().
int lcd_push | ( | LCD_CHAR * | c | ) |
Pushes a char onto the ring buffer.
If the buffer is full, new data is ignored.
c | A pointer to the LCD_CHAR struct to add to the buffer. |
Definition at line 164 of file lcd.c.
References error_occurred(), lcd_head, LCD_LENGTH, and lcd_ring.
Referenced by lcd_print_char().
00165 { 00166 if ((lcd_head[(*c).quad_num] % LCD_LENGTH) != (lcd_tail[(*c).quad_num] % LCD_LENGTH) //ring not full 00167 || lcd_head[(*c).quad_num] == lcd_tail[(*c).quad_num]){ //or empty 00168 lcd_ring[(*c).quad_num][lcd_head[(*c).quad_num] % LCD_LENGTH] = *c; 00169 00170 00171 lcd_head[(*c).quad_num]++; 00172 return 1; 00173 } else { //buffer full, ignore new data 00174 error_occurred(ERROR_LCD_STR_OF); 00175 return 0; 00176 } 00177 }
void lcd_set_quad1 | ( | char | c1, | |
char | c2, | |||
char | c3, | |||
char | c4 | |||
) |
Prints 4 characters to quad 1.
c1 | Character at position 0. | |
c2 | Character at position 1. | |
c3 | Character at position 2. | |
c4 | Character at position 3. |
Definition at line 232 of file lcd.c.
References lcd_print_char().
00233 { 00234 int i = 0; 00235 lcd_print_char(c1, i++); 00236 lcd_print_char(c2, i++); 00237 lcd_print_char(c3, i++); 00238 lcd_print_char(c4, i++); 00239 }
void lcd_set_quad2 | ( | char | c1, | |
char | c2, | |||
char | c3, | |||
char | c4 | |||
) |
Prints 4 characters to quad 2.
c1 | Character at position 4. | |
c2 | Character at position 5. | |
c3 | Character at position 6. | |
c4 | Character at position 7. |
Definition at line 248 of file lcd.c.
References lcd_print_char().
00249 { 00250 int i = 4; 00251 lcd_print_char(c1, i++); 00252 lcd_print_char(c2, i++); 00253 lcd_print_char(c3, i++); 00254 lcd_print_char(c4, i++); 00255 }
void lcd_set_quad3 | ( | char | c1, | |
char | c2, | |||
char | c3, | |||
char | c4 | |||
) |
Prints 4 characters to quad 3.
c1 | Character at position 8. | |
c2 | Character at position 9. | |
c3 | Character at position 10. | |
c4 | Character at position 11. |
Definition at line 264 of file lcd.c.
References lcd_print_char().
00265 { 00266 int i = 8; 00267 lcd_print_char(c1, i++); 00268 lcd_print_char(c2, i++); 00269 lcd_print_char(c3, i++); 00270 lcd_print_char(c4, i++); 00271 }
void lcd_set_quad4 | ( | char | c1, | |
char | c2, | |||
char | c3, | |||
char | c4 | |||
) |
Prints 4 characters to quad 4.
c1 | Character at position 12. | |
c2 | Character at position 13. | |
c3 | Character at position 14. | |
c4 | Character at position 15. |
Definition at line 280 of file lcd.c.
References lcd_print_char().
00281 { 00282 int i = 12; 00283 lcd_print_char(c1, i++); 00284 lcd_print_char(c2, i++); 00285 lcd_print_char(c3, i++); 00286 lcd_print_char(c4, i++); 00287 }
void lcd_us_delay | ( | long unsigned int | delay_time_us | ) |
A simple blocking delay.
Only used during initialization of the LCD.
delay_time_us | Wait this long... |
Definition at line 219 of file lcd.c.
Referenced by lcd_init().
void lcd_write_bit | ( | unsigned int | db, | |
unsigned int | bit | |||
) |
Writes a bit to data output.
db | The data output pin (0 to 8). | |
bit | The bit (0 or 1) to output. |
Definition at line 102 of file lcd.c.
Referenced by lcd_write_data(), and lcd_write_instruction().
void lcd_write_data | ( | unsigned char | data | ) |
Writes a byte of data to the lcd D0-D7.
data | Byte of data to send to the LCD. |
Definition at line 115 of file lcd.c.
References lcd_write_bit().
Referenced by lcd_isr().
00116 { 00117 int i; 00118 // ****** WRITE BYTE ****** 00119 FIO0SET = (1<<15); // RS = 1 data 00120 FIO0CLR = (1<<10); // R/~W = 0 write 00121 FIO0SET = (1<<11); // EN = 1 00122 // FIO0PIN0 = data; 00123 for (i = 0; i < 8; i++){ 00124 lcd_write_bit(i, data & (1<<i)); 00125 } 00126 FIO0CLR = (1<<11); // EN = 0, falling edge 00127 lcd_wait = lcd_period; 00128 }
void lcd_write_instruction | ( | unsigned char | instruction | ) |
Write the given byte instruction to the LCD controller.
instruction | The instruction to the LCD controller. |
Definition at line 76 of file lcd.c.
References LCD_CLEAR, LCD_HOME, and lcd_write_bit().
Referenced by lcd_init(), and lcd_isr().
00077 { 00078 int i; 00079 // ****** WRITE INSTRUCTION ****** 00080 FIO0CLR = (1<<15); // RS = 0 instruction 00081 FIO0CLR = (1<<10); // R/~W = 0 write 00082 FIO0SET = (1<<11); // EN = 1 00083 // FIO0PIN0 = instruction; 00084 for (i = 0; i < 8; i++){ 00085 lcd_write_bit(i, instruction & (1<<i)); 00086 } 00087 FIO0CLR = (1<<11); // EN = 0, falling edge 00088 00089 if (instruction == LCD_HOME || instruction == LCD_CLEAR){ 00090 lcd_wait = 2000; 00091 } else { 00092 lcd_wait = 50; //in ms; time to wait before executing the next function 00093 //lcd_wait = lcd_period; 00094 } 00095 }
unsigned int lcd_head[QUAD_NUM] = {0,0,0,0} |
All of the head variables.
Definition at line 60 of file lcd.c.
Referenced by lcd_pop(), and lcd_push().
VOID_VOID_F lcd_overflowfunc = voidvoid |
Function called when the timer overflows.
Can be set to asched_tick to save a Timer.
Definition at line 65 of file lcd.c.
Referenced by lcd_init(), and lcd_isr().