8051 - printf for p89v664 prints junk characters from actual micro controller -
i trying print message on serial terminal p89v664 using following code,
#include<p89v66x.h> #include<stdio.h> char putchar(char c) { if (c == '\n') { while (!ti); ti = 0; s0buf = 0x0d; } ti = 0; s0buf = c; while (!ti); return c; } int printf(char*str) { unsigned int cnt = 0; while(*str != '\0') { putchar(*str); cnt++; str++; } } void delay(unsigned int i) { int d = 100; for(;i!=0;i--) { for(;d!=0;d--); d = 100; } } int main(void) { /**serial init*/ s0con = 0x50; /* scon: mode 1, 8-bit uart, enable rcvr */ tmod |= 0x20; /* tmod: timer 1, mode 2, 8-bit reload */ th1 = 0xf6; /* th1: reload value 9600 baud */ tr1 = 1; /* tr1: timer 1 run */ ti = 1; while(1) { printf("hello\n"); delay(300); printf("hello world\n"); delay(10000); } }
above program works fine till time printf function definition in program not commented. if printf function in above program commented use printf standard library junk characters printed on serial console. (i used putty). used keil uvision v4.14.4.0 compiler.
is there missing? dont understand wrong program.
after experiments found problem keil uvision4 evaluation version. compiled code using sdcc , ran , worked. may keil evaluation version's limitation creating problem. thank mellowcandle replies.
edit:
#include <p89v66x.h> #include<stdio.h> void putchar(char c) { ti = 0; s0buf = c; if (c == '\n') { while (!ti); ti = 0; s0buf = 0x0d; } while (!ti); } int main(void) { /**serial init*/ unsigned short int c = 65334; s0con = 0x50; /* scon: mode 1, 8-bit uart, enable rcvr */ tmod |= 0x20; /* tmod: timer 1, mode 2, 8-bit reload */ /**for 11.0592 crystal value should th = -3 or th1 = fd*/ th1 = 0xf6; /* th1: reload value 9600 baud 18 mhz cyrstal */ tr1 = 1; /* tr1: timer 1 run */ while(1) { printf("hello %u\n", c); delay(300); printf("hello world %u\n" ,c); delay(10000); } }
command used compile code is,
sdcc {filename}
Comments
Post a Comment