⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 AT91RM9200的异步串口调试程序,波特率为1152
💻 C
字号:
//*----------------------------------------------------------------------------
//*         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            : FB   24/10/2002
//*
//*----------------------------------------------------------------------------

extern void AT91F_DBGU_Printk(char *);

#include "AT91RM9200.h"
#include "lib_AT91RM9200.h"
//#include "extern.h"

void delay(int i)
{
	for(;i>0;i--)
	;
}

void ambe_rst(void)
{
	AT91F_PIO_Enable(AT91C_BASE_PIOA,AT91C_PIO_PA20);        //配置为I/O口 
	AT91F_PIO_OutputEnable(AT91C_BASE_PIOA,AT91C_PIO_PA20);  // I/O口上拉
	AT91F_PIO_ClearOutput(AT91C_BASE_PIOA,AT91C_PIO_PA20);  //低电平
	delay(10000);
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA,AT91C_PIO_PA20);  //高电平
}

void usart0_init(void)
{
	AT91F_US0_CfgPIO();								//配置为US0
	AT91F_US0_CfgPMC();								//must add
	// Configure  US0
	AT91F_US_Configure(
	AT91C_BASE_US0,          			// US0 base address
	60000000,                  							// 60 MHz
	AT91C_US_ASYNC_MODE ,        // mode Register to be programmed
	115200 ,                   							// baudrate to be programmed
	0);                        							// timeguard to be programmed
	
	
	//AT91C_BASE_PIOA->PIO_PPUDR =AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
	
	// Enable Transmitter
	
	AT91F_US_EnableTx(AT91C_BASE_US0);
	
	AT91F_US_EnableRx(AT91C_BASE_US0);
	//AT91C_BASE_US0->US_CSR=0x1a;
	
	
	}


void AT91F_US0_SEND(
	char *buffer) // \arg pointer to a string ending by \0
{
	while(*buffer != '\0') {
		while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_US0));
		AT91F_US_PutChar(AT91C_BASE_US0, *buffer++);
	}
}


char AT91F_US0_RECV()
{
	while (!AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_US0));
	return AT91F_US_GetChar(AT91C_BASE_US0);
}



int main()
{ //go 0x1f0000;
   int RECV[1];
	AT91F_DBGU_Printk("\n\rBasicBoot Successfull: Enter main()\n\r");
	AT91F_DBGU_Printk("*");
    ambe_rst();//禁止ambe2000
    usart0_init();//串口0初始化
   
    AT91F_US0_SEND("\nInput a number:  ");
	while (1)
	 {
	 	
	 	
		
		 AT91C_BASE_US0->US_IDR = 0xFFFFFFFF ;//关所有中断
    
		//AT91C_BASE_US0->US_THR = 0x22;//直接写发送保存寄存器
		
		AT91F_US0_SEND("\nhit a key one time:  ");
		delay(100000);//延时一定要足够长,否则串口助手终端处理不过来,会出错
		AT91F_US0_SEND("\n");
		
		
		
	    RECV[0]= AT91F_US0_RECV();
	    delay(100000);
	    AT91F_US0_SEND("The key you hit is:  ");
	     AT91F_US0_SEND("\n");
	    
	    AT91C_BASE_US0->US_THR =RECV[0];
	    while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_US0));
	  	delay(100000);
		
	 	//AT91F_US0_SEND("\n");

     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -