Help Pbasic to PBP


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    49

    Default Help Pbasic to PBP

    Please help me to translate this code to PBP. I need this for my robotic project.I am using 16F877a .
    Code:
    ' -----[ Title ]-----------------------------------------------------------
    '
    ' File...... PARROT.BS2
    ' Purpose... ISD25xxx Controller
    ' Author.... Jon Williams
    ' E-mail.... [email protected]
    ' Started... 03 APR 1999
    ' Updated... 29 JUL 2000
    
    
    ' -----[ Program Description ]---------------------------------------------
    '
    ' This program, based on an original by Mike Politoski, controls anISD25xxx
    ' series ChipCorder(r) IC.  This program allows the user to record a
    ' message (length determined by the chip) and play it back several times
    ' to train a parrot or other talking bird.
    '
    ' Note: The ISD25xxx is configured for Mode 6, push-button mode.
    '
    ' Modes:
    '
    ' - Record:   Press and hold record button
    ' - Play:     Press play button
    ' - Training: Press start button
    
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    '
    LEDr_   CON    6         ' recording LED
    LEDp_   CON    7         ' playback LED
    LEDt_   CON    8         ' training LED
    
    PR   CON    9         ' ISD Play/Record_
    PD   CON   10         ' ISD Power Down
    CE_   CON   11         ' ISD Chip Enable
    
    BtnRec   VAR   In12         ' Record control button
    BtnPlay   VAR   In13         ' Play control button
    BtnGo   VAR   In14         ' Start control button
    RecRun   VAR   In15         ' recording/running out from ISD
    bPort   VAR   InD         ' buttons port
    
    
    ' -----[ Constants ]-------------------------------------------------------
    '
    On   CON   0         ' active low
    Off   CON   1
    
    Yes   CON   1         ' active high
    No   CON   0
    
    
    ' -----[ Variables ]-------------------------------------------------------
    '
    btns   VAR   Nib         ' debounced inputs
    state   VAR   Byte         ' button input state
    delay   VAR   Word         ' delay before training
    x   VAR   Byte         ' loop counter
    y   VAR   Word         ' loop counter
    plays   VAR   Word         ' plays counter
    
    
    ' -----[ Initialization ]--------------------------------------------------
    '
    Init:
      HIGH PD            ' reset ISD address
      HIGH CE_
      HIGH PR            ' default to Play mode
      HIGH LEDr_            ' record LED off
      HIGH LEDp_            ' play LED off
      HIGH LEDt_            ' train LED off
      PAUSE 30            ' allow device to reset
      LOW PD            ' bring out of reset
    
    
    ' -----[ Main Code ]-------------------------------------------------------
    '
    Main:
      GOSUB GetBtn
      IF btns > %000 THEN Main         ' wait for release
    
    Scan:
      GOSUB GetBtn
      LOOKDOWN btns,[%000, %001, %010, %100],state
      BRANCH state,[Scan, _Rec, _Play, _Train]
      GOTO Scan
    
    _Rec:
      PAUSE 250            ' time to get ready
      LOW PR            ' record mode
      GOSUB Blip            ' initiate recording
      LOW LEDr_            ' record LED on
    
    RLoop:
      GOSUB GetBtn
      IF btns = %001 THEN RLoop      ' record until release
      HIGH PD            ' reset device
      GOTO Init
    
    _Play:
      PAUSE 500            ' time to release play
      HIGH PR            ' playback mode
      GOSUB Blip            ' initiate playback
      LOW LEDp_            ' play LED on
    
    PLoop:
      GOSUB GetBtn
      IF btns > %000 THEN Init      ' abort if any button pressed
      IF RecRun = Yes THEN PLoop      ' check until message done
      HIGH PD            ' reset device
      GOTO Init
    
    _Train:
      PAUSE 500            ' time to release start button
    
      FOR delay = 1 to 280         ' 5 minute delay
        LOW LEDt_            ' train LED on
    
        FOR y = 1 TO 9         ' ~1/2 second delay
          GOSUB GetBtn         ' - check inputs
          IF btns > %000 THEN Init      ' abort if button pressed
        NEXT
    
        HIGH LEDt_            ' train LED off
    
        FOR y = 1 TO 9         ' ~1/2 second delay
          GOSUB GetBtn         ' - check inputs
          IF btns > %000 THEN Init      ' abort if button pressed
        NEXT
    
      NEXT ' delay
    
      LOW LEDt_            ' train LED on
      FOR plays = 1 TO 100         ' play message 100 times
        HIGH PR            ' play mode
        GOSUB Blip            ' initiate play
        LOW LEDp_            ' play LED on
    
    SLoop:
        GOSUB GetBtn
        IF btns > %000 THEN Init      ' abort if any button pressed
        IF RecRun = Yes THEN SLoop      ' wait until finished playing
        HIGH PD            ' reset the ISD
        HIGH LEDp_            ' play LED off
        PAUSE 25
        LOW PD            ' out of reset
    
        FOR y = 1 TO 500         ' 30 second delay between plays
          GOSUB GetBtn         ' scan buttons
          IF btns > 0 THEN Init      ' abort if button pressed
        NEXT
    
      NEXT
    
      GOTO Init            ' reset and start over
    
    
    ' -----[ Subroutines ]-----------------------------------------------------
    '
    Blip:
      LOW CE_            ' initiate playback or record
      PAUSE 25
      HIGH CE_
      RETURN
    
    
    ' scan and debounce button inputs
    ' - inputs must stay low for 50 ms
    ' - any debounced button returns high bit in "btns"
    '
    GetBtn:
      btns = %0111            ' scan record, play and wait
      FOR x = 1 TO 5
        btns = btns & ~bPort      ' check current state
        PAUSE 10
      NEXT
      RETURN

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    ON and Off are reserved words so change them, I added another letter to their ends, no NIB var type, so change to BYTE variable, Now In12,13 14 . . . must be aliases for ports, your choice, I tried portB pins and it all compiles.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    49


    Did you find this post helpful? Yes | No

    Default

    Thanks Joe S.
    I'll give a try and see the outcome.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 03:16

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