Truncated match.
PICList
Thread
'Setting a bit in a GPR RAM Register'
1999\03\02@095923
by
YeYo
|
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> </DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2>ByteCounter EQU
0x2d ; Here I store the address I want to
modify.<BR>BitCounter EQU 0x2e ; Here I store the bit
number I want to set.<BR>Temporal EQU 0x2f ;
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> </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> </DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT size=2><FONT
color=#000000><FONT face="Courier New"><FONT
size=2> movlw
ByteCounter
; W=0ch.<BR></FONT></FONT></FONT>
movwf
FSR
; FSR=Point to the address of W.<BR>
movfw
INDF
; W=Store the content of the pointed
address.<BR> movwf
Temporal
; Temporal=W.<BR>
bsf Temporal,BitCounter ; 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> </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> </DIV>
<DIV><FONT color=#000000><FONT face="Courier New"><FONT
size=2> movlw
ByteCounter
; W=0ch.<BR> movwf
FSR
; FSR=Point to the address of W.<BR>
movfw
Temporal
; W=Temporal.<BR> movwf
INDF
; 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> </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> </DIV>
<DIV><FONT color=#000000 size=2>Thanks in advance.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT> </DIV>
<DIV><FONT color=#000000 size=2></FONT> </DIV></BODY></HTML>
</x-html>
1999\03\02@133208
by
Quentin
|
> 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
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...