Koda: |
void lcd_init()
{ int match[4] = {0, 0, 0, 0}; timer1_init(0, match, mr0s, timer); set_pin_direction(0, RS | RW | E | DB7 | DB6 | DB5 | DB4); IO0CLR = E; wait(40000); // počaka toliko ciklov timerja 1MHz lcd_write_half_comm(SET | BITS_8); // nastavi 8-bitni priklop wait(4100); lcd_write_half_comm(SET | BITS_8); wait(100); lcd_write_half_comm(SET | BITS_8); busy(); lcd_write_half_comm(SET | BITS_4); // nastavi 4-bitni priklop busy(); // počaka da mine "busy" LCD stanje lcd_write_comm(SET | BITS_4 | LINES_2 | DOTS_5_8); lcd_write_comm(CONTROL | DISPLAY_OFF | CURSOR_OFF | BLINK_OFF); lcd_write_comm(CLEAR_DISPLAY); lcd_write_comm(MODE | CURSOR_DIRECTION_RIGHT | DISPLAY_SHIFT_OFF); lcd_write_comm(CONTROL | DISPLAY_ON | CURSOR_OFF | BLINK_OFF); } |
Koda: |
void busy()
{ int busy_flag; IO0DIR = IO0DIR & ~(DB7 | DB6 | DB5 | DB4); IO0CLR = RS; IO0SET = RW; do { wait(1); IO0SET = E; wait(1); busy_flag = IO0PIN & DB7; IO0CLR = E; wait(1); IO0SET = E; wait(1); IO0CLR = E; } while(busy_flag); IO0DIR = IO0DIR | DB7 | DB6 | DB5 | DB4; } |
Koda: |
// Wait function
// delay ... wait time in us void wait(int delay) { int div = 4; if(VPBDIV) div = VPBDIV; T1TCR = counter_reset; T1MR0 = 12 * delay * ((PLLSTAT & msel) + 1) / div; T1TCR = counter_enable; while(T1TC < T1MR0); } |