This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with interrup on P89C557E4

Hi, i'm having a problem with the interrupt routine for timer 0 on the P89C557E4 Philips chip.
The interrupt routine doesn't work when running the program. when i simulate it, it works fine.
below is the code:

#include <reg557.h>
#define TIMER0_COUNT 0xDC11 /* 10000h - ((11,059,200 Hz / (12 * FREQ)) - 17) */
static unsigned timer0_tick; /* timer tick variable */
/*------------------------------------------------------------------------------
static void timer0_isr (void);
This function is an interrupt service routine for TIMER 0. It should never
be called by a C or assembly function. It will be executed automatically
when TIMER 0 overflows.
------------------------------------------------------------------------------*/
static void timer0_isr (void) interrupt 1 using 1
{
/*------------------------------------------------
Stop Timer 0, adjust the timer 0 counter so that
we get another interrupt in 10ms, and restart the
timer.
------------------------------------------------*/
TR0 = 0; /* stop timer 0 */
TL0 = TL0 + (TIMER0_COUNT & 0x00FF);
TH0 = TH0 + (TIMER0_COUNT >> 8);
TR0 = 1; /* start timer 0 */
/*------------------------------------------------
Increment the timer tick. This interrupt should
occur approximately every 10ms. So, the resolution
of the timer will be 100Hz not including interrupt
latency.
------------------------------------------------*/
//timer0_tick++;
CMSR4 = 0;
}
/*------------------------------------------------------------------------------
void timer0_initialize (void);
This function enables TIMER 0. TIMER 0 generates a synchronous interrupt
once every 100Hz.
------------------------------------------------------------------------------*/
void timer0_initialize (void)
{
EA = 0; /* disable interrupts */
timer0_tick = 0;
TR0 = 0; /* stop timer 0 */
TMOD &= ~0x0F; /* clear timer 0 mode bits */
TMOD |= 0x01; /* put timer 0 into 16-bit no prescale */
TL0 = (TIMER0_COUNT & 0x00FF);
TH0 = (TIMER0_COUNT >> 8);
PT0 = 0; /* set low priority for timer 0 */
ET0 = 1; /* enable timer 0 interrupt */
TR0 = 1; /* start timer 0 */
EA = 1; /* enable interrupts */
}
/*------------------------------------------------------------------------------
unsigned timer0_count (void);
This function returns the current timer0 tick count.
------------------------------------------------------------------------------*/
unsigned timer0_count (void)
{
unsigned t;
EA = 0;
t = timer0_tick;
EA = 1;
return (t);
}
/*------------------------------------------------------------------------------
void timer0_delay (
unsigned count);
This function waits for 'count' timer ticks to pass.
------------------------------------------------------------------------------*/
void timer0_delay (
unsigned count)
{
unsigned start_count;
start_count = timer0_count (); /* get the starting count */
while ((timer0_count () - start_count) <= count) /* wait for count "ticks" */
{
}
}
void main (void)
{
timer0_initialize();
while (1)
  {
CMSR4 = !CMSR4;
//timer0_delay( 1 );
  }
}

thank you for any help you can provide me.

Parents
  • Hans, it is NOT being incremented, it is only when in debug mode.

    But in that same message, you said that in debug, you saw the variable move, but not the result returned by timer0_count(). That's the disparity I'm trying to resolve by that "volatile".

    And instead of looking at HEX output, you really should look at the assembly in your listing file (if you had uVision make one), or in the debugger.

Reply
  • Hans, it is NOT being incremented, it is only when in debug mode.

    But in that same message, you said that in debug, you saw the variable move, but not the result returned by timer0_count(). That's the disparity I'm trying to resolve by that "volatile".

    And instead of looking at HEX output, you really should look at the assembly in your listing file (if you had uVision make one), or in the debugger.

Children
No data