Hi Gary,

I responded to your message in the open discussion forum:

https://sourceforge.net/forum/message.php?msg_id=4457553

I am copying the answer here too (with the spelling errors corrected!):

ISRs in sdcc are non-reentrant! To see exactly what is going on check 
the generated asm code. In your code the variables UART_data, 
array_index, and delay_index are reset to zero every time the serial 
port ISR is activated. So, when a byte is transmitted inside the loop 
of the ISR, a new interrupt is generated and the variables 
controlling the loop are reset to zero, messing up everything! Either 
make the variables static, or even better don't initialize the 
variables at all. I tested your program with actual hardware with an 
AT89C51ED2 running at 22 MHZ. It sends 21 'X' every time I press 'D'. 
Some changes I made to your program to make it work in my hardware:

1) I used SDCC's <at89c51ed2.h> after fixing a typo in the 
declaration of CKCON0. I've updated the subversion repository already.

2) BRL=256-12; // 115200 baud at 22MHz in X2 mode

3) #define UART_TXD_DELAY_COUNT 20 //Because of slower clock

4) Commented out #define WATCHDOG_ON.  The program should work with 
the watch dog timer on, but I hadn't tested.

5) The most important:

void UART_interrupt(void) interrupt 4 using 2
{
    unsigned char UART_data; //Do not initialize!!!
    unsigned char array_index; //Do not initialize!!!
    unsigned long delay_index; //Do not initialize!!!

    [your code here...]
}

Jesus


At 02:06 PM 09/08/2007, Gary D. Sides wrote:


>All, I'm a newbie to SDCC.  So, I'm not sure if I'm asking for help 
>in the proper way.  If I am, sorry.
>
>Thanks for any suggestions you may have!!
>
>I've been working on converting a simple C program and compiling it 
>using SDCC instead of Keil C. The program uses the AT89C51 watchdog 
>timer, the serial port, and blinks an LED. When compiled using Keil, 
>the program works perfectly. The program simply outputs 21 exes 
>('X') in response to receiving a 'D' from a notebook PC. To compile 
>the program using SDCC, I first converted the AT89C51xDS header file 
>from Atmel so that sfr and sbit lines had the correct syntax. I also 
>toggled the the LED bit using ! rather than ~. Finally, I used 
>packihx to create the hex file.
>
>The program responds to receiving a 'D' from the notebook PC, but it 
>only transmits 8 characters instead of 21.
>
>Any suggestions? Thanks for your help in advance!!
>
>With apologies for the clutter, I've attached the code below:
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to