main.c

来自「博创2410的实验代码」· C语言 代码 · 共 98 行

C
98
字号
/***************************************************************************\
	Copyright (c) 2004-2007 threewater@up-tech.com, All rights reserved.
	by threewter	2004.5.12
\***************************************************************************/
/***************************************************************************\
    #说明: C  main 函数,ucos-ii初始化等定义
	----------------------------------  Bug  --------------------------------------

	----------------------------------  TODO list  --------------------------------------

	----------------------------------修正--------------------------------------
	2004-5-12	创建

\***************************************************************************/
#define U8 unsigned char
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "..inc/cpu.h"
#include "..inc/serial-2410.h"
#define TRUE 	1
#define FALSE 	0
#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 

#define rUTRSTAT0	(*(volatile unsigned *)0x50000010)
#define rUTRSTAT1	(*(volatile unsigned *)0x50004010)
#define WrUTXH0(ch)	(*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)
#define WrUTXH1(ch)	(*(volatile unsigned char *)0x50004020)=(unsigned char)(ch)
#define RdURXH0()	(*(volatile unsigned char *)0x50000024)
#define RdURXH1()	(*(volatile unsigned char *)0x50004024)
void Uart_SendString(int Uartnum, char *pt);
extern void Uart_SendByten(int Uartnum, U8 data);
char Uart_Getchn(char* Revdata, int Uartnum, int timeout);

void ARMTargetInit(void);
void hudelay(int time);
int main(void)
{   //int ndev; 
    char c1[1];
    char err;
	ARMTargetInit();        // do target (uHAL based ARM system) initialisation //
    serial_init(0, 115200);
	
	while(1)
	{
       	Uart_SendByten(0,0xa);//换行
		Uart_SendByten(0,0xd);//回车
        	err=Uart_Getchn(c1,0,0);	//从串口采集数据
        	Uart_SendByten(0,c1[0]);	//显示采集的数据
	}
	
	
	
}
	

   char Uart_Getchn(char* Revdata, int Uartnum, int timeout)
{
	
	if(Uartnum==0){
		while(!(rUTRSTAT0 & 0x1)); //Receive data read
		*Revdata=RdURXH0();
		return TRUE;
	}
	else{
		while(!(rUTRSTAT1 & 0x1));//Receive data read
		*Revdata=RdURXH1();
		return TRUE;
	}
}	

void Uart_SendString(int Uartnum, char *pt)
{
	while(*pt){
		if(*pt=='\n'){
			Uart_SendByten(Uartnum, '\r');
			Uart_SendByten(Uartnum, *pt++);
		}
		else
			Uart_SendByten(Uartnum, *pt++);
	}
}

void Uart_Printf(char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    Uart_SendString(0, string);
    va_end(ap);
}




⌨️ 快捷键说明

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