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

工程当中需要添加 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);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值