piclist 1999\10\19\124914a >
Thread: Why doesn't this code work ???
www.piclist.com/techref/index.htm?key=why+doesnt+code
flavicon
face BY : Dubois Michel email (remove spam text)

part 0 4060 bytes
First, OK with Jim, you need a ORG H'04'

Sorry for my previous mail, I did not see your GOTO TOGGLELEDS.

I see 2 other problems:
1. You do not return from interrupt routine:
   Data Sheet:

"When an interrupt is responded to; the GIE bit is
 cleared to disable any further interrupt,
 The "return from interrupt" instruction, RETFIE, exits
 interrupt routine as well as sets the GIE bit, which
 re-enable interrupts."
 
You have to drive your leds from interrupt routine OR main loop.

2.
toggleleds

 BTFSS PORTA,1
 goto LedsOFF
 BTFSC PORTA,1 >> if 0 then skip --> next is Ledson
 goto Ledson   >> if 1 then GOTO Ledson

Ledson

>> In both cases you are going to Ledson ...

Mathew Cohen a écrit :

  Hi All, Can someone tell me why the following code will not work. Is this the correct way to initilise the timer and use the timer overflow interupt. Thanks in advance Mathew Cohen               ORG     H'50' Start
 Call Initporta
 Call Initportb
 Call Initmr
 GOTO Checkswitch ;------------ --------------------------------------------------------------   ORG H'03'
TmrInterupt  BTFSC PORTB,7

 call Initmr
 goto toggleleds Initmr
 CLRF TMR0
 BSF STATUS,RP0 ;select bank 1
 CLRF OPTION_REG
 MOVLW B'00000111'
 IORWF OPTION_REG,1
 BCF INTCON,T0IF
 BSF INTCON,T0IE  RETURN  
Initporta  BSF STATUS,RP0
 MOVLW 0
 TRIS PORTA
 BCF STATUS,RP0
 MOVLW 31
 MOVWF PORTA  RETURN Initportb  BSF STATUS,RP0
 MOVLW H'FF'
 MOVWF TRISB
 BCF STATUS,RP0
 RETURN Checkswitch
 BTFSS PORTB,7
 BSF PORTA,4
 BTFSC PORTB,7
 BCF PORTA,4
 GOTO Checkswitch  
toggleleds

 BTFSS PORTA,1
 goto LedsOFF
 BTFSC PORTA,1
 goto Ledson

Ledson  MOVLW 15
 MOVWF PORTA
 CALL Initmr
 GOTO Checkswitch  
LedsOFF

 MOVLW 0
 MOVWF PORTA
 CALL Initmr
 GOTO Checkswitch

 END

<380CA095.C6AC5AF3@dial.oleane.com>

See also: www.piclist.com/techref/index.htm?key=why+doesnt+code
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Why doesn't this code work ???

month overview.

new search...