2440裸机程序——串口收发数据

来源:互联网 发布:网络用语狗是什么意思 编辑:程序博客网 时间:2024/05/14 06:07

工程当中需要添加 S3C2440A.s ;2440lib.c;main.c;uart0.c 这四个程序。


主程序:

/*********************************************************************************************
* File name: main.c
* Author: ZXL 
* Description: 在PC机通过串口0向终端发送一行字符(以回车键结束),开发板接收串口数据后,保存在数组中,再传回到PC端,通过终端回显。
* History: 2013.5.8
*********************************************************************************************/


#include "def.h"
#include "option.h"
#include "2440addr.h"     
#include "2440lib.h"
   
void dely(U32 tt)
{
   U32 i;
   for(;tt>0;tt--)
        for(i=0;i<10000;i++);
}


void init()
{
U32 i;
U8 key;
U32 mpll_val=0;
    i = 2 ;
switch ( i ) //设置2440的时钟频率
{
case 0: //200
key = 12;
mpll_val = (92<<12)|(4<<4)|(1);
break;
case 1: //300
key = 13;
mpll_val = (67<<12)|(1<<4)|(1);
break;
case 2: //400
key = 14;
mpll_val = (92<<12)|(1<<4)|(1);
break;
case 3: //440!!!
key = 14;
mpll_val = (102<<12)|(1<<4)|(1);
break;
default:
key = 14;
mpll_val = (92<<12)|(1<<4)|(1);
break;
}
//MDIV=92,PDIV=1,SDIV=1 通过配置MPLLCON,MPLL确定,即FCLK=400MHZ确定
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
ChangeClockDivider(key, 12);  //FCLK:HCLK:PCLK = 1:1/4:1/8 =400M:100M:50M
    
Port_Init();
  
Uart_Init(0,115200);
    Uart_Select(0);   
Uart_Printf("\n Uart0 Test!!!\n"); 
}  
   
int main(int argc, char **argv)
{
init();
    do
    {    
uart0();
}while(Uart_Getch() != ESC_KEY);//无限循环,直到用户键入ESC键,退出。
Uart_Printf("\n Exit Uart0 Test!\n");
}




串口程序:


/*********************************************************************************************
* File name: uart0.c
* Author: ZXL 
* Description: 在PC机通过串口0向终端发送一行字符(以回车键结束),开发板接收串口数据后,保存在数组中,再传回到PC端,通过终端回显。
* History: 2013.5.8
*********************************************************************************************/


#include "def.h"
#include "option.h"
#include "2440addr.h"     
#include "2440lib.h"


void uart0()
{
U8 c,string_input[256];
U8 m=0;


Uart_Printf(" Please input words, then press Enter:\n");
while(1)
{
c=Uart_Getch();//从终端接收一个字符
Uart_Printf("%c",c);//在终端显示用户输入的字符
if(c!='\r') string_input[m++]=c;   //将接收到的字符保存在一个数组里面
else
{
string_input[m]='\0';//收到回车符,表示字符输入结束,在字符串的末尾加上结束符
break;
}
}
dely(50);


Uart_Printf("\n The words that you input are: \n %s\n",string_input);
}


原创粉丝点击