TQ2440 是由广州天嵌计算机科技有限公司精心打造的一款开发板。以稳定的性能,过硬的质量,丰富的扩展接口,优质的售后服务和技术支持,赢得众多企业的青睐和支持。
//=========================================
// NAME: main.c
// DESC: TQ2440串口UART打印printf测试程序
//=========================================
/* 头文件包含 */
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include
#include
static volatile int uart_port = 0;
void uart_init(int pclk,int buad,int ch)
{
//UART初始化:端口使能、功能设定、波特率、设置数据格式
rGPHCON = (rGPHCON & ~(0xfff<<4)) | (0xaaa<<4);//端口RX[0:2]、TX[0:2]功能
rGPHUP = rGPHUP | (0x7<<1); //端口GPH[1:3]禁止上拉
rUFCON0 = 0x0; //禁止FIFO
rUFCON1 = 0x0; //禁止FIFO
rUFCON2 = 0x0; //禁止FIFO
rUMCON0 = 0x0; //禁止AFC
rUMCON1 = 0x0; //禁止AFC
//Normal:No parity:One stop:8-bits 中断响应 UART clock: PCLK
rULCON0 = (rULCON0 & ~0xff) | ((0x0<<6)|(0x0<<3)|(0x0<<2)|(0x3));
rUCON0 = (rUCON0 & ~0x3ff) | ((0x1<<9)|(0x1<<6)|(0x1<<2)|(0x1));
rUBRDIV0 = ((int)(pclk/16./buad+0.5)-1);
rULCON1 = (rULCON1 & ~0xff) | ((0x0<<6)|(0x0<<3)|(0x0<<2)|(0x3));
rUCON1 = (rUCON1 & ~0x3ff) | ((0x1<<9)|(0x1<<6)|(0x1<<2)|(0x1));
rUBRDIV1 = ((int)(pclk/16./buad+0.5)-1);
rULCON2 = (rULCON2 & ~0xff) | ((0x0<<6)|(0x0<<3)|(0x0<<2)|(0x3));
rUCON2 = (rUCON2 & ~0x3ff) | ((0x1<<9)|(0x1<<6)|(0x1<<2)|(0x1));
rUBRDIV2 = ((int)(pclk/16./buad+0.5)-1);
uart_port = ch; //设置串口端口号
}
void uart_send_byte(int data)
{
if(0 == uart_port)
{
if(data == 'n')
{
while(!(rUTRSTAT0 & 0x2));
rUTXH0 = 'n';
}
while(!(rUTRSTAT0 & 0x2));
rUTXH0 = data;
}
else if(1 == uart_port)
{
if(data == 'n')
{
while(!(rUTRSTAT1 & 0x2));
rUTXH1 = 'n';
}
while(!(rUTRSTAT1 & 0x2));
rUTXH1 = data;
}
else if(2 == uart_port)
{
if(data == 'n')
{
while(!(rUTRSTAT2 & 0x2));
rUTXH2 = 'n';
}
while(!(rUTRSTAT2 & 0x2));
rUTXH2 = data;
}
}
void uart_send_string(char *string)
{
while(*string)
{
uart_send_byte(*string++);
}
}
void uart_printf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
uart_send_string(string);
va_end(ap);
}
void Main(void)
{
int plck_val = 50000000;
int buad_val = 115200;
int ch_val = 0;
uart_init(plck_val,buad_val,ch_val);
uart_printf("PCLK is %d,buad is %d,uart_port is %d n",plck_val,buad_val,ch_val);
while(1);
}
感谢晨旭晚霞的支持!
供货情况:
天嵌科技提供专业嵌入式板卡和行业解决方案。如有需要,可以联系天嵌科技的销售人员。
销售电话:020-38219416 38373101
技术支持:020-38219416转807 820
网址:http://www.embedsky.com
用户1476573 2016-3-24 15:47
用户1476573 2016-3-24 15:46
用户1871543 2016-3-24 15:33
用户164119 2016-3-24 14:15
用户164119 2016-3-24 14:14
用户1871547 2016-3-23 16:46
用户1871598 2016-3-21 14:55
用户1871561 2016-3-21 12:26