/* Escreve a temperatura como um numero decimal */ void escrevenum(int num) { char digs[16]; int nd=0; num *=625; if(num<0) { LCDputchar('-'); num=-num; } do { digs[nd++]= (num % 10) + '0'; num /= 10; } while(num); while(nd < 5) digs[nd++]='0'; while(nd > 4) LCDputchar(digs[--nd]); LCDputchar(','); /* Parte fracionaria com resolucao de 1/16 grau */ LCDputchar(digs[--nd]); LCDputchar(digs[--nd]); UART0putchar('\n'); }
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; }
int main(void) { unsigned char buffer[17]; // Where we are reading to buffer[16] = '\0'; // Terminating string int page = 0xa0; int offset = 0; init_timer0(); // LCD needs timer0 to function LCDinit(); // Initializing LCD ini_i2c(); // Initializing i2c /******************** MAIN LOOP *********************/ while(1) { offset &= 0xff; buffer[0] = offset; escreve_i2c(page, buffer, 1); /* tell i2c we want to read from page + offset */ if(le_i2c(page, buffer, 16)) { /* If we failed to read 16 bytes */ LCDclear(); LCDgoto(0, 0); LCDputs("Problema de leitura"); LCDgoto(1, 0); LCDputs(buffer); } else { LCDgoto(0, 0); // Go to first line, first column LCDputs("Pg = "); LCDputchar(page + '0'); // Prints page number as char LCDgoto(0, 8); // Go to the second half of first line LCDputs("Of = "); LCDputchar(offset + '0'); // Prints offset as char LCDgoto(1, 0); // Fisrt column of the second line LCDputs(buffer); // Prints buffer } } return 0; }
/* Envia uma mensagem no LCD */ void LCDputs(char *txt) { while(*txt) LCDputchar(*txt++); }