I have a very simple but annoying problem. I use printf () in my code and either on Keil or Proteus simulations it works. However, when I load this code to my microcontroller, which is DS89C450, it does not work.I also add the putchar.c and getkey.c to my source code. Characters, observed on Terminal Emulator are dots and squares and sometimes endless loops. The baud rate is correct. I test it by sending characters via SBUF0. The code is right here.
#include <DS89C4xx.H> #include <stdio.h> void main (void) { SCON0=0x50; TMOD=0x20; TH1=0xFC; //9600 bps with 14.7456 MHz crystal TR1=1; TI_0=1; while (1) { printf ("test\n"); }
I changed putchar.c in c51/lib to that.
/***********************************************************************/ /* This file is part of the C51 Compiler package */ /* Copyright KEIL ELEKTRONIK GmbH 1990 - 2002 */ /***********************************************************************/ /* */ /* PUTCHAR.C: This routine is the general character output of C51. */ /* You may add this file to a uVision2 project. */ /* */ /* To translate this file use C51 with the following invocation: */ /* C51 PUTCHAR.C <memory model> */ /* */ /* To link the modified PUTCHAR.OBJ file to your application use the */ /* following Lx51 invocation: */ /* Lx51 <your object file list>, PUTCHAR.OBJ <controls> */ /* */ /***********************************************************************/ #include <DS89C4xx.H> #define XON 0x11 #define XOFF 0x13 /* * putchar (full version): expands '\n' into CR LF and handles * XON/XOFF (Ctrl+S/Ctrl+Q) protocol */ char putchar (char c) { if (c == '\n') { if (RI_0) { if (SBUF0 == XOFF) { do { RI_0 = 0; while (!RI_0); } while (SBUF0 != XON); RI_0 = 0; } } while (!TI_0); TI_0 = 0; SBUF0 = 0x0d; /* output CR */ } if (RI_0) { if (SBUF0 == XOFF) { do { RI_0 = 0; while (!RI_0); } while (SBUF0 != XON); RI_0 = 0; } } while (!TI_0); TI_0 = 0; return (SBUF0 = c); } #if 0 // comment out versions below /* * putchar (basic version): expands '\n' into CR LF */ char putchar (char c) { if (c == '\n') { while (!TI_0); TI_0 = 0; SBUF0 = 0x0d; /* output CR */ } while (!TI_0); TI_0 = 0; return (SBUF0 = c); } /* * putchar (mini version): outputs charcter only */ char putchar (char c) { while (!TI_0); TI_0 = 0; return (SBUF0 = c); } #endif
You may still be linking with the library version of putchar(). Try putting a breakpoint in your putchar() and see if it is being called.
www.maxim-ic.com/.../do