First Day and need Help!


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Drop list <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=872&stc=1&d=1147960259 ">

    Now with PBC... iiiish i'm sorry i couldn't be much help but i believe that...
    Code:
    Symbol DDIR = Dir0 ' Shift data pin direction is Dir0
    Symbol DPIN = Pin0 ' Shift data pin is 0
    Symbol CPIN = 1 ' Shift clock pin is 1
    
    Symbol I = B2 ' Loop counter
    Is invalid. I know you must use or redefine specific variable name.. about the PORTA, PORTB.. name it's sure you can't use Dir0, Pin0 and 1

    Fortunately, there's some user here who use PBC and can help.
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, Has anyone got a very simple code fragment I could try?

    So far I've not got off ground zero!

    Maybe I've got a duff install?



    Tim

  3. #3
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    I have a few, what type program are you after. I have one that runs two servos, to move my robot dog (PWM commands to servos). It is old and I would have to clean it up.

    I have one that reads and LDR and buzzes a Piezo buzzer every 30 seconds.

    What are you tryig to do?

  4. #4
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you for responding.

    I'm building a video switching unit. To choose between 5 video channels and just switch one of them to a DVD Recorder. It's monitoring nocturnal wild Hedgehog activityin a UK garden.

    I've got 5 PIR Sensors which kick out +5 volts when a hedgehog passes by.

    So for each binary pattern on PortA, a single relay attatched to the first 5 of PortB pins is switched.

    So I need to set PortA to be inputs, PortB to be outputs then read portA, make a decision, set a relay and delay, then do it again.

    Easy enough on paper but PBC code seems to use different commands to other PicBasics I've used and I got confused badly on setting up and reading PortA and defining variables.



    Tim

  5. #5
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    I am heading for work now. So not much time.

    You need to symbol portA and portB to there locations.
    Then peek portA (say into B0), do any logic on it
    Then poke portB with your results from B0.

    What happened if two PIRs are tripped? Do you have a priority for them?
    You will probably want to make sure there is only one bit set in B0 otherwise
    you will have two or more relays flip on (multiple video coming in).

    If this does not help, later I will see if I can send a sample. Just running late right now.

  6. #6
    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

  7. #7
    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

  8. #8
    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.

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