分类:
2010-09-08 15:28:22
//*---------------------------------------------------------------------------- //* ATMEL Microcontroller Software Support - ROUSSET - //*---------------------------------------------------------------------------- //* The software is delivered "AS IS" without warranty or condition of any //* kind, either express, implied or statutory. This includes without //* limitation any warranty or condition with respect to merchantability or //* fitness for any particular purpose, or against the infringements of //* intellectual property rights of others. //*---------------------------------------------------------------------------- //* File Name : main.c //* Object : main application written in C //* Creation : ODi 06/26/2002 //* //*---------------------------------------------------------------------------- #include#include "AT91RM9200.h" #include "lib_AT91RM9200.h" // AT91F_DBGU_Printk is defined in init.c extern void AT91F_DBGU_Printk(char *); void AT91F_DBGU_Printf(char *fmt,...) { va_list ap; char string[256]; va_start(ap,fmt); vsprintf(string,fmt,ap); AT91F_DBGU_Printk(string); va_end(ap); } //*---------------------------------------------------------------------------- //* \fn AT91F_DBGU_getc //* \brief This function is used to receive a character to the DBGU channel //*---------------------------------------------------------------------------- char AT91F_DBGU_Getc(void) { while (!AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU)); return AT91F_US_GetChar((AT91PS_USART) AT91C_BASE_DBGU); } int main() { unsigned int tick; int i, flag=0; //* USART0 test #if 1 AT91F_DBGU_Printk("========USART0 ECHO TEST==========\n\r"); AT91F_DBGU_Printk("Plug serial cable into COM2\n\r"); AT91F_DBGU_Printk("\'q\' to quit\n\r"); // Open PIO for USART0 AT91F_US0_CfgPIO(); AT91F_US0_CfgPMC(); // Configure USART0 AT91F_US_Configure ( AT91C_BASE_US0, // USART2 base address 60000000, // 60 MHz AT91C_US_ASYNC_MODE , // mode Register to be programmed 115200, // baudrate to be programmed 0); // timeguard to be programmed // Enable Transmitter & Receiver AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_US0); AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_US0); // USART0 echo while(1) { char c; if(AT91F_US_RxReady(AT91C_BASE_US0)) { if( (c = AT91F_US_GetChar(AT91C_BASE_US0)) != 'q') AT91F_US_PutChar(AT91C_BASE_US0, c); else break; } } #endif #if 1 //* USART1 test AT91F_DBGU_Printk("========USART1 ECHO TEST==========\n\r"); AT91F_DBGU_Printk("Plug serial cable into COM3\n\r"); AT91F_DBGU_Printk("\'q\' to quit\n\r"); // Open PIO for USART1 AT91F_US1_CfgPIO(); AT91F_US1_CfgPMC(); // Configure USART0 AT91F_US_Configure ( AT91C_BASE_US1, // USART2 base address 59904000, // 60 MHz AT91C_US_ASYNC_MODE , // mode Register to be programmed 115200, // baudrate to be programmed 0); // timeguard to be programmed // Enable Transmitter & Receiver AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_US1); AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_US1); // USART1 echo i = 0; while(1) { char c; //char temp[1024]; //int i = 0; if(AT91F_US_RxReady(AT91C_BASE_US1)) { if( (c = AT91F_US_GetChar(AT91C_BASE_US1)) != 'q') { if(AT91F_US_TxReady(AT91C_BASE_US1)) AT91F_US_PutChar(AT91C_BASE_US1, c); //AT91F_DBGU_Printk(&c); //temp[i++] = c; } else if(c == 0x89) AT91F_DBGU_Printk("error"); else break; } } #endif AT91F_DBGU_Printk("Test OK"); while(1); }