Mark Swayne wrote:
> I don't have any ideas specific to Timer 1 and SDCC. But I do have a
> Are your ISRs being run? You need to make sure that your ISRs are
> defined when your main() routine is compiled, otherwise null, stand-in
> ISRs will be used instead.
> I have my ISRs defined in various, device specific files, but I make
> sure that they have declarations in header files that can be #included
> in main.c.
> Do you get any output when you print something with printf() or putchar()?
Thank you for the reply Mark. I have written a couple other programs
that use isr and did know about the need to put the header file within
the same scope as the main function. I've tried printing with putchar
with and without ISRs being enabled. Technically, you don't have to
have the isr enabled to print or receive input. You can manually watch
the RI and TI bits and read/write when they are set. This is the
approach taken in the simple example program:
<sdcc_dir>/device/examples/mcs51/simple (notice ES=1 is commented out)
and it's also the approach taken for the keil examples:
Keil also provides an example that uses the serial interrupt:
With any of these examples, Timer 1 is used to generate the baud rate. I do get output with sdcc when I attempt to use Timer 1. I get continuous 0x00 when I use putchar. getchar never receives input. If I change the baud rate on the client (gtkterm, I get varying types of incorrect output.) All of the examples work properly when I switch the code to use T2CON (Timer 2) instead of Timer 1. The thing is, the examples work correctly with Keil. Timer 1 is used to control the baud rate and I get correct input/output functionality with printf. I haven't yet figured out why compiling with sdcc doesn't seem to set things up correctly but I think it has to do with the baud rate calculations and overflow values for TH1. I changed the OSCILLATOR value in the clock example to be 12mhz (which is what the fx2 chip is operating at) but that didn't help.
Here is something that does work though, if I change the example from keil:
to use the include files from sdcc, I start to get the correct functionality:
//-------- working ---------------
void main (void)
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 */
unsigned char aaa;
aaa = getchar();
//-------- end working ------------
So in summary, I think that the fx2 has picky reload values for the timer auto reload at the least. I also thing there may possibly be some issues with the calculations in the clock and simple examples that come with sdcc. It could be that they are hardware specific issues though. In the mean time, I'm happy enough using Timer 2 instead of Timer 1.