We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
When I use printf, the uP hangs. When I use SBUF it owrks fine, what can be the problem ??? Hope someone can help me. I use an Atmel 89c52. Kindest regards, Ben Goofers #include <At89x52.h> /* special function register declarations */ #include <stdio.h> /* prototype declarations for I/O functions */ void main (void) { /*------------------------------------------------ Setup the serial port for 9600 baud at 11.0592MHz. ------------------------------------------------*/ TR1 = 0; SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ PCON &= 0x7F; TH1 = 0xFD; /* TH1: reload value for 9600 baud @ 11.0592MHz */ // EA = 1; // ES = 1; RI = 1; TI = 1; TR1 = 1; /*------------------------------------------------ Note that an embedded program never exits (because there is no operating system to return to). It must loop and execute forever. ------------------------------------------------*/ printf ("hallo\r"); <=- with this line it doesn't work anymore !!!!!!!!!!!!!!!!! while (1) { TI = 0; SBUF = 'A'; while (!TI); P1 ^= 0xFF; TI=0; SBUF = '*'; while (!TI); TI=0; SBUF = '\r'; while (!TI); } }
Be sure you don't enable that serial interrupt (IE.ES should be 0) since you don't have an ISR to handle the serial interrupt. I see you figured that out.
// Override the default putchar() used by printf(). Just put this // function in your project (maybe uart.c) and link it in. // ANSI says take in and return int but we'll use char since we don't // return error status anyway and char is much more friendly to the 8051. char putchar(char outChar) { // CR -> CR/LF translation if needed. if ('\n' == outChar) { SBUF = '\r'; while (!TI); TI = 0; } // Send the caller's char and be sure it shifts out before returning. SBUF = outChar; while (!TI); TI = 0; return outChar; }