//*---------------------------------------------------------------------------- //* \fn AT91F_US_Get //* \brief Get a Char to USART //*---------------------------------------------------------------------------- int AT91F_DBGU_Get(char *val) { if ((AT91F_US_RxReady((AT91PS_USART) AT91C_BASE_DBGU)) == 0) return (0); else { *val = AT91F_US_GetChar((AT91PS_USART) AT91C_BASE_DBGU); return (-1); } }
static char my_getc( void ) { return AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU); }
//*---------------------------------------------------------------------------- //* \fn AT91F_Getc //* \brief This function receives a car through the DBGU //*---------------------------------------------------------------------------- int AT91F_Getc() { while(!AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU)); return((int)AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU)); }
int main() { int _row, _col; char c; U32 status; AT91PS_PIO pPioA = AT91C_BASE_PIOA; AT91PS_PMC pPMC = AT91C_BASE_PMC; AT91PS_USART pUART0 = AT91C_BASE_US0; /* Initialize the Atmel AT91SAM7X256 (watchdog, PLL clock, default interrupts, etc.) */ AT91F_LowLevel_Init(); /* Init the LCD */ InitLCD(); /* Init the UART */ AT91F_US_Configure(pUART0, MCK, AT91C_US_ASYNC_MODE, 9600L, 0 ); AT91F_PMC_EnablePeripheralClock(pPMC, 1 << AT91C_ID_US0 ); AT91F_US_EnableRx(pUART0); AT91F_US_EnableTx(pUART0); AT91F_PIO_Disable( pPioA, RXD0 | TXD0 | RTS0 | CTS0 ); AT91F_PIO_A_RegisterSelection( pPioA, RXD0 | TXD0 | RTS0 | CTS0 ); /* enable interrupts */ AT91F_Finalize_Init(); /* add your program here ... */ LCD_ClearScreen( LCD_COLOR_RED ); LCD_WriteString("UART Demo:", &Fixedsys_descriptor, 2, Fixedsys_descriptor.font_height, LCD_COLOR_WHITE, LCD_COLOR_RED); _row = 2*(Fixedsys_descriptor.font_height+2); _col = 2; /* ... and here */ while ( true ) { status = AT91F_US_RxReady(pUART0); if(status) { c = AT91F_US_GetChar(pUART0); AT91F_US_PutChar(pUART0, c); LCD_WriteChar(c, &Fixedsys_descriptor, _col, _row, LCD_COLOR_WHITE, LCD_COLOR_RED); if (_col<(128-Fixedsys_descriptor.font_width)) _col += Fixedsys_descriptor.font_width; else { _col = 2; _row += (Fixedsys_descriptor.font_height+2); if (_row>(128-Fixedsys_descriptor.font_height)) { LCD_ClearScreen( LCD_COLOR_RED ); _row = 2; //Fixedsys_descriptor.font_height; _col = 2; } } } else status = AT91F_US_TxReady(pUART0); if(status) { //AT91F_US_PutChar(pUART0, '.'); } } /* Actually, the execution never gets here */ return 0; }