/************************************************ Módulo uart.c: Configura UART Marcos Augusto Stemmer *************************************************/ #include #include "monarm.h" /* Configuracao da Porta Serial 0 */ void U0init(void) { PCLKSEL0 = (PCLKSEL0 & (~0xc0)) | 0x40; /* divide por 1 no PCLK da UART0 */ PCONP |= 8; /* Liga energia da UART0 */ PINSEL0 = (PINSEL0 & (~0xf0)) | 0x50; /* Seleciona pinos TxD0 e RxD0 */ U0FCR = 0x7; /* Habilita as FIFOs e reset */ U0LCR = 0x83; /* Habilita acesso ao divisor de baud-rate (DLAB) */ U0DLL = ((SYSCLK/BAUDRATE+8) >> 4) & 0xff; U0DLM = ((SYSCLK/BAUDRATE) >> 12) & 0xff; U0LCR = 0x03; /* Configura UART0 como 8N1 */ } /* Recebe um caractere da porta serial */ int U0getchar(void) { while((U0LSR & 1) == 0); /* Espera ate receber algo */ return U0RBR; } /* Envia um caractere */ void U0putchar(int c) { while((U0LSR & 0x20) == 0); /* Tespera transmissor disponivel */ U0THR = c; /* Transmite */ } /* Envia uma mensagem pela UART0 */ void U0puts(char *txt) { while(*txt) U0putchar(*txt++); }