Hi all, i'm trying to set the serial communication up with the Timer 2 (TR2) as baudrate generator . and 19200 Baud. I don't have any errors or warnings. I can't print nothing to the serial UART window.
Copi of my Code:
#include <REG668.H> #include <stdio.h> void Main(void){ // Init off UART EC = 0x01; // PCA(Program CounterArray) InterruptEnable. EA = 0x01; // Global disable bit. If EA = 0, all interrupts are disabled. If EA = 1, each interrupt can be individually enabled or disabled by setting or clearing its enable bit. T2CON = 0x30; // 0b00110000 // set timer 2 til baudrate generator. RCAP2H = 0xff; RCAP2L = 0xd9; TR2 = 0x01; // Start/stop control for Timer 2. A logic 1 starts the timer. saættes = 1 her og ikke i T2CON. S0CON = 0x50; // (Enhanced UART) UART0 mode 1, 8-bit, reception enable ( 0x50=80 Dec =01010000 binary) betyder at SM1=1 & REN=1 Resten er deafault 0 i S0CON registret se fig 32 i data blad. ES0 = 0x01; while (1) { P1 ^= 0x01; /* Toggle P1.0 each time we print */ printf ("Hello World\n"); /* Print "Hello World" */ } }
Hello Hassan,
Assuming you are using a NXP P89C668, you would need to double check the data sheet for the correct SFR settings.
http://www.keil.com/dd/chip/3298.htm
If those are correct, double check your numbers using the Keil baud rate calculator:
http://www.keil.com/c51/baudrate.asp
You will need to modify the code you provided.
Try using the hello world example and the timer 2 example for reference. Hello can be found on your hard drive at:
\Keil\C51\Examples\HELLO\HELLO.Uv2
The timer 2 examples can be found here: http://www.keil.com/download/list/c51.htm
Finally use the simulator to debug your issue
If the code will not work in the simulator, it definitely will not work on the hardware.
Make sure you have the correct XTAL value set under project -> options for target -> target tab
Does the Keil simulator display the correct Baud rate when you debug? Is the timer set up correctly?
http://www.keil.com/dd/vtr/3298/879.htm http://www.keil.com/dd/vtr/3298/1947.htm
You did not mention anything about putchar. By default, Keil uses the putchar from the Keil library, which will be the same as this file, found on your hard drive at:
\Keil\C51\LIB\PUTCHAR.C