|
开始接触ARM编程,由于用的是Windows7,ADS用的有问题,所以用了KEIL MDK4.22编译系统,
编了一个串口程序,按照要求应该是输出Hello,World然后进入While(1)循环,不过串口不断输出Hello,World,很是不解。
项目中包含:S3C44B0X.S/main.c/uart.c
源代码如下:
------------------------------以下是main.c-----------------------------------
#include <S3C44B0X.H>
#include "44blib.h"
main()
{
PLL_init();
Uart_init();
Uart_printf("-----hello,world--------\n");
Uart_printf("abcdefghijklmn\n");
while(1);
}
--------------------------以上是main.c------------------------------------
--------------------------以下是uart.c------------------------------------
#include <S3C44B0X.H>
#define MCLK 64000000
const unsigned char mdiv=120;
const unsigned char pdiv=6;
const unsigned char sdiv=1;
void Delay(int m)
{
int i,j;
for(i=0;i<=m;i++)
for(j=0;j<=100;j++);
}
PLL_init()
{
pCLK->PLLCON = (mdiv<<12)|(pdiv<<4)|(sdiv); //main clock is 64MHz
}
Uart_init()
{
pPIO->PCONE = 0x28; //PE2,PE3 -->Uart Mode
rULCON0 = 0x03;
rUCON0 = 0x05;
rUFCON0 =0x00;
rUMCON0 =0x00;
rUBRDIV0= ( (int)(MCLK/16.0/115200 + 0.5) -1 ); //bardrate is 115200pbs
}
void Uart_SendByte(char data)
{
if(data=='\n')
{
while(!(rUTRSTAT0 & 0x2));
// Delay(10); //because the slow response of hyper_terminal
WrUTXH0('\r');
}
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
// Delay(10);
WrUTXH0(data);
}
void Uart_SendString(char *pt)
{
while(*pt != '\0')
Uart_SendByte(*pt++);
}
Uart_printf(char *fmt)
{
Uart_SendString(fmt);
}
---------------以上uart.c---------------------------------
上面程序的目的是调用
Uart_printf("-----hello,world--------\n");
Uart_printf("abcdefghijklmn\n");这两个语句后进入while(1);
不过只能不断的接收-----hello,world--------\n,系统一直在发送。abcdefghijklmn\n这个字符串没有接收到,应该是没有运行到这里,
请各位大师看下是什么原因。 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|