Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/13/09 06:47
Read: times


 
#163405 - keep interrupts short ... in time .. and more
Responding to: ???'s previous message
I suppose this explanation needs engsish skils, better than mine, but hope You will understand. So, see commented code below.


.equ    port_e, 0xF901
.equ	port_def_pgm, 0xF903
.equ	alarm, 0x00
.equ	count, 0x40 
.equ LED_PORT, P1.0 ; i assume Your P1.0 can drive led.

;======================
;Vector table
;====== usually this begins at addr 0, i dont know what is You micro, 
;and why You start from 2000h
;
.baseaddr   equ 2000h
.ext0vectoraddr equ baseaddr+3h
.tim0vectoraddr equ baseaddr+0Bh


.org baseaddr
ljmp main      
.org ext0vectoraddr
vectorex0_isr: ljmp ex0_isr
.org tim0vectoraddr
vectort0_isr: ljmp t0_isr
;.......
;....... other interrupts vector "LJMP"s

;=====================
;rellocatable code
.org baseaddr+100h

main:
	mov	dptr, #port_def_pgm
	mov	a, #128
	movx	@dptr, a

	mov     dptr, #port_e
        mov     a, #0xFF
        movx    @dptr, a

	mov	tmod,#0x01

	clr	tr0
	clr	tf0
	mov	th0,#0x00
	mov	tl0,#0x00

	setb	ex0
	setb	et0
	setb	ea   
	setb	it0 ;Falling Edge interrupt
	mov	ip, #0  ;Timer0 is lower priority than ExtInt0 !!!think 
	mov	a, #0

loop:
	movx	@dptr, a
	inc	a
        jnb alarm,loop_1 ;NEW line
        setb LED_PORT ;NEW line
            
    
loop_1:
	ljmp	loop

;So You wait for inerrupts ....
 
;=========
ex0_isr:
        push PSW ;!!!! allways do it
	push	acc ;not needed - Your routine doesnt uses acc
	push	dph ;same
	push	dpl ;same 
	mov	count, #250
	setb 	tr0
	
         clr LED_PORT ;NEW line
         jmp ex0_isrend ;NEW line

         jnb	alarm, *
        ;Without new lines - Now You stay here and wait timer0 ro set   
         this   bit.
        ;But You stay in interrupt with highest priority. Other interrups
        ;cant be called(hardware) until "reti" is executed.
        ;It is possible to make this workable, but is wrong practice.
        ;BTW, this routine doesnt make something usefull, i understand -
        ;this is excercise, AND this is main reason for troubles. 
        ;My advise - light on some LED here, and do "reti".
        ; In main loop check "alarm" and turn off LED if settled.
        ;And - stayng here for time count*
        
ex0_isrend:
	pop	dpl ;not needed if not pushed
	pop	dph ;same  
	pop	acc ;same
        POP PSW
	reti

;========
t0_isr:
        push PSW ;allways do it
      
	mov	th0,#0x00
	mov	tl0,#0x00
        ;not needed , timer interrupts just when tl=th=0
        ;loading tl,th is needed when You plane shortest timer thicks .
        ;nex day, i suppose.
        
       ;here You need that "push"es- push ACC,DPL,DPH

	mov	a, count        

	movx	@dptr, a ;????where is writen value of "count"

	djnz 	count, t0_end
	setb	alarm
         ;If You want to stop timer (and interrupt), simply do "CLR TR0" 
         ;here

t0_end:
        ;here You need that "pop"s
        Pop PSW
	reti
     

 



BTW, staying in EXT0_ISR and waiting is main error. Time between enter and exit (if program works, after changing IP priority reg.) is =
count*Timer0interrupt_interval.
And this is allmost ethernity.
regards


List of 5 messages in thread
TopicAuthorDate
Interrupts and timers            01/01/70 00:00      
   keep interrupts short ... in time .. and more            01/01/70 00:00      
      Thanks about the info            01/01/70 00:00      
         some thoughts            01/01/70 00:00      
            After a week of deep work with it            01/01/70 00:00      

Back to Subject List