How to get .hex from this code??


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Question How to get .hex from this code??

    Hi guys.

    I have been working with electronics for over 15years but i am absolutly newby with PIC's. That's include all stuff about programming them.
    I've found one project which catched my eye. It's servo controller with PIC16F84A.
    There is some sort of code, but i don't know how to use it. Can someone guide me what software i can use to get .hex file from that code?
    I will really appreciate that.
    Thanks a lot.

    Best tegards
    Brano

    The project is here.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Brano,
    You will need the M E Labs PIC Basic Pro Compiler. It is available from:
    http://www.rentron.com/PicBasic/PBP.htm
    http://www.microengineeringlabs.com/
    http://www.crownhill.co.uk/level3.php?cat=40
    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


    Did you find this post helpful? Yes | No

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Michael Wakileh View Post
    Omission unintentional, please pardon.
    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.

  5. #5
    Join Date
    Jun 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thank you guys for reply.
    Doesn't the code from Listing 3 below have to be somehow modified?
    Code:
    'Manual control of two servomotors using 2 SPDT switches
    
    'Use B1 to hold pulsewidth variable for servo 1
    'Use B2 to hold pulsewidth variable for servo 2
    
    'Initialize Variables
    
    B1 = 150
    B2 = 150
    
    'start servo 1 at center position
    'start servo 2 at center position
    
    start:
       IF pin1 = 0 Then left1
       IF pin2 = 0 Then right1
       IF pin4 = 0 Then left2
       IF pin5 = 0 Then right2
       PulsOut 0, B1
       PulsOut 3, B2
       Pause 18
       GoTo start
    
    'check for switch closures
    'is sw1 left active?
    'is sw1 right active?
    'is sw2 left active?
    'is sw2 right active?
    'send current servo 1 position out
    'send current servo 2 position out
    
    'Routines for Servomotor 1
    left1:
       B1 = B1 + 1
       PulsOut 0, B1
       PulsOut 3, B2
       Pause 18
       IF B1 > 225 Then max1
       GoTo start
    right1:
       B1 = B1 - 1
       PulsOut 0, B1
       PulsOut 3, B2
       Pause 18
       IF B1 < 75 Then min1
    GoTo start
    max1:
       B1 = 225
       GoTo start
    min1:
       B1 = 75
       GoTo start
    
    
    
    'increase the pulse width
    'send current B1
    'send current B2
    'set frequency update about 50 hz
    'maximum 2.25 millisecond
    
    
    'decrease the pulse width
    'send current B1
    'send current B2
    'set frequency update about 50 hz
    'minimum .75 millisecond
    
    
    'cap max B1 at 2.25 milliseconds
    
    
    'cap min B1 at .75 millisecond
    
    'Routines for Servomotor 2
    left2:
       B2 = B2 + 1
       PulsOut 0, B1
       PulsOut 3, B2
       Pause 18
       IF B2 > 225 Then max2
       GoTo start
    right2:
       B2 = B2 - 1
       PulsOut 0, B1
       PulsOut 3, B2
       Pause 18
       IF B2 < 75 Then min2
       GoTo start
    max2:
       B2 = 225
       GoTo start
    min2:
       B2 = 75
       GoTo start

    Because if i try to compile it with MicroCode Studio - PICBASIC PRO, i'll receive too many errors like:
    ERROR Line 15: Bad expresion. (ser1.txt)
    There are errors almost for each line.
    As i am absolute NOVICE in coding, those errors are bit over my head

    I have seen some codes, where guys had something like:
    Code:
    #include < blablabla.h >
    Does i need some .h file to be included?
    Last edited by irootsk; - 21st June 2009 at 02:26.

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    I have seen some codes, where guys had something like:
    Code:
    #include < blablabla.h >
    Does i need some .h file to be included?
    Right you are. The code looks like it was written for a Basic Stamp Pic Chip. For this, just add the include at the top of your program, then it will compile without errors.
    Code:
    DEFINE OSC 20       'define crystal speed. This is 20 mhz
    include "bs1defs.bas"    'lets you use definitions same as Basic Stamp 1
    Last edited by ScaleRobotics; - 21st June 2009 at 08:29.
    http://www.scalerobotics.com

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Looks like the code may work straight away with MeLabs PBC (Pic Basic Compiler) rather than PBP (Pic Basic Pro).

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by scalerobotics View Post
    Code:
    DEFINE OSC 20       'define crystal speed. This is 20 mhz
    include "bs1defs.bas"    'lets you use definitions same as Basic Stamp 1
    Hi,

    No,No ... error this code has been written for a 4 Mhz Pic or BS1 ... ( pulsout units are 10µs ! )

    No need any "DEFINE OSC " then ...
    nor "bs1defs" ... as pins are " genuine numbered " by PBP



    Other project error : Pic and Servos MUST NOT share the same supply ... if you want them to work properly ...

    and R2 / R4 might get their supply from +5 v ... NO MORE !

    In other words ... soft may be Ok, as Mel states ... but not Hardw. !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Thanks Alain, good catch on the pulseout.

    But speaking of errors, when I try to compile on PBP without using:

    Code:
    INCLUDE "bs1defs.bas"
    I get too many errors to compile. It gets stuck on the first mention of variables:
    Code:
    B2 = B2 + 1
    How do you overcome this with Picbasic Pro, without using the include (and without defining each variable separately)? My manual states I must include "for compatibility sake", and that the include creates "the standard variables used with the Basic Stamps", not to mention that it compiles without errors when I use the include.....
    http://www.scalerobotics.com

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Right ... definitly a Stamp dinausaur ...

    So just add at the progam top:

    B1 var Byte ' "B" stands for Byte, " W " for Word, ... in the Stamp language.
    B2 var Byte

    care must also be taken Stamp automatically resets variables to zero ... and PbP not !

    I prefer writing it like that for " little RAM " processors ... like my old 16C84s ... than include BSx inc Files ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Jun 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    thank you for all replys guys.

    after modification of code with:

    Code:
    include "bs1defs.bas"
    
    B1 VAR BYTE
    B2 VAR BYTE
    i was able to compile it.
    When i press the coresponding button, servo1 react, but it's bit slow.
    Servo2 doesn't react on button. It's just go full CW and then stop. And sometimes it buzzing.
    Aslo, when i want to turn servo1, servo2 is trying to move.
    But that's probably of shared power supply.
    I will try to rebuilt it.

  12. #12
    Join Date
    Jun 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Actually, all i had to ad to the code was just
    Code:
    include "bs1defs.bas"
    If i tried it with
    Code:
    B1 VAR BYTE
    B2 VAR BYTE
    i received an error: Redefinition of VAR

  13. #13
    Join Date
    Jun 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    One more question. What about Fuses? What should i set for my for that project? I've got MPASM from Microchip.

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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