PICcoder.co.uk Forum  


::post new topic::
Aseemble Language question
Date: 2008/09/07 12:20 By: Roger Status: Visitor  
 
Hi,

I am new to PIC programming and have run into a problem with my code.

I want to set a spicific bit on PortB to light up a LED but I want to be able to change which bit I set so I thought I would set up a piece of code as below

MOVLW 1 ;PUT 1 IN W
MOVWF COUNT ; PUT W IN COUNT
MAIN
BSF PORTB,COUNT ;TURN ON LED
CALL DELAY1 ;WAIT 1 SECOND
BCF PORTB,COUNT ;TURN LED OFF
CALL DELAY1 ;WAIT 1 SEC
CALL DELAY1 ;WAIT 1 SECOND
INCF COUNT ;INCREMENT COUNT
GOTO MAIN ;LOOP FOREVER

Now what I expected to happen was for each led to come on and then go off starting with LED1 and moving up one at a time, but what actually happens is that LED0 comes on and then goes off.

The offending line is BSF PORTB,COUNT does anyone know why I cannot do this?
reply | quote

Re:Aseemble Language question
Date: 2008/09/11 07:45 By: DaveS Status: Visitor  
 
COUNT is an 8 bit file register and as such cannot be used as a PORTB bit.

Try:-


MOVLW 1 ;PUT 1 IN W

MOVWF COUNT ; PUT W IN COUNT

MAIN

movf;TURN ON LED

CALL DELAY1 ;WAIT 1 SECOND

BCF PORTB,COUNT ;TURN LED OFF

CALL DELAY1 ;WAIT 1 SEC

CALL DELAY1 ;WAIT 1 SECOND

INCF COUNT ;INCREMENT COUNT

GOTO MAIN ;LOOP FOREVER
reply | quote

Re:Aseemble Language question
Date: 2008/09/11 07:53 By: DaveS Status: Visitor  
 
Sorry, pressed wrong button. I'll start again.

COUNT is an 8 bit file register and as such cannot be used as a PORTB bit.



Try:-

MOVLW 1 ;PUT 1 IN W

MOVWF COUNT ; PUT W IN COUNT

MAIN

movf COUNT,W;put contents of count in W

movwf PORTB ; W to PORTB

CALL DELAY1 ;WAIT 1 SECOND

clrf PORTB;TURN LED OFF

CALL DELAY1 ;WAIT 1 SEC

CALL DELAY1 ;WAIT 1 SECOND

INCF COUNT ;INCREMENT COUNT

GOTO MAIN ;LOOP FOREVER

This will cause the leds to count up in binary however. To achieve what you want replace incf COUNT with RLF COUNT, F
reply | quote

::post new topic::