Dear All,
For the past few days I have been trying to send a string of data to the PC but I get a garbage value…
The following is the code…
#include “LPC24xx.h” /* LPC23xx/24xx definitions */
#define EA_BOARD_LPC24XX 0
#define LINE_FEED 0x0A
#define CARRIAGE_RET 0x0D
/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */
/* PLL input Crystal frequence range 4KHz~20MHz. */
#define Fosc 12000000
/* System frequence,should be less than 80MHz. */
#define Fcclk 48000000
#define Fcco 288000000
/* APB clock frequence , must be 1/2/4 multiples of ( Fcclk/4 ). */
/* If USB is enabled, the minimum APB must be greater than 16Mhz */
#define Fpclk (Fcclk / 2)
void ptchr(char c)
{
while(!(U0LSR && 0x20));
U0THR = c;
}
void UARTInit(unsigned long PortNum,unsigned long baudrate)
{
unsigned long Fdiv;
if ( PortNum == 0 )
{
PINSEL0 = 0x00000050; /* RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / baudrate; /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; /* DLAB = 0 */
U0FCR = 0x07; /* Enable and reset TX and RX FIFO. */
}
else if (PortNum == 1)
{
#if EA_BOARD_LPC24XX
PINSEL7 |= 0x0000000F; /* P3.16 TXD1, P3.17 RXD1 */
#else /* Default is Keil MCB2300 board */
PINSEL0 |= 0x40000000; /* Enable TxD1 P0.15 */
PINSEL1 |= 0x00000001; /* Enable RxD1 P0.16 */
#endif
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / baudrate ; /*baud rate */
U1DLM = Fdiv / 256;
U1DLL = Fdiv % 256;
U1LCR = 0x03; /* DLAB = 0 */
U1FCR = 0x07; /* Enable and reset TX and RX FIFO. */
}
}
int main (void)
{
int i;
char c[16]=“Philips LPC”;
UARTInit(0,9600); /* baud rate setting */
/* Keep Transmitting until Null character(‘\0’) is reached */
for(i=0;i<16;i++)
{
ptchr(c*);*
- }*
- U0THR=LINE_FEED;*
- U0THR=CARRIAGE_RET;*
_ /* Wait till U0THR and U0TSR are both empty */_ - while(!(U0LSR & 0x20)){}*
}
---------------------------------------------------------------------------
It would be great if someone can help me sort this problem…