| ??? 09/25/11 00:46 Read: times |
#183865 - Thanks also you for your time Responding to: ???'s previous message |
Stefan Kanev said:
C_seg segment CODE
D_seg segment DATA
B_seg segment bit
rseg D_seg
HalfPeriod2Cnt: ds 1
HalfPeriod1Cnt: ds 1
rseg B_seg
Timer10ms_tickFLAG: ds 1
;--------------------
ASEG CODE
org 0
ljmp main
org 01bh
ljmp timer1isr_handler
;---------------------
rseg C_seg
TIMER1VALUE_10msec equ 56320 ; //(65536-9216) ,Your timer's input freq is 921600 Hz,
;timer will be incremented 9216 times in 10 millisec timepiece
Halfperiod2Hz equ 25 ;*10 ms = 250 ms
Halfperiod1Hz equ 50 ;*10 ms = 500 ms
Port_2Hz equ P1.5
Port_1Hz equ P1.6
main:
MOV TMOD,#10H ;timer 1, mode 1 (16-bit)
; old AGAIN:
MOV TL1,#low(TIMER1VALUE_10msec )
MOV TH1,#high(TIMER1VALUE_10msec)
SETB TR1 ;start the timer1
setb ET1 ;enable Timer 1 interrupt
setb EA ; enable common Interrupt Enable
mov HalfPeriod1Cnt,#0
mov HalfPeriod2Cnt,#0
clr Timer10ms_tickFLAG
AGAIN:
;BACK: JNB TF1,BACK stay till timer rolls over;
; CLR TR1 ;stop timer 1
; CPL P1.5 ;comp. p1.5 to get hi, lo
; CLR TF1 ;clear timer flag 1
; SJMP AGAIN ;reload timer since mode 1
; ;is not auto-reload
jnb Timer10ms_tickFLAG, AGAINno10ms
clr Timer10ms_tickFLAG
call Freq2HzHandle
call SomeOther10msecProc
AGAINno10ms:
call SomeOtherUsefullProc
jmp AGAIN
;-----
Freq2HzHandle:
inc HalfPeriod2Cnt
mov a, HalfPeriod2Cnt
clr c
subb a,# Halfperiod2Hz
jc Freq2Hzret
mov HalfPeriod2Cnt,#0
CPL Port_2Hz
Freq2Hzret:
ret
SomeOther10msecProc:
;-------
ret
SomeOtherUsefullProc
;..................
ret
timer1isr_handler:
push PSW
push a
clr TR1
MOV TL1,#low(TIMER1VALUE_10msec )
MOV TH1,#high(TIMER1VALUE_10msec)
setb TR1
;clr TF1 - not needed flag is autocleared , when ISR enters
setb Timer10ms_tickFLAG
inc HalfPeriod1Cnt
mov a, HalfPeriod1Cnt
clr c
subb a,#HalfPeriod1Hz
jc timer1isr_end
mov HalfPeriod1Cnt,#0
cpl Port_1Hz
timer1isr_end:
pop a
pop PSW
reti
Hi Stefan Kanev: I really did not know where to start with code. I do appreciate your time giving an example. Best regards, Ralph Sac |



