Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MOVLW not setting correct value in W register

Status
Not open for further replies.

bitem2k

New Member
Here is the problem code:

Code:
;
;knight rider type thingy
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LIST P=PIC12F629
include "P12F629.inc"
    
    __CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT  

CBLOCK 0x20
SUBCOUNT
COUNT
LEDPORT

ENDC


PROGSTART
    
    ORG        0x0000
SETUP_OSC
    bsf STATUS, RP0 ;Bank 1
    call 3FFh ;Get the cal value
    movwf OSCCAL ;Calibrate
    bcf STATUS, RP0 ;Bank 0
SETUP
    BSF     STATUS,RP0    ;CHANGE TO BANK1
    MOVLW    0x00        ;SET W REGISTER 
    MOVWF    TRISIO        ;SET ALL PORTS TO OUTPUT
    BCF     STATUS,RP0    ;CHANGE TO BANK0
    CLRF     GPIO        ;CLEAR GPIO REG
    MOVLW    B'111'        ;DISABLE
    MOVWF   CMCON        ;COMPARATOR

START
    MOVLW    0x01        ;TURN first port
    MOVWF     GPIO        ;ON
    MOVWF     LEDPORT        ;SET LEDPORT
    CALL     DELAY

MOVELEFT
    RLF        LEDPORT, F    ;SHIFT BIT LEFT(I.E LED)
    ;CHECK IF NEXT PORT IS GP3
    MOVLW     b'00010000'    ;VALUE WILL BE USED FOR GPIO, IF PORT3 IS ACTIVE(I.E GP3 IS INPUT ONLY)
    BTFSC    LEDPORT, GP3;SKIP NEXT LINE IF ZERO
    MOVWF    LEDPORT        ;SKIP GP3 AND MOVE TO GP4
    BTFSC    LEDPORT, 6    ;CHECK IF WE ARE AT THE LEFTMOST POSITION    
    CALL    MOVERIGHT    ;NOW START MOVING RIGHT AGAIN IF WE ARE AT LEFTMOST POS
    CLRW
    [COLOR=Red][B]MOVLW    LEDPORT        ;MOVE LED PORT BITS[/B][/COLOR]
    MOVWF    GPIO        ;INTO GPIO REGISTER
    CALL     DELAY
    GOTO     MOVELEFT    ;MOVE LED LEFT AGAIN
    
MOVERIGHT
GOTO START
    

DELAY    
        movlw    0xFF
        movwf    COUNT

DELAYLOOP        
    DECFSZ    SUBCOUNT
    GOTO DELAYLOOP
    DECFSZ    COUNT
    GOTO DELAYLOOP    
    RETURN





end

When I simulate this, for some reason the following code doesnt work properly.
Code:
 MOVLW    LEDPORT        ;MOVE LED PORT BITS
For example, when LEDPORT equals 00000010, I call the above MOVLW, but instead of changing to 00000010, it changes to 00100010!:mad:

Whats going on?:confused:

thanks
 
Last edited:
MOVLW moves a literal value (a number) into W. The (literal) value of LEDPORT is 0x22 = 00100010. What you want to do is to move the value from the file (ram) that is at location 0x22 into W. To do this you use the MOVFW (move file to W) instruction.

HTH

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top