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

Strange behaviour in TIMER0 ISR

Hi all, I have a problem with the ISR of TIMER0.
I'm using keil uVision2 and my target is SIlicon Laboratories C8051F040.

I've tried to make a very simple project in assembler to use Timer0 ISR (below you will find the relatives code) and it works fine.

If I try to translate this project in C, the ISR is called just a few time (around 10 or 11 times) but after this, it is never called!

But... if, instead of Timer0, I use Timer1, all work fine both in C and in Assembler

I can't understand why?
There is someone wich can help me?

NOTE: Is not important the reload value so i don't set it, and although if I set this value the behaviour not change.
NOTE: Timer0 is a 16-bit timer
NOTE: In the examples below I've hided the not relevant code like oscillator init, port init,...

--------------
ASSEMBLY CODE:
--------------

        ...
        ...
        ...

;TIMER_0 Overflow
ORG 0x000B
        LCALL TIMER0_INT

        ...
        ...
        ...


TIMER_INIT:
        NOP

;------
;TIMER0
;TIMER1
;------
        MOV SFRPAGE, #TIMER01_PAGE
        MOV TCON, #01000101b
        MOV TMOD, #00100001b

        ...
        ...
        ...

INTERRUPTS_INIT:
        MOV IE, #10010111b
        MOV IP, #00000000b
        MOV EIE1, #00001000b
        MOV EIE2, #01000000b
        MOV EIP1, #00001000b
        MOV EIP2, #00000000b

        ...
        ...
        ...


MAIN:
        MOV SFRPAGE, TIMER01_PAGE
        SETB TR0                        ;START TIMER

        JMP $


        ...
        ...
        ...


TIMER0_INT:

        RETI

-------
C CODE:
-------

...
...
...


void Timer_Init() { SFRPAGE = TIMER01_PAGE; TCON = 0x45; TMOD = 0x21; CKCON = 0x18; SFRPAGE = TMR2_PAGE; TMR2CN = 0x04; TMR2CF = 0x08; SFRPAGE = TMR3_PAGE; TMR3CN = 0x04; TMR3CF = 0x08; SFRPAGE = TMR4_PAGE; TMR4CN = 0x04; TMR4CF = 0x08; }
... ... ...
void Interrupts_Init() { IE = 0x97; EIE1 = 0x08; EIE2 = 0x40; EIP1 = 0x08; }
... ... ...
void main(void){
Timer_Init(); Interrupts_Init() ... ... ...
SFRPAGE = TIMER01_PAGE; TR0 = 1; //START TIMER
while(1);
}
void timer0_int(void) reentrant interrupt 1 {
}

Parents
  • but just for this, I would reduce your waste of time focusing on real problem
    how can we do that when the first thing we see is a glaring error (resulting from your 'copying'). Do you ASS U ME that we would know that this "is not your problem"?, if so you are sadly mistaken. YOU and only YOU can "reduce your waste of time" by posting what you have and not an erroneous copy of it.

    Anyhow in your code you will generate T1 interrupts and you show no T1 ISR, is there one in the assembler and not in the C

    Erik

Reply
  • but just for this, I would reduce your waste of time focusing on real problem
    how can we do that when the first thing we see is a glaring error (resulting from your 'copying'). Do you ASS U ME that we would know that this "is not your problem"?, if so you are sadly mistaken. YOU and only YOU can "reduce your waste of time" by posting what you have and not an erroneous copy of it.

    Anyhow in your code you will generate T1 interrupts and you show no T1 ISR, is there one in the assembler and not in the C

    Erik

Children
No data