Timer interrupt subroutine counters not working

20 views Asked by At

I am working with the microcontroller Philips 80C552.

I have created this subroutine for my program's timer interrupt to execute every 5ms. I want to count different time-lengths and for that I use counters. The problem is they don't measure the times I want correctly and I don't know what the problem is.

Count_100ms     EQU r2
Count_500ms     EQU r3
Count_8s        EQU r4
Count_10s       EQU r5
Count_25s       EQU r6
Tick_tmr_5ms    EQU 23H.0
Tick_tmr_500ms  EQU 23H.1
Tick_tmr_8s     EQU 23H.2
Tick_tmr_10s    EQU 23H.3
Tick_tmr_25s    EQU 23H.4

ORG 0x1B
    Push    ACC
    Push    PSW
    Acall   SUB_TIMER
    Pop PSW
    Pop ACC
    Reti

ORG 0x7B
    Acall   INITIALIZATIONS

LOOP:
    Acall   SMTHNG
    Ajmp    LOOP

INITIALIZATIONS:
    Setb    0xA8.7          ;Enable interrupts
    Setb    0xA8.3
    Clr Tick_tmr_5ms        ;Initializations for timer1
    Clr Tick_tmr_500ms
    Clr Tick_tmr_8s
    Clr Tick_tmr_10s
    Clr Tick_tmr_25s
    Mov Count_100ms, #00H
    Mov Count_500ms, #00H
    Mov Count_8s, #00H
    Mov Count_10s, #00H
    Mov Count_25s, #00H
    Mov TMOD, #10H
    Acall   TIMER_START     ;Timer1 start
    Ret

SMTHNG:
    Ret

TIMER_START:
    Mov Kont_100ms, #00H
    Mov Kont_500ms, #00H
    Mov Kont_8s, #00H
    Mov Kont_10s, #00H
    Mov Kont_25s, #00H
    Clr Tick_tmr_5ms
    Clr Tick_tmr_10s
    Clr Tick_tmr_8s
    Clr Tick_tmr_25s
    Clr Tick_tmr_500ms
    Mov TH1, #0x27
    Mov TL1, #0x10
    Orl TCON, #40H
    Ret

SUB_TIMER:
    Clr Tick_tmr_10s
    Clr Tick_tmr_8s
    Clr Tick_tmr_25s
    Clr Tick_tmr_500ms
    Setb    Tick_tmr_5ms
    Mov TH1, #0x27
    Mov TL1, #0x10
    Inc Count_100ms
    Mov A, Count_100ms
    Cjne    A, #14H, TIMER_END
    Inc Count_500ms
    Inc Count_8s
    Inc Count_10s
    Inc Count_25s
    Mov Count_100ms, #00H
TIME_500MS:
    Mov A, Count_500ms
    Cjne    A, #05H, TIME_8SEG
    Setb    Tick_tmr_500ms
    Mov Count_500ms, #00H
TIME_8SEG:
    Mov A, Count_8s
    Cjne    A, #50H, TIME_10SEG
    Setb    Tick_tmr_8s
    Mov Count_8s, #00H
TIME_10SEG:
    Mov A, Count_10s
    Cjne    A, #64H, TIME_25SEG
    Setb    Tick_tmr_10s
    Mov Count_10s, #00H
TIME_25SEG:
    Mov A, Count_25s
    Cjne    A, #0xFA, TIMER_END
    Setb    Tick_tmr_25s
    Mov Count_25s, #00H
TIMER_END:
    Ret

END

The calculations for the timer are the following:

count = T / (Tosc * prescaler)
count = 5*10^-3 / (1/24*10^6 * 12)
count = 10,000 --> TH1 = 27h and TL1 = 10h

The counters are incremented every time the counter for 100ms runs out so the numbers I compare each counter with is calculated with this: number = count (ms) / 100

I've been measuring the counter for 8s. I've found that with the initial value I gave it (50H = 80 decimal) I got more or less have of the time I wanted. I tried to duplicate it and wrote A0H but it still wasn't measuring 8s and I can't seem to find the error in my calculations.

0

There are 0 answers