#include<s3c2440.h>
#include<stdarg.h>
#include"uart.h"
#define PCLK 50000000
#define UART_BRD (int)((PCLK/(baudrate*16))-1)
/***********************************************
*函数名称:void Uart0_Init(unsigned int baudrate)
*参数说明:baudrate:波特率
*返 回 值:无
*全局变量: 无
*功 能:对UART0进行初始化
************************************************/
void Uart0_Init(unsigned int baudrate)
{
GPHCON&=~((3<<4)|(3<<6)); //GPH2--TXD0;GPH3--RXD0
GPHCON|=((2<<4)|(2<<6)); //设置GPH2、GPH3为TXD0、RXD0功能
GPHUP=0x00; //上拉电阻使能
ULCON0|=0x03; //设置数据发送格式:8个数据位,1个停止位,无校验位
UCON0=0x05; //发送模式和接收模式都使用查询模式
UBRDIV0=UART_BRD; //设置波特率,其中波特率作为一个参数传递到该初始化函数
URXH0=0; //将URXH0清零
}
/***********************************************
*函数名称:void putc(unsigned char c)
*参数说明:c:通过串口接收到的字符,注意这里是8位数据
*返 回 值:无
*全局变量: 无
*功 能:将通过串口接收到的字符发送给PC机并显示在
* 串口调试工具。
************************************************/
void putc(unsigned char c)
{
UTXH0=c;
while(!(UTRSTAT0&(1<<2))); //等待发送完成
}
/***********************************************
*函数名称:unsigned char getc(void)
*参数说明:无
*返 回 值:c:通过串口接收到的字符,注意这里是8位数据
*全局变量: 无
*功 能:接收并保存通过串口输入的数据
************************************************/
unsigned char getc(void)
{
unsigned char c;
while(!(UTRSTAT0&(1<<0))); //查询是否接收到有效数据
c=URXH0;
return c;
}
/***********************************************
*函数名称:static void Uart0_SendByte(int data)
*参数说明:data:一个字节的数据
*返 回 值:无
*全局变量: 无
*功 能:向串口发送一个字节的数据。这个函数只在本
* C文件内使用,不被其他文件所调用,故使用
* static来修饰。
************************************************/
static void Uart0_SendByte(int data)
{
if(data=='\n') //注意,在超级终端中使用的换行符是'\r',因此当遇到'\n'时
{ //需要将其转换为'r'
while(!(UTRSTAT0&(1<<2))); //等待发送完成
UTXH0='\r';
}
while(!(UTRSTAT0&(1<<2))); //等待发送完成完成后,将新发送
UTXH0=data; //的数据写入发送寄存器
}
/***********************************************
*函数名称:static void Uart0_SendString(char *pt)
*参数说明:pt:指针,指向将要发送的数据所在数组的地址
*返 回 值:无
*全局变量: 无
*功 能:发送字符串
************************************************/
static void Uart0_SendString(char *pt)
{
while(*pt)
{
Uart0_SendByte(*pt++);
}
}
/***********************************************
*函数名称:void Uart0_Printf(const char *fmt,...)
*参数说明:可变参数
*返 回 值:无
*全局变量: 无
*功 能:将()的内容通过串口发送并在PC机显示
************************************************/
void Uart0_Printf(const char *fmt,...)
{
va_list ap; //定义了一个指向可变参数列表指针
char string[50]; //存储要发送的内容
va_start(ap,fmt); //是参数列表指针ap指向函数参数列表中的第一个可变参数
vsprintf(string,fmt,ap);
va_end(ap); //清空参数列表
Uart0_SendString(string); //将该缓冲区中的数据打印到串口中
}
//详细讲解请看博客:http://blog.csdn.net/mybelief321/article/details/8934635
没有合适的资源?快使用搜索试试~ 我知道了~
UART实验下载到Nor Flash中运行
共42个文件
d:4个
o:4个
crf:4个
需积分: 9 29 下载量 23 浏览量
2013-05-20
20:51:17
上传
评论
收藏 123KB RAR 举报
温馨提示
这是我用MDK编写的程序,可以将生成的bin文件通过烧写supervivi的方式下载到mini2440的nor flash中,实现脱机运行。详见我的博客: http://blog.csdn.net/mybelief321/article/details/8952306
资源推荐
资源详情
资源评论
收起资源包目录
UART实验下载到Nor Flash中运行.rar (42个子文件)
UART实验下载到Nor Flash中运行
Ext_RAM.ini 3KB
uart0.plg 10KB
S3C2440.s 51KB
uart.crf 13KB
my_mem.scf 236B
uart0.htm 58KB
nand.crf 4KB
main.d 106B
nand.__i 163B
uart0_uvproj.bak 15KB
uart0.sct 478B
clock.d 91B
dnw.ini 115B
ExtDll.iex 19B
uart0.uvopt 58KB
uart.o 30KB
uart0.bin 8KB
nand.d 40B
uart0_sct.Bak 476B
main.crf 13KB
uart0.map 119KB
clock.__i 167B
uart0.uvproj 15KB
uart0_Target 1.dep 873B
RuninRAM.sct 523B
uart.d 128B
uart0.axf 33KB
S3C2440.o 4KB
uart.__i 163B
uart0_uvopt.bak 58KB
uart0.hex 24KB
uart0.lnp 261B
main.o 28KB
clock.crf 12KB
S3C2440.lst 115KB
RuninFlash.sct 240B
JLinkArm_Target 1.ini 248B
nand.o 11KB
SRC
uart.h 1KB
uart.c 3KB
main.c 299B
uart0.tra 936B
共 42 条
- 1
资源评论
玖零大壮
- 粉丝: 4334
- 资源: 108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功