PBC Pokes and Peeks

Electronics Computer Programming Q&A
Post Reply
mustang
Posts: 31
Joined: Thu Jan 17, 2002 1:01 am
Location: Santa Ana, CA
Contact:

PBC Pokes and Peeks

Post by mustang »

I am using a pbc compiler to try and program a 16F84 pic. It is my understanding, from the books that I have, that the STATUS, Option, and INTCON registers can be poked and peeked. Does anyone have a pic basic rountine that can accomplish this task? Why does the 16F84 have a status register in BANK 0 and also in BANK 1?
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: PBC Pokes and Peeks

Post by bodgy »

<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">quote:</font><hr>Why does the 16F84 have a status register in BANK 0 and also in BANK 1?[/ <hr></blockquote><p>Because the Pic is a risc based processor and uses the Harvard style architecture (data memory and program memory are on two different busses), Microchip make some of the essential Special File Registers available at all times.<p>The Status register being a quite important register is therefore available to be read no matter where the last data register to be used address happens to be.<p>You will see from the datasheet that the Intcon, PCLATH and FSR registers are also available in both banks. The last two because PCLATH contains the top 5 bits for program addressing and FSR is used to address registers. <p>This scheme becomes more obvious in the larger and more recent Pics that have more hardware registers and larger program and data memory than the 84 - which is now exxxxxtremely ancient.<p> <blockquote><font size="1" face="Verdana, Helvetica, sans-serif">quote:</font><hr>It is my understanding, from the books that I have, that the STATUS, Option, and INTCON registers can be poked and peeked. <hr></blockquote><p>I'm not sure which Pic Basic you are using, but normally PEEK and POKE basic commands access any variable directly.<p>Normally their usage is as follows -<p>A = PEEK register ADDRESS //Variable 'A' now holds the value of the register peeked. So -<p>A = PEEK 0x02 //Note 0x02 is the address of the Status register.<p>POKE 0x02,A //Status now contains the contents of A<p>If your version of basic allows it, you will find it is more efficient to access registers directly, such as A = STATUS_REG or whatever syntax your compiler uses.<p>The assembler equivalent of peek and poke is<p>movlw register_address //w holds reg address
movwf FSR //FSR now holds the contents of reg_addr
movf INDF,A //'A' now holds the contents of reg_addr.<p>Or for poking<p>as above but -<p>movf A,w
movwf INDF.<p>Normally this type of coding would be used if you didn't know where a particular variable/register lived and you needed to access large amounts of data.<p>For example, you want to send or receive a string of characters to a serial port or an LCD, and the length of this string could vary sometimes 10 bytes sometimes 40 etc. Then you would use PEEK and Poke.<p>So lets say you have a real time clock that sends you the time and calendar in seconds. You have declared either an array to hold these seconds or if your basic doesn't allow this a number of consecutive registers.<p>Naturally you don't want to have to think about addressing 32 consecutive bytes. So you'd use POKE.<p>for loop = 1 to 33
POKE secs, rtc_secs
secs = secs + 1
next<p>Confused? My poor explanation!<p>Colin<p>[ April 23, 2005: Message edited by: bodgy ]</p>
On a clear disk you can seek forever.
mustang
Posts: 31
Joined: Thu Jan 17, 2002 1:01 am
Location: Santa Ana, CA
Contact:

Re: PBC Pokes and Peeks

Post by mustang »

Thank you for the explanation Colin. I did get my counter to work after a lot of trial and error.
Do you know of any pic basic book or tutorial that deals with manipulating the available registers? Chuck Hellebuyck "Programming Pic Microcontrollers With PicBasic" briefly delves into the subject but does not give enough detail.
Thanks Again,
Ray
John Brown
Posts: 40
Joined: Mon Nov 01, 2004 1:01 am
Contact:

Re: PBC Pokes and Peeks

Post by John Brown »

<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">quote:</font><hr> quote:Why does the 16F84 have a status register in BANK 0 and also in BANK 1?[/ <p>Because the Pic is a risc based processor and uses the Harvard style architecture (data memory and program memory are on two different busses), Microchip make some of the essential Special File Registers available at all times. <hr></blockquote>
And, if memory serves, the bits which control the bank switching are part of the status register, so the scheme would be unworkable if the status register wasn't double-mapped (or quadruple mapped in the 16F877, for example).
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests