Searching \ for 'Setting a bit in a GPR RAM Register' 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/index.htm?key=setting+bit+gpr
Search entire site for: 'Setting a bit in a GPR RAM Register'.

Truncated match.
PICList Thread
'Setting a bit in a GPR RAM Register'
1999\03\02@095923 by YeYo

flavicon
face
part 0 6898 bytes
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type>
<META content='"MSHTML 4.72.3110.7"' name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT><FONT color=#000000 size=2>I have a program coded
for the PIC16C84/16F84, and at this point I want to set a bit in a GRP PIC RAM
Register. I have others 2 registers declared at the start:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2>ByteCounter EQU
0x2d&nbsp;&nbsp;&nbsp; ; Here I store the address I want to
modify.<BR>BitCounter&nbsp; EQU 0x2e&nbsp;&nbsp;&nbsp; ; Here I store the bit
number I want to set.<BR>Temporal&nbsp;&nbsp;&nbsp; EQU 0x2f&nbsp;&nbsp;&nbsp; ;
Temp register.<BR></FONT></FONT></FONT><FONT size=2><FONT
face="Courier New"></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"></FONT></FONT><FONT
face="Courier New" size=2>Let's assume ByteCounter has the value 0x0c, and
BitCounter has the value 4. In this case all I want is to set to 1 the bit 4 of
the register located at address 0x0c. Please, can you tell me if the following
piece of code is correct?</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2><FONT
color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT></FONT></FONT></FONT><FONT color=#000000 size=2>;
First I extract the content of the address pointed by ByteCounter to Temporal,
and set the bit.</FONT></DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2><FONT
color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2><FONT
color=#000000><FONT face="Courier New"><FONT
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;
ByteCounter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; W=0ch.<BR></FONT></FONT></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
movwf&nbsp;&nbsp;
FSR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; FSR=Point to the address of W.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
movfw&nbsp;&nbsp;
INDF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; W=Store the content of the pointed
address.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;
Temporal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Temporal=W.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bsf&nbsp;&nbsp;&nbsp;&nbsp; Temporal,BitCounter&nbsp;&nbsp;&nbsp;&nbsp; ; Set
the bit 4 of Temporal register.</FONT></FONT></FONT></DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT><FONT size=2><FONT
face="Courier New"></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>; Once the bit is set, let's store the content
of Temporal to the address pointed by ByteCounter (0x0c in this
case)</FONT></DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;
ByteCounter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; W=0ch.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;
FSR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; FSR=Point to the address of W.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
movfw&nbsp;&nbsp;
Temporal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; W=Temporal.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;
INDF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Store W inside the address pointed.</FONT></FONT></FONT></DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2></FONT></FONT></FONT><FONT size=2><FONT
face="Courier New"></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>I don't know very well how to handle indirect
addressing, I am sure this piece of code can be reduced in only a few lines of
code. Please If you can help me I will appreciate it very much.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>Thanks in advance.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV></BODY></HTML>

</x-html>

1999\03\02@133208 by Quentin

flavicon
face
> YeYo wrote:
>
> I have a program coded for the PIC16C84/16F84, and at this point I
> want to set a bit in a GRP PIC RAM Register. I have others 2 registers
> declared at the start:
>
> ByteCounter EQU 0x2d    ; Here I store the address I want to modify.
> BitCounter  EQU 0x2e    ; Here I store the bit number I want to set.
> Temporal    EQU 0x2f    ; Temp register.
> Let's assume ByteCounter has the value 0x0c, and BitCounter has the
> value 4. In this case all I want is to set to 1 the bit 4 of the
> register located at address 0x0c. Please, can you tell me if the
> following piece of code is correct?
>
> ; First I extract the content of the address pointed by ByteCounter to
> Temporal, and set the bit.
>
First you declare Bytecounter and Bitcounter as registers, then you
carry on using them as if they are literals.

I take it you want to use the value in the register. Thus:
>         movlw   ByteCounter             ; W=0ch.
Should be: movf   Bytecounter,w
>         movwf   FSR                     ; FSR=Point to the address of
> W.
>         movfw   INDF                    ; W=Store the content of the
> pointed address.
no such command, should be: movf        INDF,w
>         movwf   Temporal                ; Temporal=W.
>         bsf     Temporal,BitCounter     ; Set the bit 4 of Temporal
> register.
Here you got another problem, BitCounter here stands for a literal as
you cannot use a register in such a way. Rather 'OR' the two using
IORWF. Replace the above two line with:
       iorwf   BitCounter,w
       movwf   Temporial

>
> ; Once the bit is set, let's store the content of Temporal to the
> address pointed by ByteCounter (0x0c in this case)
>
>         movlw   ByteCounter             ; W=0ch.
Repair the same as above.
>         movwf   FSR                     ; FSR=Point to the address of
> W.
>         movfw   Temporal                ; W=Temporal.
Repair the same as above.
>         movwf   INDF                    ; Store W inside the address
> pointed.

Hope it helps
Quentin

1999\03\03@061856 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hello,

I once needed a addressable bit field. 80x51 have bit addressable
functions,
PICS does4nt.

So what I did on a PIC 16C84 ( should work on other PIC4s too ) was:

       1. taking the Byte holding the address of the bit and
       store the contents to the fsr and divide fsr by 8.
       now add the offset which points to the range in memory
       wher the bit addressable area starts.
       fsr now holds the addressed byte.

       2. take the byte holding the address of the bit
       and get the least 3 bit. use these 3Bit to do a
       table read with a table looking like  this:

       RETLW B'00000001'
       RETLW B'00000010'
       RETLW B'00000100'
       RETLW B'00001000'
       (...)
       RETLW B'10000000'

       this gives you the bit to manipulate in W . The manipulation could
       be done as usal with OR, XOR, AND,  etc. using INDF as destination.

Kind regards,

       Stefan

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