[首页]
[文章]
[教程]
首页
Web开发
Windows开发
编程语言
数据库技术
移动平台
系统服务
微信
设计
布布扣
其他
数据分析
首页
>
其他
> 详细
16V554 的测试代码
时间:
2015-11-11 23:55:27
阅读:
426
评论:
0
收藏:
0
[点我收藏+]
/* SC16C554 */
#define SC16C554_BASE ( (unsigned char *) 0x50004000 )
#define SC16C554_PORTA_BASE ( (unsigned char *) 0x50004000 )
#define SC16C554_PORTB_BASE ( (unsigned char *)
0x50004100
)
#define SC16C554_PORTC_BASE ( (unsigned char *) 0x50004200 )
#define SC16C554_PORTD_BASE ( (unsigned char *) 0x50004300 )
char *SC16C554_RegPtrA = (
char *)SC16C554_PORTA_BASE;
char *SC16C554_RegPtrB = (
char *)SC16C554_PORTB_BASE;
char *SC16C554_RegPtrC = (
char *)SC16C554_PORTC_BASE;
char *SC16C554_RegPtrD = (
char *)SC16C554_PORTD_BASE;
extern
void DelayMs(unsigned
char Count);
/************************************************************************/
#define Port_RHR 0
#define Port_THR 0
#define Port_IER 1
#define Port_ISR 2
#define Port_FCR 2
#define Port_LCR 3
#define Port_MCR 4
#define Port_LSR 5
#define Port_MSR 6
#define Port_SR 7
#define Port_DLL 0
#define Port_DLM 1
/************************************************************************/
#define BAUD_2400_DLL 0xC0
#define BAUD_2400_DLM 0x0
#define BAUD_4800_DLL 0x60
#define BAUD_4800_DLM 0x0
#define BAUD_9600_DLL 0x30
#define BAUD_9600_DLM 0x0
#define BAUD_19200_DLL 0x18
#define BAUD_19200_DLM 0x0
#define BAUD_38400_DLL 0x0C
#define BAUD_38400_DLM 0x0
#define BAUD_57600_DLL 0x08
#define BAUD_57600_DLM 0x0
#define BAUD_76800_DLL 0x06
#define BAUD_76800_DLM 0x0
#define BAUD_115200_DLL 0x04
#define BAUD_115200_DLM 0x0
#define BAUD_153600_DLL 0x03
#define BAUD_153600_DLM 0x0
#define BAUD_230400_DLL 0x02
#define BAUD_230400_DLM 0x0
#define BAUD_460800_DLL 0x01
#define BAUD_460800_DLM 0x0
/************************************************************************/
#define PORTA 0
#define PORTB 1
#define PORTC 2
#define PORTD 3
/************************************************************************/
void SC16C554_init(
void)
{
*(SC16C554_RegPtrA + Port_LCR) = 0x80;
*(SC16C554_RegPtrA + Port_DLL) = BAUD_115200_DLL;
*(SC16C554_RegPtrA + Port_DLM) = BAUD_115200_DLM;
*(SC16C554_RegPtrA + Port_LCR) = 0x03;
// N,8,1
*(SC16C554_RegPtrA + Port_FCR) = 0x00;
*(SC16C554_RegPtrA + Port_MCR) = 0x08;
*(SC16C554_RegPtrA + Port_IER) = 0x05;
*(SC16C554_RegPtrB + Port_LCR) = 0x80;
*(SC16C554_RegPtrB + Port_DLL) = BAUD_115200_DLL;
*(SC16C554_RegPtrB + Port_DLM) = BAUD_115200_DLM;
*(SC16C554_RegPtrB + Port_LCR) = 0x03;
// N,8,1
*(SC16C554_RegPtrB + Port_FCR) = 0x00;
*(SC16C554_RegPtrB + Port_MCR) = 0x08;
*(SC16C554_RegPtrB + Port_IER) = 0x05;
*(SC16C554_RegPtrC + Port_LCR) = 0x80;
*(SC16C554_RegPtrC + Port_DLL) = BAUD_115200_DLL;
*(SC16C554_RegPtrC + Port_DLM) = BAUD_115200_DLM;
*(SC16C554_RegPtrC + Port_LCR) = 0x03;
// N,8,1
*(SC16C554_RegPtrC + Port_FCR) = 0x00;
*(SC16C554_RegPtrC + Port_MCR) = 0x08;
*(SC16C554_RegPtrC + Port_IER) = 0x05;
*(SC16C554_RegPtrD + Port_LCR) = 0x80;
*(SC16C554_RegPtrD + Port_DLL) = BAUD_115200_DLL;
*(SC16C554_RegPtrD + Port_DLM) = BAUD_115200_DLM;
*(SC16C554_RegPtrD + Port_LCR) = 0x03;
// N,8,1
*(SC16C554_RegPtrD + Port_FCR) = 0x00;
*(SC16C554_RegPtrD + Port_MCR) = 0x08;
*(SC16C554_RegPtrD + Port_IER) = 0x05;
}
/************************************************************************/
void Reset16C554(
void)
{
AT91F_PIO_SetOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);
DelayMs(50);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);
DelayMs(50);
}
/************************************************************************/
void SC16C554_Send(unsigned
char Port,unsigned
char *buf,unsigned
short len)
{
unsigned
short i;
if(Port == PORTA)
{
for(i=0;i<len;i++)
{
*(SC16C554_RegPtrA + Port_THR) = buf[i];
}
}
if(Port == PORTB)
{
for(i=0;i<len;i++)
{
*(SC16C554_RegPtrB + Port_THR) = buf[i];
}
}
if(Port == PORTC)
{
for(i=0;i<len;i++)
{
*(SC16C554_RegPtrC + Port_THR) = buf[i];
}
}
if(Port == PORTD)
{
for(i=0;i<len;i++)
{
*(SC16C554_RegPtrD + Port_THR) = buf[i];
}
}
}
/************************************************************************/
unsigned
char SC16C554_Receive(unsigned
char Port)
{
unsigned
char TempChar;
unsigned
char IntStatus;
if(Port == PORTA)
{
TempChar = *(SC16C554_RegPtrA + Port_RHR);
IntStatus = *(SC16C554_RegPtrA + Port_ISR);
}
if(Port == PORTB)
{
TempChar = *(SC16C554_RegPtrB + Port_RHR);
IntStatus = *(SC16C554_RegPtrB + Port_ISR);
}
if(Port == PORTC)
{
TempChar = *(SC16C554_RegPtrC + Port_RHR);
IntStatus = *(SC16C554_RegPtrC + Port_ISR);
}
if(Port == PORTD)
{
TempChar = *(SC16C554_RegPtrD + Port_RHR);
IntStatus = *(SC16C554_RegPtrD + Port_ISR);
}
return TempChar;
}
16V554 的测试代码
原文:http://www.cnblogs.com/zym0805/p/4957658.html
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年09月23日 (328)
2021年09月24日 (313)
2021年09月17日 (191)
2021年09月15日 (369)
2021年09月16日 (411)
2021年09月13日 (439)
2021年09月11日 (398)
2021年09月12日 (393)
2021年09月10日 (160)
2021年09月08日 (222)
最新文章
更多>
2021/09/28 scripts
2022-05-27
vue自定义全局指令v-emoji限制input输入表情和特殊字符
2022-05-27
9.26学习总结
2022-05-27
vim操作
2022-05-27
深入理解计算机基础 第三章
2022-05-27
C++ string 作为形参与引用传递(转)
2022-05-27
python 加解密
2022-05-27
JavaScript-对象数组里根据id获取name,对象可能有children属性
2022-05-27
SQL语句——保持现有内容在后面增加内容
2022-05-27
virsh命令文档
2022-05-27
教程昨日排行
更多>
1.
list.reverse()
2.
Django Admin 管理工具
3.
AppML 案例模型
4.
HTML 标签列表(功能排序)
5.
HTML 颜色名
6.
HTML 语言代码
7.
jQuery 事件
8.
jEasyUI 创建分割按钮
9.
jEasyUI 创建复杂布局
10.
jEasyUI 创建简单窗口
友情链接
汇智网
PHP教程
插件网
关于我们
-
联系我们
-
留言反馈
- 联系我们:wmxa8@hotmail.com
© 2014
bubuko.com
版权所有
打开技术之扣,分享程序人生!