Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 3rd July 2007, 01:54 PM   #1
Angry MOVLW not setting correct value in W register

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
    MOVLW    LEDPORT        ;MOVE LED PORT BITS
    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!

Whats going on?

thanks

Last edited by bitem2k; 3rd July 2007 at 01:56 PM.
bitem2k is offline  
Old 3rd July 2007, 02:18 PM   #2
Default

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.
Pommie is offline  
Old 3rd July 2007, 02:32 PM   #3
Default

ah, stupid me!
thanks very much mate.
bitem2k is offline  
Old 3rd July 2007, 02:38 PM   #4
Default

Yeah that did the trick.

cheers
bitem2k is offline  
Reply

Tags
correct, movlw, register, setting

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
PLL WITH PIC AND TSA5511 savnik Micro Controllers 23 26th April 2009 08:50 PM
PIC16F628A Reset? marting Micro Controllers 18 5th December 2008 09:31 PM
Problem with LCD code? spondootre Micro Controllers 15 29th April 2008 10:15 AM
How to code a pic based speed trap user1453 Micro Controllers 17 8th October 2006 01:07 PM
ya mari_69 Micro Controllers 4 7th June 2004 02:29 PM



All times are GMT. The time now is 07:39 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker