/* Configura Timer e LCD */ void LCDinit(void) { /* Configura portas I/O do LCD */ FIO3DIR |= 0xff; FIO4DIR |= LCD_E | LCD_RS; espera(20); LCDcomando(0x38); /* Configura LCD para 2 linhas */ LCDcomando(1); /* Limpa display */ LCDcomando(0x0c); /* Apaga cursor */ }
// Configura LCD void LCDinit(void) { // Configura portas I/O do LCD FIO3DIR |= 0xff; // Dados do LCD como saidas FIO4DIR |= LCD_E | LCD_RS; // EN e RS do LCD como saidas espera(20); LCDcomando(0x38); // Configura LCD para 2 linhas LCDcomando(1); // Limpa display LCDcomando(0x0c); // Apaga cursor }
void LCDinit(void) { FIO4DIR = LCD_E + LCD_RS; /* Controle do LCD na P4 */ FIO4CLR = LCD_E; FIO3DIR = 0xff; /* Dados do LCD como saidas */ T0TCR = 0; /* Desabilita T0 */ T0PR = CRYSTALFREQ/1000 - 1; /* Incrementa o contador T0TC 1000 vezes por segundo */ T0TCR = 2; /* Inicializa T0 */ T0TCR = 1; /* Habilita T0 */ LCDcomando(0x38); /* Configura LCD */ LCDcomando(1); /* Limpa o display */ LCDcomando(14); /* Liga cursor */ }
BYTE U0get (int mtempo) { BYTE d; int idx; static int brilho=0x38; int k,seg; int tempo, tini; tini = Timer; tempo = mtempo / 1000; /* Wait while Rx buffer is empty */ seg = RTC_SEC; k=10000; while (!RxFifo0.count) { idx = LEBOTAO; if((mtempo > 0) && (Timer-tini) >= mtempo) return ' '; switch(idx){ case SW3: brilho += 2; // KB4 incrementa contraste case SW4: brilho --; // KB5 decrementa contraste break; case SW2: if(k==0) return ' '; break; case SW1: tempo=5; break; default: if(k) k--; break; } if(tempo > 0 && seg!=RTC_SEC) { LCDcomando(0x86); LCDputchar(tempo+'0'); LCDputchar(' '); LCDcomando(0x87); LCDputs(" T="); if((--tempo) == 0) return ' '; seg = RTC_SEC; } } U0IER = 0; /* Disable interrupts */ idx = RxFifo0.rptr; d = RxFifo0.buff[idx]; /* Get a byte from Rx buffer */ RxFifo0.rptr = (idx + 1) % BUFFER_SIZE; RxFifo0.count--; U0IER = 0x07; /* Enable interrupt */ return d; }