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

Back to Subject List

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


 
#107276 - Should of been original question sorry !
Responding to: ???'s previous message
In the code below the state of port 2 pin 2 is checked,and timer 0 is used as a delay by calling the subrutine FiftyMsDelay
100 times to result in a 5 second delay and then end.

What should happen is if p2.2 is set an interrupt occurs and incerments register 1 and continues with the delay until 5 seconds are up, thats unless p2.2 isn't set again and so on.

This is a subrotine in my main program to count porpeller rotation using an optical encoder.

The reality is the code below wont trigger an interrupt if p2.2 is set and timer 0 wont start,im thinking of using P3.2 or P3.3 as they are for external interrutpt but im not sure on how to implement.

I would be grateful of any help.
Eymard.

_____________________________________________________________
ORG 0 ; Reset vector
JMP MAIN ; Jump above interrupt vectors
ORG 000BH ; Timer 0 interrupt vector
loopA:
CALL FiftyMsDelay ; Call the 50 ms delay
DJNZ R0,loopA ; 40 times - resulting in a 2 second delay
JMP FINISH ; Return from interrupt
ORG 001BH ; Timer 1 interrupt vector
JMP timer1ISR ; Jump to timer 1 ISR
ORG 0030H ; Main program entry point

MAIN:
MOV R0,#100 ; 50 Ms by 100 is 5 seconds
MOV P2,#0 ; Clears port two
MOV TMOD, #62H ; Timer 0 in 8-bit auto-reload timer mode
; Timer 1 in 8-bit auto reload counter mode
BEGIN:
SETB TF1 ; Force timer 1 interrupt
SETB ET0 ; Enable timer 0 interrupt
SETB ET1 ; Enable timer 1 interrupt
SETB PT1 ; Set timer 1 overflow to high priority
SETB EA ; Global interrupt enable
JMP LOOPA ; continue delay

FiftyMsDelay:
CLR TR0 ; Stop timer 1(In case it is started already)
MOV TH0,#3CH
MOV TL0,#0B0H ; Load 15,536 (3CB0H) into timer 0
SETB TR0 ; Start timer 0
JNB TF0,$ ; Repeat this line while timer 0
; Overflow flag is not set
CLR TF0 ; Timer 0 overflow flag is set by hardware
CLR TR0 ; Stop timer 0
RET

timer1ISR:
SETB ET0
MOV A,0A0H ; Location of port two in memory
CJNE A,#4,RETURN ; Value of port 2 if only p2.2 is set
CLR TR1 ; Stop timer 1
INC R1 ; Event count held here
RETURN:
RETI
END


List of 17 messages in thread
TopicAuthorDate
timer/ counter            01/01/70 00:00      
   clarify            01/01/70 00:00      
   To rephase my Question            01/01/70 00:00      
      what is "the event counter"            01/01/70 00:00      
         Event counter explained            01/01/70 00:00      
            I know what the datasheet (the "bible")            01/01/70 00:00      
   Try prioritizing            01/01/70 00:00      
      About Prioritizing            01/01/70 00:00      
      Priority            01/01/70 00:00      
   Should of been original question sorry !            01/01/70 00:00      
      a few comments            01/01/70 00:00      
         i dont have to stick to P2.2            01/01/70 00:00      
            never us a register for a dedicated purp            01/01/70 00:00      
               Thanks for tip            01/01/70 00:00      
                  you do not need that            01/01/70 00:00      
               thanks            01/01/70 00:00      

Back to Subject List