Shop OBEX P1 Docs P2 Docs Learn Events
Manipulating bits – Help! — Parallax Forums

Manipulating bits – Help!

ChrisGChrisG Posts: 3
edited 2004-08-27 20:23 in General Discussion
Here's hoping someone will take pity on a poor Basic Stamp programmer and tell me what I'm doing wrong with my brand new SX28.
·
I'm trying to follow the development manual, and the first sample program it has you run is a simple LED flasher, moving the inverse of rc.7 into W and then moving it back, as in 'mov w,/rc.7' 'mov rc.7,w'.· And every time I even try to assemble it, it gives me an ‘Error 1, Pass 2: Bad instruction statement' error.· It works just fine if I allow it to move the entire register 'mov rc,w', but doesn't like having its bits moved individually.· If I set the entire C register as outputs ‘mov !RC,#$FF’, and try a ‘not RC’, then all of RC toggles as I expected, and also RB.7 which I didn’t expect.
·
It will assemble with ‘mov w,rc.0’, but that has the same effect as ‘mov w,rc’, where it moves the entire register.· I can 'setb rc.7' and 'clrb rc.7' (or any other bit) easily enough, just can't seem to move anything into or out of it.· Same thing happens for any individual bit in any other register, too.·
·
Another demo program demonstrating the 'watch' directive stores '%01' into the variable 'flags', and then uses a 'watch flags.0,1,UBIN' and 'watch flags.1,1,UBIN' to look at each bit separately.· When I tried it, both 'flags.0' and 'flags.1' showed the same value '1', and when I toggled the relevant bit in the debugger, both flags.0 and flags.1 toggled together.
·
I have downloaded the latest version SX-Key v2.02.· I have ‘use SASM’ checked in the configuration menu.· Curiously, it does assemble and run when I uncheck the ‘Use SASM’ box, but it still doesn’t run properly; a ‘not RC.6’ toggles the entire RC register as well as bit 7 of the RB register.
·
Help!

Comments

  • KenMKenM Posts: 657
    edited 2004-08-27 15:15
    Please post your program.

    Either paste it below or as an attachement

    Also, exactly which development manual are you using? Is there a link to a downloadable version so I can check it out?

    Ken


    Post Edited (KenM) : 8/27/2004 3:19:20 PM GMT
  • BeanBean Posts: 8,129
    edited 2004-08-27 15:32
    Use MOVB bitvar,bitvar

    or to put a bit into a byte I do this:

    CLR bytevar
    ADDB bytevar,bitvar ; bytevar = 0 or 1

    or

    CLR bytevar
    SUBB bytevar,bitvar ; bytevar = 0 or 255

    You cannot set individual bits of configuration registers like !RB by using SETB or CLRB

    Terry
  • ChrisGChrisG Posts: 3
    edited 2004-08-27 16:22
    Wow, fast responses!
    ·
    Okay, I’m using the SX-Key/Blitz! Development System Manual Version 2.0 available for download at http://www.parallax.com/dl/docs/prod/sx/SXKeyMan2_0.pdf, and the program that I’m having difficulty with is LED28.src - straight off of the CD included with the starter kit.
                            DEVICE            SX28L,OSC1MHZ,TURBO 
                            RESET            Start 
                            FREQ 1_000_000 
      
    ;Define all symbols 
                            Count1            EQU            $08 
                            Count2            EQU            $09 
      
                            WATCH            Count1,16,UDEC 
      
    Start                 mov            rc, #%00000000            ;Set port C output latch to zero 
                            mov            !rc,#%01111111            ;Set port C.bit7 to output direction 
                            
    Main                call            delay                ;delay                                                   
                            mov            W,/RC.7        ;grab inverse of RC bit7 
                            mov            RC.7,W         ;and store it in RC bit7 
                            jmp            Main                ;goto main                                         
      
      
    Delay               clr            Count1              ;Initialize Count1, Count2 
                            clr            Count2              ;                                                           
      
    Loop                djnz            Count1,loop   ;Decrement until all are zero                        
                            djnz            Count2,loop    ;                                                           
                            RET                                  ;then return
    
    

    Simple enough even for someone like me to follow ... or so I thought.· Like I said, it won't even assemble due to errors on lines 15 and 16 'Error 1, Pass 2: Bad instruction statement.'

    Bean, I tried replacing the ‘mov W,/RC.7’ instruction with a ‘movb W,/RC.7’ but still got the same error.
  • BeanBean Posts: 8,129
    edited 2004-08-27 18:07
    That's because W is not a bit variable.

    Change the code to MOVB Z,/RC.7 and MOVB RC.7,Z

    Z is the zero flag and it is a bit variable.

    Bean.
  • ChrisGChrisG Posts: 3
    edited 2004-08-27 20:23
    Ah, that'd do it then. Gotta be smarter than the machine, I guess.

    Thanks
Sign In or Register to comment.