First Day and need Help!


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Yes it does help!

    To avoid two video channels is key to getting this program right.

    With a 5 bit word there are 64 possible input patterns, mostly it will just be a logic '1' with it
    just passing the data staight thro.

    But it gets very interesting when several go off! That will need data translation based on the significance of the pattern.

    IF A0 = 6 then PortB = 7 '4th video channel selected

    etc

    I'm not confident yet I've got the symbol/peek/poke syntax right. I've been posted the manual now, but feel very nervous about producing working code right now, so a code example would be brilliant!

    Many thanks again for responding.



    Tim

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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

  3. #3
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    You can also test the bits in the priority that you want them and jump to the right routine to flip the relay on, then no fancy stuff (masking, tables, lookups, etc).

    like (below is an idea, no idea if it will run) And it will look bad in PBC do to lack of IF ENDIF, but this should get you rolling. Assuming port A and B are PIR0 is RELAY0. Note I do not have the PBC manual with me and just received it and did not start using it do to conditionals, so below is just an idea. Take below and clean it up. Also, do not recall the two commands, the lookup and one other you can index and jump to them. Hope this helps.

    Symbol PortA = 5 'assuming it is 5
    Symbol PortB = 6 'check the ports in the PIC datasheet
    'set PortA and B directions and make sure PortA is in digital mode (some pic need that)

    top:
    peek PortA, B0 'might have these backwards (I am at work no PBC here
    if bit4 = 1 then turnon4 'highest priority camera
    if bit2 = 1 then turnon2 'etc
    goto top

    turnon4:
    poke PortB,%00010000
    goto top

    turnon2:
    poke PortB,%00000100
    goto top
    Last edited by mramos; - 2nd June 2006 at 16:39.

  4. #4
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Many thanks for that I'll take a very close look at it.

    Should watchdog fuse be ticked or not at time of flashing?

    Whilst I don't understand bits of it, I've been messing about and freely adapted a chunk of code posted by Lauren Barta

    Code:-

    Symbol TRISB = 134 'Symbol For TrisB Is Decimal 134
    Symbol TRISA = 133 'Symbol For TrisA Is Decimal 133
    Symbol PORTB = 6 'Symbol For PortB Is Decimal 6
    Symbol PORTA = 5 'Symbol For PortA Is Decimal 5


    Poke 134, 0 'Makes All PortB Pins Outputs
    Poke 133, 255 'Makes All PortA Pins Inputs

    Start:

    Poke 6, 0 'Makes PortB Pins Low
    Pause 10 'Short Pause

    Run:
    LET B2 = 0 'Making B2 a zero
    Pause 10 'Short Pause
    Peek PortA, B0 'Look at PortB, put results in B0

    Filters:
    IF B0 = 3 THEN Run1 'start of 24 filters, 23 yet to be added
    poke 6, B0
    Pause 7500 'Wait 3 seconds
    goto Run 'Start all over again!

    Run1:
    B0 = 5
    poke 6, B0
    Pause 7500 'Wait 3 seconds 10 Mhz clock
    goto Run 'Start all over again!

    End
    Last edited by timmoore47; - 2nd June 2006 at 19:29.

  5. #5
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    This is what I meant when I mail the last post from work. Use a couple of your lines.
    Code:
    Symbol TrisB = 134 
    Symbol TrisA = 133 
    Symbol PortB = 6 
    Symbol PortA = 5 
    
    Poke TrisB, 0      'Makes All PortB Pins Outputs
    Poke TrisA, 255   'Makes All PortA Pins Inputs
    
    Poke PortB, 0      'Makes PortB Pins Low
    
    'depending on PIC type, make sure PortA is set for Digital IO
    
    top:
    pause 7500
    peek PortA, B0           'read PIRs or sensors
    
    'check the sensor bits
    if bit4 = 1 then turnon4 'highest priority camera
    if bit2 = 1 then turnon2 'etc
    if bit1 = 1 then turnon1 'etc
    if bit3 = 1 then turnon3 'etc
    if bit5 = 1 then turnon5 'etc
    if bit0 = 1 then turnon0 'etc
    
    goto top
    
    turnon0:
    poke PortB,%00000001
               '76543210    'The relay to turn on is 0
    goto top
    
    turnon1:
    poke PortB,%00000010
               '76543210    'The relay to turn on is 1
    goto top
    
    turnon2:
    poke PortB,%00000100
               '76543210    'The relay to turn on is 2
    goto top
    
    turnon3:
    poke PortB,%00001000
               '76543210    'The relay to turn on is 3
    goto top
    
    turnon4:
    poke PortB,%00010000
               '76543210    'The relay to turn on is 4
    goto top
    
    turnon5:
    poke PortB,%00100000
               '76543210    'The relay to turn on is 5
    goto top
    Last edited by mramos; - 3rd June 2006 at 00:31.

  6. #6
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Paul & MrAmos,

    Thank you both so much for your substantial samples of code. Because of them I was able to complete and test the code using a test jig of a bunch of switches and led's for driving the video switch and pir inputs.

    FANTASTIC! IT WORKED AOK!

    I've got to finish off the PIR Inputs circuits and the video switch circuits but the hardware is easy compared to driving the PICs.

    I've avoided assembler which would have slowed the project down loads.

    The Hedgehog (European Wild variety) breeding season is upon us and in a about 3 weeks we hope to be able to track and record movement of the hoglets. We hope somewhere between 3 and 9 will arrive in the end of June batch and similar numbers in September and October.

    Curently we track 13 adult hedgehogs manually up to about 3am most nights and are VERY keen automate it. Since January we have filled 136 DVD's full of data burnt out two DVD Recorders and now use a Pioneer 80GB Recorder *LOL*.
    Many thanks again!



    Tim

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Tim,

    Post a picture to this thread of a hoglet camptured by PBC code - everyone would enjoy that (unless they do not like hedgehogs). We do not have hedgehogs here in Utah as far as I know.

    As a side note, you might want to check out this guy's stuff - awesome homebrew PIR camera stuff. I have made some of these camera modifications and they work quit well.

    http://www.jesseshunting.com/forums/...p?showforum=50

    As always
    Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  8. #8
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Many thanks Paul, I'll do that. Meanwhile here is a link to a video we made of a Hedgehog plus some other wild and not so wild life. The last few minutes is the best.

    Totally tame for non wild-life folk, BTW>



    Tim

    link:-

    http://video.google.com/videoplay?do...72146235684890

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts