This is code for showing temperature sensed value of UART0 of lpc2138
#include <stdio.h> #include"LPC213.h" // Define LPC2148 Header File
#define CR 0x0D #define DONE 0x80000000 #define START 0x01000000 #define PRESET 0x00230600
void Delay (); void init_serial (void); int putchar (int ch); int getchar(void); int main () { unsigned long Val; char *Ptr = "Current Temperature is:"; VPBDIV = 0x02; //pclk @ 30MHz init_serial(); PINSEL1 = 0x01 << 24; //P0.28 configure as ADC0.1 AD0CR = PRESET | 0x02; AD0CR |= START; //Start Conversion NOW while (1) { do { Val = AD0GDR; } while ((Val & DONE) == 0); Val = ((AD0GDR >> 6) & 0x3FF); while (*Ptr) { putchar(*Ptr++); } printf ("%4d ", Val); putchar(getchar()); // Echo terminal
} //printf ("\xF8\F \r"); }
void Delay () { unsigned int i,j; for (i=0;i<50;i++) for (j=0;j<500;j++); }
void init_serial (void) { PINSEL0 = 0x00000005; // Enable RxD0 and TxD0 U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB Clock U0LCR = 0x00000003; } int putchar (int ch) { if (ch == '\n') { while (!(U0LSR & 0x20)); U0THR = CR; } while (!(U0LSR & 0x20)); return (U0THR = ch); } int getchar(void) { while (!(U0LSR & 0x01)); return (U0RBR); }
This is the above code which shows following errors when I add studio.h header file in code
compiling adc.c... adc.c(9): warning: #1295-D: Deprecated declaration Delay - give arg types adc.c(11): error: #79: expected a type specifier adc.c(12): error: #55: too many arguments in macro invocation adc.c(12): error: #79: expected a type specifier adc.c(55): error: #79: expected a type specifier adc.c(55): error: #141-D: unnamed prototyped parameters not allowed when body is present adc.c(65): error: #55: too many arguments in macro invocation adc.c(65): error: #79: expected a type specifier adc.c(65): error: #141-D: unnamed prototyped parameters not allowed when body is present Target not created
And if I dont add studio.h header file then printf function doesn't work. What should I do in this case? I guess I need printf function in order to print ADC value to the UART terminal.
Read the posting tips lest we assume you're a fool. http://www.keil.com/forum/tips.asp
Could it be that if you don't have the printf() it doesn't call the SWI and fault? Could you use a debugger and identify what's going on? Could you look at the .MAP and see what's linking in?
The compiler gives errors if the syntax is wrong. The linker gives errors if the binding is wrong. Neither can tell if your code is functionally correct.
Like I said, go review how to actually retarget the stdio/console functionality in Keil.
http://www.keil.com/forum/58917/