Ok. I'm sure this is a very elementary question, but I really don't know much yet. I've got a Silabs 8051 development kit ( www.silabs.com/.../C8051F330DK.htm ) and I'm trying to learn about serial IO. I'm trying to get the following code to work:
#include "c8051f330.h" #include "reg51.h" #include "stdio.h" #include "initdevice.h" void main (void)
{ Timer_Init(); UART_Init(); Port_IO_Init(); SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 0xf3; /* TH1: reload value for 2400 baud */ TR1 = 1; /* TR1: timer 1 run */ TI = 1; /* TI: set TI to send first char of UART */
while(1) { unsigned char aaa; aaa = _getkey(); putchar(aaa); } }
Now, presumably all I would have to change is to include something like this as initdevice.h to set up the crossbar right?:
void Timer_Init() { TMOD = 0x20; CKCON = 0x01; TH1 = 0xB1; }
void UART_Init() { SCON0 = 0x10; }
void Port_IO_Init() { XBR0 = 0x01; XBR1 = 0x40; }
If this worked, I'd be able to hook hyperterminal up to the serial port and whatever I type will get echoed, right? Doesn't seem to work, and I'm just hoping someone can give me a push in the right direction. Thanks. Sorry if this is stupid.
OK, I realize I typed that wrong and seem to be initializing the timer and UART twice and differently. Lets pretend that didn't happen and concentrate only on the first initializations of those and the Port_IO_Init() in the header. I wish I could edit my first post. Sorry.
Lets pretend that didn't happen
No, let's NOT 'pretend', 'pretending' is not an accepted software designing/debugging method, why do you not cut and paste the actual code that has the problem.
Erik
Sorry for the poor form. I did, however, find a bit of sample code elsewhere which does work that I'll be attempting to adapt to my purposes, so for now, problem solved. But thank you, and I promise not to pretend anymore.