3.18
来源:互联网 发布:js判断浏览器语言 编辑:程序博客网 时间:2024/04/29 23:43
#include "S3C2451_uart.h"
#include "S3C2451_vector.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
UART_MemMapPtr const UART_BASE_PTR[4] = {UART0_BASE_PTR,UART1_BASE_PTR,UART2_BASE_PTR,UART3_BASE_PTR};
void UART_Init(UART_Typedef uartx,UART_Init_Typedef uart_init_struct)
{
UART_BASE_PTR[uartx]->ULCON &= ~(0x3F);
//wordwidth
UART_BASE_PTR[uartx]->ULCON |= uart_init_struct.wordwidth;
//stop
UART_BASE_PTR[uartx]->ULCON |= (uart_init_struct.stop<<2);
//parity
UART_BASE_PTR[uartx]->ULCON |= (uart_init_struct.parity<<3);
//baud
if( 9600 == uart_init_struct.baudrate)
{
UART_BASE_PTR[uartx]->UBRDIV = 10;
UART_BASE_PTR[uartx]->UDIVSLOT = 0xeeeee;
}else if(115200 == uart_init_struct.baudrate)
{
UART_BASE_PTR[uartx]->UBRDIV = 34; //pclk=66.5Mhz
UART_BASE_PTR[uartx]->UDIVSLOT = 0xDFDD;
}
UART_BASE_PTR[uartx]->UCON &= ~(0x0f);
//enable tx
if((uart_init_struct.mode&UART_Mode_TX) == UART_Mode_TX)
{
UART_BASE_PTR[uartx]->UCON |= (1<<2);
}
//enable rx
if((uart_init_struct.mode&UART_Mode_RX) == UART_Mode_RX)
{
UART_BASE_PTR[uartx]->UCON |= 1;
}
}
void UART_SendData(UART_Typedef uartx,U8 data)
{
UART_BASE_PTR[uartx]->UTXH = data;
while(!(UART_BASE_PTR[uartx]->UTRSTAT&0x04));
}
void UART_SendDataBuf(UART_Typedef uartx,U8 *data,U32 len)
{
unsigned char i;
for(i=0;i<len;i++){
UART_SendData(uartx,data[i]);
}
}
void UART_SendString(UART_Typedef uartx,U8 *s)
{
U32 len = strlen((char*)s);
UART_SendDataBuf(uartx,s,len);
}
void UART_Printf(char *fmt,...)
{
va_list ap;
char string[1024];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
va_end(ap);
UART_SendString(UART0,(U8 *)string);
}
U8 UART_ReceiveData(UART_Typedef uartx)
{
//while(!(UART_BASE_PTR[uartx]->UTRSTAT&0x01));
return (UART_BASE_PTR[uartx]->URXH);
}
void UART_IRQService_Init(UART_Typedef uartx,U32 addr)
{
switch(uartx)
{
case UART0:
pISR_UART0 = addr;
break;
case UART1:
pISR_UART1 = addr;
break;
case UART2:
pISR_UART2 = addr;
break;
case UART3:
pISR_UART3 = addr;
break;
}
}
#include "S3C2451_vector.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
UART_MemMapPtr const UART_BASE_PTR[4] = {UART0_BASE_PTR,UART1_BASE_PTR,UART2_BASE_PTR,UART3_BASE_PTR};
void UART_Init(UART_Typedef uartx,UART_Init_Typedef uart_init_struct)
{
UART_BASE_PTR[uartx]->ULCON &= ~(0x3F);
//wordwidth
UART_BASE_PTR[uartx]->ULCON |= uart_init_struct.wordwidth;
//stop
UART_BASE_PTR[uartx]->ULCON |= (uart_init_struct.stop<<2);
//parity
UART_BASE_PTR[uartx]->ULCON |= (uart_init_struct.parity<<3);
//baud
if( 9600 == uart_init_struct.baudrate)
{
UART_BASE_PTR[uartx]->UBRDIV = 10;
UART_BASE_PTR[uartx]->UDIVSLOT = 0xeeeee;
}else if(115200 == uart_init_struct.baudrate)
{
UART_BASE_PTR[uartx]->UBRDIV = 34; //pclk=66.5Mhz
UART_BASE_PTR[uartx]->UDIVSLOT = 0xDFDD;
}
UART_BASE_PTR[uartx]->UCON &= ~(0x0f);
//enable tx
if((uart_init_struct.mode&UART_Mode_TX) == UART_Mode_TX)
{
UART_BASE_PTR[uartx]->UCON |= (1<<2);
}
//enable rx
if((uart_init_struct.mode&UART_Mode_RX) == UART_Mode_RX)
{
UART_BASE_PTR[uartx]->UCON |= 1;
}
}
void UART_SendData(UART_Typedef uartx,U8 data)
{
UART_BASE_PTR[uartx]->UTXH = data;
while(!(UART_BASE_PTR[uartx]->UTRSTAT&0x04));
}
void UART_SendDataBuf(UART_Typedef uartx,U8 *data,U32 len)
{
unsigned char i;
for(i=0;i<len;i++){
UART_SendData(uartx,data[i]);
}
}
void UART_SendString(UART_Typedef uartx,U8 *s)
{
U32 len = strlen((char*)s);
UART_SendDataBuf(uartx,s,len);
}
void UART_Printf(char *fmt,...)
{
va_list ap;
char string[1024];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
va_end(ap);
UART_SendString(UART0,(U8 *)string);
}
U8 UART_ReceiveData(UART_Typedef uartx)
{
//while(!(UART_BASE_PTR[uartx]->UTRSTAT&0x01));
return (UART_BASE_PTR[uartx]->URXH);
}
void UART_IRQService_Init(UART_Typedef uartx,U32 addr)
{
switch(uartx)
{
case UART0:
pISR_UART0 = addr;
break;
case UART1:
pISR_UART1 = addr;
break;
case UART2:
pISR_UART2 = addr;
break;
case UART3:
pISR_UART3 = addr;
break;
}
}
0 0
- 3.18
- 3.18
- 3.18
- 3.18
- 3.18
- 3.18
- 3.18
- 3.16~3.18
- web 3.18
- 3.18任务
- 12.3.3.18 Lock statements
- 2010 3.18 晴天
- 读书随笔_2016.3.18
- 周总结3.18
- 3.18内核的sk_buff
- 3.18日的总结
- 计划一(3.15-3.18)
- 3.18 Data Mining Query任务
- laravel源码阅读之框架实例
- 算法训练 和为T dfs
- 排序总结---冒泡排序
- 递归解决整数逆置
- GIS讲堂第四课-大量POI点的展示
- 3.18
- 基本粒子群算法matlab 程序
- 排序总结---桶排序
- HTTPS配置全记录
- Ubuntu下解决Git保存用户名和密码的方法
- SCU 4437Carries(数论)
- 数据结构之字符串
- 排序总结---堆排序
- centos7.3 打开端口失败