Tim,
Do not make the peek/poke thing harder than it is. Think of it like this: Peek is literally peeking (or reading) the value of a register (register is a fancy word for variable) and poke is literally poking (or writing) a new value to the register. I like to think of the whole thing as two filing cabinets – one for RAM (registers and variables) and one for Porgram Memory. With PBC, each filing cabinet has only one drawer.
Imagine if you were an accountant and wanted to know how much money was in the “Johnson” account, you would probably go the filing cabinet, open it up, find the “Johnson” folder, and peek inside to see the value. In this example, the “Johnson” folder is the “address” of physical location of the file so you can find it easily every time.
PICs work the same way; they keep specific data in easy to find locations (called addresses) so you (and the PIC) can find it easily. The map of where these locations are detailed in the data sheet. You MUST download the 16F877 data sheet and look on page 13. Did I mention that you must get the data sheet! Here you will see that PORTA data is kept in location 5 of the “filing cabinet”, PORTB data is kept at Location 6, TRISA data is kept at location 133 (=85 in hex), and TRISB data is kept at location 134 (= 86 in hex). That's it. So if you want to change the value of PORTB, you need to open your filing cabinet, pull out file number 6 and write (i.e, poke) new values. If you want to setup PORTA as outputs, go to your filing cabinet, pull out file 134 and write your new values. If you want to know what value are on PORTA, go to your filing cabinet and take a peek in file 5. It will become straight forward.
You can set up Symbols to help you – but they are not necessary (but I recommend it).
For example
Symbol TRISA=133
Peek TRISA, B0
does the same thing as
Peek 133, B0
so does this
Symbol BlahBlah=5
Peek BlahBlah, B0
Most people set up the symbols (which only need to be done once) early in the program to make this easier to read.
Back to your HedgeHogs...
Here is a sample code that might get you going a bit
Symbol TRISA=133
Symbol TRISB=134
Symbol PORTA=5
Symbol PORTB=6
Symbol HogPIR = B0 ' B0 goes from 0 - 255
Symbol TimeOn=B1 ' B1 goes from 0-255
Poke TRISA, 31 ' make RA0-RA4 Inputs, rest outputs
Poke PORTA, 0 ' make PORTA outputs low
Poke TRISB, 0 ' make PORTB all outputs
Poke PORTB, 0 'make PORTB outputs low
PAUSE 2000 ' pause for 2 seconds for things to settle
Main:
Pause 1000 ' 1 second delay
TimeOn = TimeOn + 1
If TimeOn < 30 then SamplePIR
Poke PORTB, 0 ' turn off all VCRs – no PIR trip for 30 seconds
SamplePIR:
Peek PORTA, HogPIR
if HogPIR=0 then Main ; wait for Hog
TimeOn = 0 ' reset VCR time on
Poke PORTB, HogPIR ' make VCR relays on PORTB match PIR sensors of PORTA
goto Main
Note – or Tim, instead of PORTB mirroring PORTA for high signals, you could do smart sampling
If HogPIR = 1 then VCR0 ' RA0 = 1 so make RB0 = 1
If HogPIR = 2 then VCR1 ' RA1 = 1 so make RB1 = 1
If HogPIR = 3 then VCR0 ' RA0 and RA1 = 1 but only make VCR0 = 1
etc
VCR0:
POKE PORTB, 1
goto Main
VCR1:
POKE PORTB, 2
goto Main
VCR2:
POKE PORTB, 4
goto Main
VCR0_3:
Poke PORTB, 9
goto Main
etc.
I do not have PBC so I have not tried this but believe this should work
HTH,
Paul Borgmeier
Salt Lake City, Utah
USA




Bookmarks