First Day and need Help!


Closed Thread
Results 1 to 18 of 18
  1. #1
    timmoore47's Avatar
    timmoore47 Guest

    Default First Day and need Help!

    Just getting started but unfamiliar with this Micro Code Studio environment.

    I get an error message about not supporting 16F877 on a sample program.

    Well I want to program 16F628A and 16F84A Pics, so how do I do that?

    Normally I'd start with

    Device 16F628
    Dim A, B
    Define PortA %00000000
    etc etc

    but what do I need to get this off the ground?

    A puzzled,

    TIM

    PS Any really noddy tutorials around?

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


    Did you find this post helpful? Yes | No

    Default

    If the 16F877 is on the drop list it must work.

    remove your config fuse to see. If there's any other problem, tell us your PBP version, Microcode Studio version and also post your code here.
    Steve

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

  3. #3
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    If the 16F877 is on the drop list it must work.

    remove your config fuse to see. If there's any other problem, tell us your PBP version, Microcode Studio version and also post your code here.
    Err... I don't know where the drop list is. THe version of Micro Code Studio is v 2.2.1.1

    The Read.me file says this:-
    PICBASIC(TM) Compiler Ver. 1.45 README.TXT
    Copyright 2005 microEngineering Labs, Inc.

    I don't know if it's integrated correctly Into PIC BASIC Standard.

    The code is one of the Samples:-


    ' Simulate BS2 Shiftin and Shiftout

    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


    ' Shift in some data
    Low CPIN ' Start shift clock low

    Gosub shiftin ' Shift in some data

    ' Shift out some data
    Low CPIN ' Start shift clock low

    B0 = 100 ' Data to shift out
    Gosub shiftout ' Go do it

    End


    ' Subroutine to synchronously shift in one byte
    shiftin: DDIR = 0 ' Set data pin direction to input

    For I = 1 to 8 ' 8 bits to a byte
    B0 = B0 * 2 ' Shift result 1 bit to the left
    Toggle CPIN ' Toggle shift clock
    Bit0 = DPIN ' Move data into LSB
    Toggle CPIN ' Toggle shift clock once more
    Next I ' Loop

    Return ' Go back to caller


    ' Subroutine to synchronously shift out one byte
    shiftout: DDIR = 1 ' Set data pin direction to output

    For I = 1 to 8 ' 8 bits to a byte
    DPIN = Bit0 ' Data out is LSB
    Toggle CPIN ' Toggle shift clock
    B0 = B0 / 2 ' Shift byte 1 bit to the right
    Toggle CPIN ' Toggle shift clock once more
    Next I ' Loop

    Return
    Last edited by timmoore47; - 18th May 2006 at 14:48.

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

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

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

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

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

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

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

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

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

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

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

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

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

  17. #17
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    Tim:

    Good stuff. My kids loved it (3 boys).. We used to, a few years ago, I would put a PIR an a long cat 5 wire in the yard, and a battery and buzzer at the other end. When a raccoon would come up (I would leave sardines in front of the PIR) go on the balcony and watch them eat. They loved it..

    It was funny, you hear the buzzer, and kids running up the stairs.. It reminded me of those days.

    It us know if you have any questions. Or hardware issues to resolve.

  18. #18
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks MrAmos! Your Racoons sound fun!

    Hardware should be OK but I'll keep in touch as to the progress!



    Tim

Members who have read this thread : 1

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