|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
各位兄弟姐妹们好,小弟这几天刚刚学习s3c44b0x,今天用串口通信的时候,我让COM0发送数据20次,但是调试每次只能接到12~15次,不知道为什么。
哪位帮忙看一下程序,谢谢!
附上主函数的程序。(启动代码的大家都差不多就不贴了)
#include "44b.h"
void PortD_init(void);
void Timer0_init(void);
void Uart_init(int bps0,int bps1);
void Uart_send_char(int port_num,char data);
void delay(int t);
void Main(void){
int i;
char data;
data = 'C';
PortD_init();
Uart_init(9600,9600);
for(i = 0;i < 20;i ++){
delay(100);
Uart_send_char(0,'C');
}
while(1);
}
void delay(int t){
int i;
while(t--)
for(i = 0;i < 5000;i ++)
;
}
void PortD_init(void){
rPCOND = 0x5555;
rPUPD = 0x1;
rPDATD = 0xffff;
}
void Timer0_init(void){
void Timer0_ISR(void);
rINTCON = 0x5; //Non-vectored,IRQ enable,FIQ disable
rINTMOD = 0x0; //ALL = IRQ mode
rINTMSK = ~(BIT_TIMER0 | BIT_GLOBAL);
pISR_TIMER0 = (unsigned)Timer0_ISR;
rTCFG0 = 0x000000ff;//timer0 prescale value = 255// MCLK = 42M
rTCFG1 = 0x00000004;
rTCNTB0 = 4000;
rTCON = 0x0000000a;
rTCON = 0x00000009;
}
void __irq Timer0_ISR(void){
static int v = 0x0000;
rI_ISPC = BIT_TIMER0;
v = ~v;
rPDATD = v;
}
//【串口初始化】
void Uart_init(int bps0,int bps1){
//【bps0-------串口0波特率】
//【bps1-------串口1波特率】
rINTCON = 0x5; //Non-vectored,IRQ enable,FIQ disable
rINTMOD = 0x0; //ALL = IRQ mode
rINTMSK = ~(BIT_UTXD0 | BIT_UTXD1 | BIT_GLOBAL);
rULCON0 = 0x03; //UART0 is 8bit,1 stop bit ,no parity,Normal mode operation
rULCON1 = 0x03; //UART1 is 8bit,1 stop bit ,no parity,Normal mode operation
rUCON0 = 0x205; //Interrupt UART0 is requested while Tx buffer is empty
rUCON1 = 0x205; //Interrupt UART1 is requested while Tx buffer is empty
rUFCON0 = 0x00; //FIFO is disable
rUFCON1 = 0x00; //FIFO is disable
rUMCON0 = 0x00; //AFC is disable
rUMCON1 = 0x00; //AFC is disable
rUBRDIV0 = (int)(42000000 / 16 / bps1 + 0.5) - 1;// (int)(42000000 / (9600 * 16)) - 1; //UART0 baud rate is 9600
rUBRDIV1 = (int)(42000000 / 16 / bps1 + 0.5) - 1; //UART1 baud rate is 9600
}
//【串口发送】
void Uart_send_char(int port_num,char data){
//【port_num】 :端口号(0 或 1)
//【data】 :字符型
int flag = 1;
int rTR;
while(flag){
rTR = rUTRSTAT0 & 0x2;
if(rTR == 0x2) {
if (port_num == 0)
rUTXH0 = data;
else
rUTXH1 = data;
flag = 0;
}
}
}
[ 本帖最后由 angle3839 于 2007-12-1 22:02 编辑 ] |
|