Tamasco
Full Member level 3
lpc2000 uart
I wrote the following program for the NXP LPC2000 mcu. The progam compiles whenever i comment out the library header file #include <stdio.h> . But the problem is that it doesn't work when i load it! I guess it's because #include <stdio.h> has been commented out. The program is provided below.
I would appreciate it if u could help me out.
Thanks in advace.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
define CR 0x0D
#include <LPC21xx.H>
#include <stdio.h> //the program compiles when i comment this out!
#include <string.h>
//my function prototypes
void init_serial (void);
int putchar (int ch);
int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
init_serial();
while(1)
{
printf("Hello Engineer.... TEST UART-0\n"); // Call printf Function
printf("Press any key to continue....\n"); //Echo terminal
}
}
void init_serial (void) /* Initialize Serial Interface */
{
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 0x000000C2; /* 9600 Baud Rate @ 30MHz VPB Clock */
U1LCR = 0x00000003; /* DLAB = 0 */
}
int putchar (int ch) /* Write character to Serial Port */
{
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getchar (void) /* Read character from Serial Port */
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
I wrote the following program for the NXP LPC2000 mcu. The progam compiles whenever i comment out the library header file #include <stdio.h> . But the problem is that it doesn't work when i load it! I guess it's because #include <stdio.h> has been commented out. The program is provided below.
I would appreciate it if u could help me out.
Thanks in advace.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
define CR 0x0D
#include <LPC21xx.H>
#include <stdio.h> //the program compiles when i comment this out!
#include <string.h>
//my function prototypes
void init_serial (void);
int putchar (int ch);
int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
init_serial();
while(1)
{
printf("Hello Engineer.... TEST UART-0\n"); // Call printf Function
printf("Press any key to continue....\n"); //Echo terminal
}
}
void init_serial (void) /* Initialize Serial Interface */
{
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 0x000000C2; /* 9600 Baud Rate @ 30MHz VPB Clock */
U1LCR = 0x00000003; /* DLAB = 0 */
}
int putchar (int ch) /* Write character to Serial Port */
{
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getchar (void) /* Read character from Serial Port */
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`