Searching \ for '[PIC]: code help' 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/microchip/devices.htm?key=pic
Search entire site for: 'code help'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: code help'
2000\11\27@222739 by PDRUNEN

picon face
Hi group,

In the code below, I want to set a bit in the [INDF] => 0x30 register during
each loop. The label "loop" will be executed
eight times, each time I wish to do the following, using temp1 as a bit index
variable.

loop 1:  BSF INDF,7  ;0x30 = 10000000
loop 2:  BSF INDF,6  ;0x30 = 11000000
loop 3:  BSF INDF,5  ;0x30 = 11100000
loop 4:  BSF INDF,4  ;0x30 = 11110000
loop 5:  BSF INDF,3  ;0x30 = 11111000
loop 6:  BSF INDF,2  ;0x30 = 11111100
loop 7:  BSF INDF,1  ;0x30 = 11111110
loop 8:  BSF INDF,0  ;0x30 = 11111111


However, only BSF INDF,7 appears to work during simulation.  So, is it
possible?

Thanks,

Paul

BEGIN:


   MOVLW   0x07
   MOVWF   TEMP1
LOOP
   MOVLW   0x30
   MOVWF   FSR

   BSF INDF,TEMP1
   DECFSZ  TEMP1,F
   GOTO    NEXT_LBL2
;

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2000\11\27@223829 by Dwayne Reid

flavicon
face
You cannot directly address bits in this fashion, only bytes.

However, you can achieve the result that you posted by ensuring that the
Carry bit is set according to the state you want, then rotating left or
right as desired.

In other words,
    MOVLW   0x08                ;you originally specified only 7 loops,
this is 8
    MOVWF   TEMP1

LOOP
    MOVLW   0x30
    MOVWF   FSR

    setc
    rrf     INDF,F

    DECFSZ  TEMP1,F
    GOTO    NEXT_LBL2



At 10:26 PM 11/27/00 -0500, .....PDRUNENKILLspamspam@spam@AOL.COM wrote:
{Quote hidden}

Dwayne Reid   <.....dwaynerKILLspamspam.....planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 16 years of Engineering Innovation (1984 - 2000)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2000\11\27@224610 by David Duffy

flavicon
face
Paul wrote:
{Quote hidden}

Hi Paul,
You can't use a file register as the bit number in the BCF instruction.
One way to do it would be shifting (RRF) in a 1 from the carry position
each time during the loop. Something like this should do:

        movlw           0x08            ;
        movwf           temp1           ;set up loop counter
        movlw           0x30            ;
        movwf           fsr             ;point fsr to ram
        clrf            indf            ;start with result 00000000
loop:
        bsf             indf,7          ;set bit 7 (1xxxxxxx)
                                        ;do something with result here?
        rrf             indf,f          ;rotate it towards lsb
        decfsz          temp1,f         ;last loop?
        goto            loop            ;no

Regards...

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2000\11\27@224816 by Dan Michaels

flavicon
face
At 10:26 PM 11/27/00 EST, you wrote:
{Quote hidden}

             ^^^^^

Paul,

I do not believe this is an allowable command format - much to
my chagrin, and no doubt to that of everyone else who has ever
programmed a PIC. The bit must be called out specifically.

- danM
====================




{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2000\11\28@100317 by Olin Lathrop

face picon face
>     MOVLW   0x07
>     MOVWF   TEMP1
> LOOP
>     MOVLW   0x30
>     MOVWF   FSR
>
>     BSF INDF,TEMP1

You can't do that.  The BSF instruction sets a particular bit which is hard
coded into the instruction.  The bit can not be selected at run time.  To do
that, you need to OR the target with a mask containing the selected bit.

>     DECFSZ  TEMP1,F
>     GOTO    NEXT_LBL2


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, RemoveMEolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\11\28@132521 by Barry Gershenfeld

picon face
I saw the same thing the others did, but I thought of
the explanation a little differently.  Must be my background.

>In the code below, I want to set a bit in the [INDF] => 0x30 register ...

>However, only BSF INDF,7 appears to work during simulation...

When you compile this:

>    BSF INDF,TEMP1

the compiler uses the value for TEMP1 to build the
instruction.  Your TEMP1 was probably located at 0x27
or something.  It simply got used as the bit number.
Not what's in the register, but the address of it,
instead.  I bet if you moved it to another
location you would find it "only worked with" a
different bit.

Once in a while looking at the compiled instruction
in the assembly listing will reveal something you
hadn't realized.  This might take some experience.

Understanding this kind of cause/effect goes a long way
towards understanding what the processor (and the
compiler) can and can't do.

Barry

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


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