Searching \ for 'Why doesn't this code work ???' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=why+doesnt+code
Search entire site for: 'Why doesn't this code work ???'.

Truncated match.
PICList Thread
'Why doesn't this code work ???'
1999\10\19@054711 by Mathew Cohen

flavicon
face
part 0 16 bytes
</x-html>

1999\10\19@083402 by Dubois Michel

flavicon
face
part 0 4181 bytes
x-html> You never go to "toggleleds".
I suggest you the following:

Checkswitch
 BTFSS PORTB,7
 BSF PORTA,4
 BTFSC PORTB,7
 BCF PORTA,4
            &nbs p;       GOTO Checkswitch *delete this line*
 

toggleleds
 
 BTFSS PORTA,1
 goto LedsOFF
            &nbs p;   BTFSC PORTA,1  *delete this line
            &nbs p;   goto Ledson *delete this line
 
Ledson
 
 MOVLW 15
 MOVWF PORTA
 CALL Initmr
 GOTO Checkswitch
 

LedsOFF
 
 MOVLW 0
 MOVWF PORTA
 CALL Initmr
 GOTO Checkswitch
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

1999\10\19@094019 by jamesp

picon face
Matthew,

The first thing I see wrong I believe is that you have the
"INTERRUPT VECTOR" at 0x03.  It should be 0x04.  Everything
else looks okay from my initial glance.  I think if you get
the interrupt vector corrected, it'll work as planned.

                                    Regards,

                                      Jim


{Quote hidden}

1999\10\19@124914 by Dubois Michel

flavicon
face
part 0 4056 bytes
x-html> 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

1999\10\20@082515 by Martin SchŠfer

flavicon
face
Hi Mathew,

why is your interrupt starting at H'03' ?

Mathew Cohen schrieb:

>   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 ;-----------------------------------------------------------------
---------
{Quote hidden}

1999\10\26@013934 by Mathew Cohen

flavicon
face
I believe that this is the interupt vector location for the 16f84. In
software simulation it seems to work. If this is not the case than could
someone please set me straight. Also it ahs been brought to my attention
that I seem to have left the global interupt bit low this is probably why
the code does not work .
Can someone test it thanks.


Regards

Mathew Cohen


{Original Message removed}

1999\10\26@030741 by Ben Stragnell

flavicon
face
The interrupt vector's at H'04'.
Are you sure your software simulation is hitting the btfsc instruction?

Cheers,
Ben

Mathew Cohen wrote:
{Quote hidden}

> {Original Message removed}

1999\10\26@102102 by paulb

flavicon
face
Mathew Cohen wrote:

> 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
> interrupt.

>              ORG     H'50'
 I don't know if the programmer is smart enough to place code at $50
*after* code at $03, when placed first in the source, but the latter
code is most likely to overlay the former anyway if it long enough.

> Start
>  Call Initporta
>  Call Initportb
>  Call Initmr
>  GOTO Checkswitch
>
> ;---------------------------------------------------------------------
>
  ORG H'04'  ; Page 11 document DS30430C
> TmrInterupt
>
>  BTFSC PORTB,7
>  call Initmr
>  goto toggleleds
 Now let's see, when interrupted by the timer, you test your switch and
perform a timer initialisation if PORTB.7 is high, and in either case
jump to toggleleds?  Toggleleds ends up in an infinite "copy" loop but I
suppose if you have re-initialised the timer, it can interrupt again.
The stack pointer will go insane, but in fact this doesn't matter.  The
simulator won't like it however.
>
> Initmr
>  CLRF TMR0
>  BSF STATUS,RP0 ;select bank 1
>  CLRF OPTION_REG
>  MOVLW B'00000111'
>  IORWF OPTION_REG,1
 That's a long-winded way of setting up the option register, but....
>  BCF INTCON,T0IF
>  BSF INTCON,T0IE
 You left bank 1 selected!
>  RETURN
>
>
> Initporta
>
>  BSF STATUS,RP0
>  MOVLW 0
>  TRIS PORTA
 You don't need to set up RP0 to use TRIS.  That's the whole point!
{Quote hidden}

 Sets PORTA.4 (open collector) to inverse of PORTB.7
>  BTFSS PORTB,7
>  BSF PORTA,4
>  BTFSC PORTB,7
>  BCF PORTA,4
>  GOTO Checkswitch
>
>
> toggleleds
 This isn't going to work real well, as in Initmr, you left bank 1
selected!
>  BTFSS PORTA,1
>  goto LedsOFF
>  BTFSC PORTA,1
>  goto Ledson
 That's redundant - you get to Ledson either way!
{Quote hidden}

 The overall flow control is shall I say, most unconventional.  The
code initially drops through to Checkswitch which is dead-end code, but
having initialised the timer to interrupt, this happens periodically,
clearing the interrupt without restoring the stack (but that doesn't
actually matter in the real silicon!) and toggles the LEDs before
dropping back into CHeckswitch.

 The mis-setting of the bank select will prevent it from working, but
otherwise it presumably will.

 Note that the combined maximum prescale and timer overflow will cause
it when fixed to flash the LEDs at 1/65536 of the instruction clock,
about 7 Hz with a 4 MHz crystal or 18 Hz with a 10 MHz crystal which may
be difficult to visualise.   If simulated, will give a continuous stream
of stack errors but should otherwise work.

 I'd really like to know however, Mathew, whether you tried the code in
my previous reply?
--
 Cheers,
       Paul B.

1999\10\26@224444 by John Considine

flavicon
face
The PIC16C84 has the interupt at org 4
I don't see you saving the registers after going into interupt and returning
the registers when returning (you should have a RETFIE, not a return)
_w    equ    10
_status    equ    11

org 4
Interrupt
movwf    _w                ;save work
movf     STATUS, w
bcf        STATUS, RP0    ;puts the pic register in a know page (optional)
movwf    _status        ;save status

bcf    INTCON, 1    ;clear INTF in INTCON register
bcf    INTCON, 2    ;ckear TOIF in INTCON register

Do your other interupt code here

RETFIE                    ;puts the PC at Top of Stack (where the interupt came
from)





Mathew Cohen wrote:

{Quote hidden}

> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...