/************************************* Escreve no LCD usando interrupcao do timer 1 *******************************************/ #include #include "uart.h" /* No vic_cpsr.h tem declaracoes importantes para ativar as interrupcoes */ #include "vic_cpsr.h" #define TAMFILA 0x1ff #define LCD_E 1 #define LCD_RS 2 /* Se CLOCKRTC for definido usa-se oscilsdor espencial de 32768Hz */ /* Se nao for definido usa o clock de 12MHz -*/ //#define CLOCKRTC /* Fila para escrever no LCD usando a IRQ do Timer0 */ short LCDfila[TAMFILA+1]; int LCDini, LCDfim; volatile int ctempo=0; int ka, xa; /* A rotina de atendimento da IRQ do RTC Pega caracteres da fila e escreve no display LCD Pisca sequencialmente os LEDs */ void IRQ_RTC(void) __attribute__ ((interrupt("IRQ"))); void IRQ_RTC(void) { short k; if((LCDini!=LCDfim) && !ctempo--) { FIO3DIR |= 0xff; k = LCDfila[LCDini++]; /* Pega caractere k da fila */ if(k<0) { ctempo=8; FIO4CLR3=LCD_RS; } /* Se k for negativo e' comando */ else { FIO4SET3=LCD_RS; /*U0THR=k;*/ } /* Caractere */ FIO3PIN0=k; /* Escreve dados */ FIO4SET3=LCD_E; /* Pulsa E */ LCDini &= TAMFILA; FIO4CLR3=LCD_E; } if(ctempo < 0) ctempo=0; k=RTC_ILR; /* Le o identificador de IRQ do RTC */ RTC_ILR = k; /* Limpa a IRQ do RTC */ VICVectAddr = 0; } /* Configura o RTC para gerar 1024 IRQ por segundo */ void LCDinit() { int m, p; FIO4DIR |= (LCD_E + LCD_RS) << 24; FIO4CLR3 = LCD_E; ctempo=40; #ifdef CLOCKRTC RTC_CCR=0x11; #else RTC_PREINT = (CRYSTALFREQ >> 17)-1; RTC_PREFRAC = ((CRYSTALFREQ >> 2) & 0x7fff); RTC_CCR=1; #endif RTC_CISS = 0x82; /* Ativa RTC IRQ */ RTC_ILR=0; ctempo=0; desabilitaIRQ(); VICVectAddr13 = (int)IRQ_RTC; VICIntSelect &= ~0x2000; VICIntEnable = 0x2000; /* Habilita IRQ do RTC */ habilitaIRQ(); m=RTC_SEC; while(m==RTC_SEC); LCDcomando(0x38); /* Inicializa display LCD */ LCDcomando(1); /* Limpa */ LCDcomando(0x0c); /* Desliga cursor */ LCDcomando(0x40); m=0x1f0; do { p=8; do LCDputchar(m & 0x1f); while(--p); m >>= 1; } while(m & 0xf0); LCDcomando(0x80); } /* Coloca um caractere no fim da fila para escrita no LCD */ void LCDputchar(int c) { if(c & (-32)){ LCDfila[LCDfim++]=c; LCDfim &= TAMFILA; } } /* Coloca um comando na fila do LCD */ void LCDcomando(int c) { LCDfila[LCDfim++]= c-256; LCDfim &= TAMFILA; } /* Escreve um texto no LCD */ void LCDputs(char *s) { while(*s) LCDputchar(*s++); } void barra(int x) { int k; if(xa==x) return; if(x < 0) x=0; if(x > 160) x=160; k=x/5+0x80; while(k < ka) { LCDcomando(ka); LCDputchar(' '); ka--; } while(k > ka) { LCDcomando(ka); LCDputchar(4); ka++; } LCDcomando(k); LCDputchar(x % 5); ka=k; xa=x; }