asm to hex

Discussion in 'Programmer's Corner' started by markosillypig, Jan 28, 2009.

  1. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    hi all i have a asm file and need it converting to a hex file for a 12f629 chip
    could any one do this for me
    thanks again

    marko
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    When you write the assembler instructions in the editor, the file that they get stored in is the .asm. After you tell the editor to process the instructions, the hex file is produced.
     
  3. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    i got this asm code of a web site and i have no idea about codeing yet i'm learning so if some one could change it to a hex file it would be much appreciated untill i learn how to do this my self
     
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    I guess another way to put the answer is how are you going to program the chip, once you have the hex file? There should be an assembler available for your programmer.

    John
     
  5. kahafeez

    Active Member

    Dec 2, 2008
    150
    0
    Hey Mark, all u need is a good assembler like Keil..... u can find Keil at www.esnips.com and search for Keil...... version 8 is better


    if u need any help just PM me....
     
  6. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    i'm using winpic 800 and a jdm programmer
     
  7. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    i have had a go at making the hex file from this asm file unfortunatly no
    succsess
    so acn some one do the trick for me i have attached the asm file
    thanks

    ;*****************************************************************************
    ; Navlights.asm LED Lighting System
    ;*****************************************************************************
    ; Bruce Abbott bhabbott@paradise.net.nz
    ;
    ; for Microchip PIC 12C508, 12C509, 12F629 or 12F675.
    ;
    ;=============================================================================
    ; Summary of Changes
    ;
    ; 2005/03/15 V0.0 - Created from RXDecode.asm
    ; 2005/08/06 V0.1 - Two strobe lights, asyncronous flash sequence.
    ; 2005/12/17 V0.2 - Servo input selects Landing, Lights On, or Lights Off.
    ; -----------------------------------------------------------------------------
    #DEFINE TIME 4 ; number of servo pulses per strobe state
    #DEFINE version "0.2"
    ;#DEFINE __12C508 ; enable if processor not specified elsewhere
    ;#DEFINE __12F675 ; MPLAB users should use menu <Configure/Select Device>
    ;#DEFINE NO_OSCCAL ; enable if OSCCAL value was erased!

    ifdef __12C508
    PROCESSOR PIC12C508
    INCLUDE <P12C508.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
    else
    PROCESSOR PIC12F675
    INCLUDE <P12F675.inc>
    __CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
    endif
    radix dec
    errorlevel 0,-305,-302

    ; Bit definitions for the GPIO register and the TRIS register
    ; NOTE: LED is turned on when its GPIO ouput is LOW.
    ;
    #DEFINE STRB1 5 ; pin 2 Strobe Light #1
    #DEFINE STRB2 4 ; pin 3 Strobe Light #2
    #DEFINE SERVO 3 ; pin 4 servo pulse input
    #DEFINE LAND 2 ; pin 5 Landing Lights
    #DEFINE LED1 1 ; pin 6 Fixed lighting (eg. Navigation Lights)
    #DEFINE LED2 0 ; pin 7 More Fixed Lighting (eg. Cabin Lights)
    ;
    #DEFINE TrisBits (1<<SERVO) ; servo pulse is an input
    ; -------------------- OPTIONS ------------------------
    ; no wakeup (12C508)
    ; weak pullups enabled
    ; Timer 0 source internal
    ; Prescaler to Timer 0, divide by 256.
    ;
    ifdef __12C508
    #DEFINE OptionBits B'10000111'
    else
    #DEFINE OptionBits B'00000111'
    endif

    ;=========================================================================
    ; Macro for generating short time delays
    ;
    NO_OP MACRO count
    NO_OP_COUNT SET count
    WHILE NO_OP_COUNT>1
    goto $+1 ; 2 clocks
    NO_OP_COUNT SET NO_OP_COUNT-2
    ENDW
    IF NO_OP_COUNT
    nop ; 1 clock
    ENDIF
    ENDM
    ;===========================================================================
    ; Macro to create offsets for variables in RAM
    ;
    ifdef __12C508
    ByteAddr SET 7
    else
    ByteAddr SET 32 ; user RAM starts here
    endif
    BYTE MACRO ByteName
    ByteName EQU ByteAddr
    ByteAddr SET ByteAddr+1
    ENDM
    ; ==========================================================================
    ; RAM Variable Definitions
    ;
    BYTE Flags ; various boolean flags
    BYTE ServoCount ; servo pulse length. 1~255 = 0.01~2.55mS
    BYTE Timer ; delay timer for strobes
    BYTE Strobe1 ; strobe 1 sequencer
    BYTE Strobe2 ; strobe 2 sequencer
    BYTE Glitches ; number of consecutive bad servo pulses
    BYTE Temp1
    BYTE Temp2

    ; flag values
    ;
    #DEFINE WATCH 0 ; Watchdog timed out
    #DEFINE STROBE1 1 ; strobe 1 on
    #DEFINE STROBE2 2 ; strobe 2 on
    #DEFINE LANDING 3 ; Landing lights on

    ;****************************************************************************
    ; Code
    ;
    ORG 0
    goto ColdStart
    ;-------------------------- version string ----------------------------------
    org 8
    ifdef __12C508
    dt "LIGHT508"
    endif
    ifdef __12F629
    dt "LIGHT629"
    endif
    ifdef __12F675
    dt "LIGHT675"
    endif
    dt "--V"
    dt version
    dt "--"
    ;============================================================================
    ColdStart:
    bcf Flags,WATCH
    btfss STATUS,NOT_TO ; copy Watchdog timeout flag
    bsf Flags,WATCH
    ; get oscillator calibration value and use it to fine-tune clock frequency.
    ; 12C508/9 has value in W at startup, 12F629/75 gets it from RETLW at 0x3ff.
    ifdef __12C508
    ifdef NO_OSCCAL
    movlw 0x90 ; replace with value for your PIC!
    endif
    movwf OSCCAL ; set oscillator calibration
    else
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    call 0x3ff ; get OSCCAL value
    movwf OSCCAL ; set oscillator calibration
    bcf STATUS, RP0 ; register bank 0
    endif
    ; set options
    ifdef __12C508
    movlw OptionBits
    option
    else
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw OptionBits
    movwf OPTION_REG
    bcf STATUS,RP0 ; register bank 0
    endif
    ;========================================================================
    ; initialise I/O registers
    ifdef __12C508
    movlw 0
    movwf GPIO ; all outputs on
    movlw TrisBits
    TRIS GPIO ; set I/O pin directions
    else
    clrf GPIO ; all outputs low
    bsf STATUS,RP0 ; register bank 1 (12F629/75)
    movlw TrisBits
    movwf TRISIO ; set I/O pin directions
    ifdef ANSEL
    clrf ANSEL ; disable analog inputs (12F675)
    endif
    bcf STATUS,RP0 ; register bank 0
    ifdef CMCON
    movlw b'00000111'
    movwf CMCON ; Comparator off
    endif
    endif
    ; CPU specific stuff done, now we can start the main program!
    goto Main
    SeqStrobe1:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe1,w
    addwf PCL
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    SeqStrobe2:
    ifdef PCLATH
    clrf PCLATH
    endif
    movf Strobe2,w
    addwf PCL
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000001'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'00000000'
    retlw b'10000000'
    ;-------------------------------------------------------------------------------
    ; Millisecond Delay Timer
    ;-------------------------------------------------------------------------------
    ; Input: W = number of milliseconds to wait (max 256mS)
    ;
    dx1k: movwf Temp1
    _dx1k1: movlw (1000-5)/5
    movwf Temp2
    _dx1k2: clrwdt ; avoid watchdog timeout
    nop
    decfsz Temp2 ; wait 1mS
    goto _dx1k2
    decfsz Temp1
    goto _dx1k1
    retlw 0

    ;*******************************************************************************
    ; Main
    ;*******************************************************************************

    Main: btfsc Flags,WATCH ; did the watchdog timeout ?
    goto MainLoop ; oops! try to keep going ...
    clrf Flags ; clear all flags
    movlw 250 ; wait 500mS for power to stabilise
    call dx1k
    movlw 250
    call dx1k
    movlw TIME
    movwf Timer
    clrf Strobe1
    clrf Strobe2
    clrf Glitches
    MainLoop: clrf TMR0 ; start timer
    WaitLow: clrwdt ; avoid watchdog timeout
    btfsc TMR0,7 ; timer reached 33mS ?
    goto NoSignal
    btfsc GPIO,SERVO ; wait for no servo pulse
    goto WaitLow
    clrf TMR0 ; start timer
    waitpulse: clrwdt ; avoid watchdog timeout
    btfsc TMR0,7 ; timer reached 33mS ?
    goto NoSignal
    btfss GPIO,SERVO ; wait for start of servo pulse
    goto waitpulse
    clrf ServoCount
    measure: clrwdt ;1
    incf ServoCount ;2 count = pulse width (* 10uS)
    skpnz ;3 > 2.55mS ?
    goto BadPulse ;4 Yes, error
    NO_OP 3 ;5~7
    btfsc GPIO,SERVO ;8 servo pulse finished ?
    goto measure ;9,10 no, continue measuring
    movlw 70
    subwf ServoCount,w ; less than 0.7mS ?
    skpc
    goto BadPulse ; yes, bad pulse
    bcf Flags,LANDING ; assume landing lights are off
    movlw 130
    subwf ServoCount,w ; less than 1.3mS ?
    skpc
    bsf Flags,LANDING ; yes, landing lights on
    movlw 170
    subwf ServoCount,w ; less than 1.7mS ?
    skpc
    goto power_on ; yes, power on
    power_off movlw 1<<STRB1|1<<STRB2|1<<LAND|1<<LED1|1<<LED2
    movwf GPIO ; All lights OFF
    goto GoodPulse
    power_on: bcf GPIO,LED1 ; fixed lights ON
    bcf GPIO,LED2
    landing_lights: btfss Flags,LANDING
    bsf GPIO,LAND ; Landing lights OFF
    btfsc Flags,LANDING
    bcf GPIO,LAND ; Landing lights ON
    strobes: decfsz Timer ; time for next strobe change?
    goto GoodPulse ; no, done
    movlw TIME
    movwf Timer ; restart timer
    call SeqStrobe1 ; get Strobe 1 state
    movwf Temp1
    incf Strobe1 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe1 ; restart sequence
    bcf Flags,STROBE1
    btfsc Temp1,0 ; strobe 1 to be on ?
    bsf Flags,STROBE1
    call SeqStrobe2 ; get Strobe2 state
    movwf Temp1
    incf Strobe2 ; next state
    btfsc Temp1,7 ; end of sequence ?
    clrf Strobe2 ; restart sequence
    bcf Flags,STROBE2
    btfsc Temp1,0 ; strobe 2 to be on ?
    bsf Flags,STROBE2
    btfss Flags,STROBE1
    bsf GPIO,STRB1 ; flash strobe 1
    btfsc Flags,STROBE1
    bcf GPIO,STRB1
    btfss Flags,STROBE2
    bsf GPIO,STRB2 ; flash strobe 2
    btfsc Flags,STROBE2
    bcf GPIO,STRB2
    GoodPulse: tstf Glitches
    skpnz
    goto done
    decf Glitches ; another good pulse received
    goto done
    BadPulse: incf Glitches ; another bad pulse!
    movlw 10
    subwf Glitches,w
    skpc ; too many bad pulses?
    goto done
    decf Glitches
    NoSignal: movlw 1<<STRB1|1<<STRB2|1<<LAND|1<<LED1|1<<LED2
    movwf GPIO ; turn off all outputs
    done: goto MainLoop



    ;---------- Oscillator Calibration Subroutine (12F629/75 only) --------------
    ifdef __12F675
    org 0x3ff
    retlw 0x90 ; replace with oscal value for your PIC!
    endif
    END
     
  8. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    I copied what you posted, made a new project in MPLab 8.0, and pasted the material. There appeared to be some errors, and the asm code would not compile.

    Some superficial observations: The file is made for the 12C508 and 12F675 You need to change the file for the processor you are going to use, or are you using the 12F675? I am not adept at assembly to debug the file quickly. So, you might want to download your assembler (like MPLab) and get the file debugged and working before trying to program a chip.

    John

    John
     
  9. markosillypig

    Thread Starter Active Member

    Jul 21, 2008
    184
    0
    well i'm not as clever as you so if you could debug it for me i would be eternerly thankfull i got the sorce from and it is for a 12f629 acording to the site
    http://homepages.paradise.net.nz/bhabbott/navlights.html
    hope this helps you
    thanks once again
    ps i found errors with keil but i dunno what to do or how to make it into a hex file :mad:
     
    Last edited: Jan 28, 2009
  10. kahafeez

    Active Member

    Dec 2, 2008
    150
    0
    as long as there are errors in the code the compiler wont make the hex file..... anyway below is the way of making a hex file using Keil (can be found on www.esnips.com and search for Keil. version 8 is better)......

    in the file menu goto project> new project> then choose the ic> then make a new text file> then save it with the name and extension .asm> then copy paste the code u have>

    after u've saved the file with the name and extension .asm then u need to expand the folder whose name is Target1 (its located on the extreme left corner of the monitor) then u expand it by clicking on the plus sign.... then u right click the source group1 folder and choose add files to group..... and then select ur file, the asm file.... click the add button and then close button

    then open the wand button next to the place where its written Target1.... this button says options for target if u keep the mouse on it for a while..... open that button and in the ouput tab check create hex file.... then complie the program and u'll find the hex file present in the folder where u saved the project.....
     
Loading...