# Help converting an "asm" file over to HEX for a PIC12F508 ic

#### Flash001USA

Joined Nov 27, 2020
15
Hi I am searching for someone who can help me with converting an open source assembly code "asm file" over to a hex file for a PIC12F508 ic. I'm retired from the electronics field and I do not have the knowledge or proper training to convert this file over myself. I did try my hand at MPLAB ver 8.xx but I'm spinning my wheels and driving blind with this process. A bit about me: I come from the wild world of analog electronics repair along with some with digital troubleshooting skills but unfortunately I do not possess skills for actual programming and this is something that I rarely ever do and when I have programmed ic's in the past it was with pre-written ready to go HEX files for open source projects. I'm in the process of trying to learn this skill but it's going to take me a while to absorb this and in the meantime I'm hoping to find someone who can help me with this conversion. Any help whatsoever would be greatly appreciated. Once again, this is open source code so there are no restrictions to using this code. Thank you.

#### Attachments

• 26.7 KB Views: 29

#### MrChips

Joined Oct 2, 2009
25,928
I am not an MPLAB fan but as I understand it, you open MPLAB, copy the .asm file into the text editor.
Connect your PIC using a PICkit and hit Run.

#### Flash001USA

Joined Nov 27, 2020
15
First-most, THANK YOU for the reply. I'm running a ic programmer that I purchased off of ebay that does have the PIC12F508 chip listed in it's library and there should be no problems with the actual programming or even reading and saving hex files from an unsecured ic using this hardware. Unfortunately I don't have a PICkit programmer. From what I am led to understand (unless I'm mistaken and I very well could be) I would first need to convert this asm file over to a HEX file before I could program it to an ic. The MPLAB program has the ability to convert the file over even without using a programmer hooked to the computer and it should allow the conversion to be saved as a standalone HEX file but this program is somewhat over my head and from what I've seen on youtube related to this program, and even those videos are sketchy at best. As far as the actual programming goes, I should be able to use any ic programmer to do the job with as long as the ic is supported in the software for a given ic with any programmer. From what you're telling me it sounds as if the MPLAB program does this in a sort of cut and paste process where I simply paste the asm file contents into a text editor and use the PICkit programmer to automatically do the conversaion and programming in one process. Are you telling me that the conversion happens in the programming half of the MPLAB software? There are two separate MPLAB programs. One is the meat and potatoes program for heavy duty writing and editing of files and the other is for an actual hardware interface for the programmer like the one you mentioned. If that's the case can the file not be pasted into the programmer part of MPLAB and then saved as a HEX file? Forgive me if I am making this more complicated than it really is.

#### Flash001USA

Joined Nov 27, 2020
15
I am not an MPLAB fan but as I understand it, you open MPLAB, copy the .asm file into the text editor.
Connect your PIC using a PICkit and hit Run.
One more thing I should have mentioned. Unfortunately the ic programmer I have is not listed in the MPLAB programming software list.

#### MrChips

Joined Oct 2, 2009
25,928
Ok. Let's break this down a little. A platform such as MPLAB is called an IDE = Integrated Development Environment.
It integrates many components:

1. Text Editor
2. C compiler
3. ASM assembler
5. Chip Programmer
6. Code debugger

You can use MPLAB to take your .asm code and produce a .hex file.

#### jpanhalt

Joined Jan 18, 2008
11,088
I have uploaded the hex file as .hex and .txt

I would not recommend using that chip. It is one-time programmable. That may be why your programmer doesn't list it. What programmer do you have? You canchange the processor to 12F508A or 12F509A and it may work.

#### Attachments

• 2.9 KB Views: 14
• 2.9 KB Views: 16

#### Flash001USA

Joined Nov 27, 2020
15
I am not an MPLAB fan but as I understand it, you open MPLAB, copy the .asm file into the text editor.
Connect your PIC using a PICkit and hit Run.
I almost forgot. My programmer is not supported in the MPLAB programmer software.

#### Flash001USA

Joined Nov 27, 2020
15
Ok. Let's break this down a little. A platform such as MPLAB is called an IDE = Integrated Development Environment.
It integrates many components:

1. Text Editor
2. C compiler
3. ASM assembler
5. Chip Programmer
6. Code debugger

You can use MPLAB to take your .asm code and produce a .hex file.
You said that "You can use MPLAB to take your .asm code and produce a .hex file hen use your programmer to program your PIC chip." Yes this I am well aware of. What I'm not clear on is which steps I need or do not need to take for this process. All I am trying to do is manavure my way around in the program and produce a viable HEX file from the asm file but I have had no luck. Please understand that I am not a code writer and that is my shortfall here. I tried to follow steps the from a few youtube videos and from what I was able to pick up playing monkey see monkey do, there are a handful of steps INCLUDING selecting the correct sub program for the given ic you are converting the asm file over with but I only came up with errors and was not able to produce the actual HEX file. This is why I was asking for someone to possibly help me with the conversion this file. This is something that I rarely do and when I do a project like this it's always from a pre-built hobby project.

Last edited:

#### MrChips

Joined Oct 2, 2009
25,928
@jpanhalt went ahead and converted the .asm file to .hex.
Can you use that?

#### Flash001USA

Joined Nov 27, 2020
15
I have uploaded the hex file as .hex and .txt

I would not recommend using that chip. It is one-time programmable. That may be why your programmer doesn't list it. What programmer do you have? You canchange the processor to 12F508A or 12F509A and it may work.
Thank you. I actually have two versions of this IC. One is a single write IC and the other IC can be erased and rewritten. Both IC's should be compatible from what I understand.

#### jpanhalt

Joined Jan 18, 2008
11,088
Then your question is solved, right?

#### Flash001USA

Joined Nov 27, 2020
15
I have uploaded the hex file as .hex and .txt

I would not recommend using that chip. It is one-time programmable. That may be why your programmer doesn't list it. What programmer do you have? You canchange the processor to 12F508A or 12F509A and it may work.
I want to thank you for converting this for me. It worked without a niche. It worked for the 12C508A as it did for the 12F508 along with the 12F509. As I mentioned I'm old school hardware/analog but not knowledgeable in the arena of writing or working with code. I've went all over Youtube trying to learn how to use MPLAB just to convert this file. I understand the mechanics of this but not the process of real world putting it into action. Where would be the best place to start if someone wanted to have a decent basic entry level understanding of this stuff? I realize that's a loaded question but I would like to start the process of learning how to take my own ideas and eventually be able to just code simple stuff for simple projects. I have a strong real world hands on electronics background of over 40 years and I'm a decent learner and my math skills are good enough just due to the past work I've did in electronics. As I mentioned I'm retired and the only programming experience I have is working with programming pre built HEX files for open source projects I found online but by no means am I versed in working with code. I'm willing to take a guess and say that if I can grasp even simple projects I will eventually learn enough of this to be slightly dangerous. Once again, thank you sir!
I have uploaded the hex file as .hex and .txt

I would not recommend using that chip. It is one-time programmable. That may be why your programmer doesn't list it. What programmer do you have? You canchange the processor to 12F508A or 12F509A and it may work.

#### jpanhalt

Joined Jan 18, 2008
11,088
I use MPLab 8.92. It may still be available as a legacy.
1) Save the ASM file in a convenient place. I have a folder on my desktop named AAC Junk. That works.
2) Open MPLab. Click on Configure > Select Device and select the device you are using. Be careful to get the exact name or the assembler may complain.

3) Open File>new file, load the asm file, then save as (same thing). That will give you a nice color coded and proper asm file to view.
4) With that file active (dark blue header), click on Project >Quickbuild (no .asm file). I know that's a bit misleading. Be sure your rabbit foot is being rubbed. It will do its thing, and with luck, you will get a successful build.
5) Click on File>Export (default settings are probably OK) and save the hex in the same folder. To view, you can simply click on it or change its extension to .txt and view in a text editor.

Steps 2 and 3 can be done in any order. But you must have the correct chip identified in Configure, or you are likely to get several errors when assembling.

Important: Your code has .inc files. It is not always necessary to point to them, but I do. Go to the View>Project tab and check the tree for what project files are there. Right click "header files">add files and navigate to where the .inc files are for your installation. They are in the same folder as MPASM on whatever drive you installed it. Open/add it to that tree. The .inc files contain all sort of "defines." If you get errors to the effect that something has been used that is not defined, you probably need to add the .inc file.

BTW, are you the guy on YT doing wood gasification? Interesting.

#### Flash001USA

Joined Nov 27, 2020
15
I use MPLab 8.92. It may still be available as a legacy.
1) Save the ASM file in a convenient place. I have a folder on my desktop named AAC Junk. That works.
2) Open MPLab. Click on Configure > Select Device and select the device you are using. Be careful to get the exact name or the assembler may complain.
View attachment 223528
3) Open File>new file, load the asm file, then save as (same thing). That will give you a nice color coded and proper asm file to view.
4) With that file active (dark blue header), click on Project >Quickbuild (no .asm file). I know that's a bit misleading. Be sure your rabbit foot is being rubbed. It will do its thing, and with luck, you will get a successful build.
5) Click on File>Export (default settings are probably OK) and save the hex in the same folder. To view, you can simply click on it or change its extension to .txt and view in a text editor.

Steps 2 and 3 can be done in any order. But you must have the correct chip identified in Configure, or you are likely to get several errors when assembling.

Important: Your code has .inc files. It is not always necessary to point to them, but I do. Go to the View>Project tab and check the tree for what project files are there. Right click "header files">add files and navigate to where the .inc files are for your installation. They are in the same folder as MPASM on whatever drive you installed it. Open/add it to that tree. The .inc files contain all sort of "defines." If you get errors to the effect that something has been used that is not defined, you probably need to add the .inc file.

BTW, are you the guy on YT doing wood gasification? Interesting.
I'm LAMO! Yeah I'm that guy. I wasn't expecting that question! I recently designed an open source automation system for the gasifier all in the analog world. I would have loved to had the programming skills and knowledge for that build. I have no doubt it would have made the design much simpler. It's projects like that where learning even the basics of this stuff would be a big help.

#### jpanhalt

Joined Jan 18, 2008
11,088
I thought your YT was well done. I knew about "wood gas" before and just hadn't thought about it much. My home is in the middle of an ash forest. Since the emerald ash borer plight, I have had to just burn many tons of wood.

Glad that code worked for you.

John

xox

#### Flash001USA

Joined Nov 27, 2020
15
I thought your YT was well done. I knew about "wood gas" before and just hadn't thought about it much. My home is in the middle of an ash forest. Since the emerald ash borer plight, I have had to just burn many tons of wood.

Glad that code worked for you.

John
Yes sir the code worked like a charm and I cannot thank you enough for doing that for me. Did you use MPLAB for this project? I know that you mentioned using it. I really want to start learning some basic stuff on being able to eventually write simple programs even if it's just to make a LED blink on and off. In other words, a starting point to get a basic grasp on working with programmable ic's past just going and downloading someone's open source hobby build and copying that to a ic but I'm not sure where a good starting point is? I'm sure the code has it's own set of parameters and rules and then there are the ic's themselves that you have to know their function abilities and limitations but I figured if I started with basic PIC ic projects this would be a starting point. Hell, I self taught myself HTML and actually took that a long way on my own and I'm sure there has to be some pre built projects out there that will explain the functions of the code and even allow you to change basic parameters as a way of learning this process. I don't have a need to learn to be a master code writer/programmer because I don't plan on doing this professionally for a living but if I can find a starting point that won't be totally over my head that would be great. If you have any ideas or other sites for me to check out or throw my way would be appreciated. Thanks.

#### jpanhalt

Joined Jan 18, 2008
11,088
Yes, I use MPLab 8.92 (ASM v. 5.49). It is called a whole "tool suite." 8.92 is no longer supported, but those who write Assembly use to prefer it to the early version of MPLabX (ASM v.5.77 or so). If you use chips from the last couple of years, you have no choice but to use the later software.

I don't have the latter program even installed as I use an older series of chips (PIC16F1xxx) that are known as enhanced midrange. The chips you are using are baseline. They have a slightly fewer instructions, and they do not have interrupts. The 12F6xx and 12F1xxx are midrange and enhanced midrange respectively . They have interrupts. The chips are often identified by their "core" size. Yours are 12-bit, midrange are 14-bit, and the PIC18F chips are 16-bit. The core size affects programming and memory access. All of the chips I have mentioned are 8-bit devices and in general, the memory registers are just 8-bit.

I started with the 12F508/509 series and quickly migrated to the 12F6xx and later devices. The only advantage I see to baseline chips is the set-up is simpler as there are not as many options to chose. Countless tutorials on the web for programming; although, Assembly is not very popular today. In the early part of this century, it was more common.

Joined Jul 18, 2013
25,001
I don't think the original full user guide manuals are still available for the MPLAB-IDE but if you punch in a search on the Microchip web site using the original part No's, you do get some helpful publications for using the older MPLAB-IDE.
Search Using DS33014 & DS51519, the latter has some of the older manual at the end.
Max.

#### Flash001USA

Joined Nov 27, 2020
15
Yes, I use MPLab 8.92 (ASM v. 5.49). It is called a whole "tool suite." 8.92 is no longer supported, but those who write Assembly use to prefer it to the early version of MPLabX (ASM v.5.77 or so). If you use chips from the last couple of years, you have no choice but to use the later software.

I don't have the latter program even installed as I use an older series of chips (PIC16F1xxx) that are known as enhanced midrange. The chips you are using are baseline. They have a slightly fewer instructions, and they do not have interrupts. The 12F6xx and 12F1xxx are midrange and enhanced midrange respectively . They have interrupts. The chips are often identified by their "core" size. Yours are 12-bit, midrange are 14-bit, and the PIC18F chips are 16-bit. The core size affects programming and memory access. All of the chips I have mentioned are 8-bit devices and in general, the memory registers are just 8-bit.

I started with the 12F508/509 series and quickly migrated to the 12F6xx and later devices. The only advantage I see to baseline chips is the set-up is simpler as there are not as many options to chose. Countless tutorials on the web for programming; although, Assembly is not very popular today. In the early part of this century, it was more common.
John let me ask you a question: I just figured out that this circuit times out after 5 minutes of inactivity. I figured this out a few hours ago and at first I thought I was losing my mind till I timed it at which point it led me to the asm file where I thumbed through it and seen what appeared to be a line displaying a timeout after 5 minutes of inactivity meaning that it would shut down until the switches were toggled. I pasted that part of the asm file below. The timeout is listed in two places. Can changing what these lines have typed in them tell it to always stay on and if not, can the time be changed to tell the program to stay on for hours instead of minutes? I placed a "<----------" next to the two lines I found discussing time. I really did NOT want to come here and bother you with this again. Also I have MPLAB ver 8.10 and it looks close to what you are running and I was working with it using your notes but I still had issues trying to convert the file over so it may be the version is slightly different that what you are using.

Code:
;**************************************************************************
;
; Specification
;
;**************************************************************************

; power-up self-test - all LEDs flash twice
; double beep then self-calibrates

; re-calibrates every 5s or less

; tone frequency = ~500Hz - ~4kHz

; button1 decreases range by an octave
; button2 increases range by an octave
; both buttons toggles slide/discrete mode

; sleeps after 5 minutes of inactivity, either button to wake <----------

;**************************************************************************
;                                                                         *
; Port assignments                                                        *
;                                                                         *
;**************************************************************************

GPIO_IN        equ  b'011111'      ; GPIO IN status
GPIO_OUT       equ  b'011100'      ; GPIO OUT status

SPEAKER_PORT   equ  GPIO           ; speaker port
SPEAKER1       equ  4              ; speaker output1
SPEAKER2       equ  5              ; speaker output2

SPEAKER_ON     equ  GPIO_OUT&~(1<<SPEAKER1)
SPEAKER_OFF    equ  GPIO_OUT|(1<<SPEAKER1)

BUTTON_PORT    equ  GPIO           ; button port
BUTTON1        equ  1              ; button1
BUTTON2        equ  0              ; button2

LED_PORT       equ  GPIO           ; LED port
LED1           equ  1              ; LED #4
LED2           equ  4+1            ; LED #3
LED3           equ  0              ; LED #2
LED4           equ  4+0            ; LED #1
MUX            equ  5              ; LED multiplexer

;**************************************************************************
;                                                                         *
; Constants and timings                                                   *
;                                                                         *
;**************************************************************************

CLOCK     equ  d'4000000'          ; processor clock frequency in Hz

SAMPLE1   equ  d'10'               ; slide sample period in ms
SAMPLE2   equ  d'125'              ; discrete sample period in ms

SLIDE_THRESHOLD     equ  d'6'
SLIDE_UPPER         equ  d'250'
SLIDE_LOWER         equ  d'50'

RECALIBRATE    equ  d'5000'        ; recalibration time in ms

BEEP_PITCH     equ  d'75'          ; beep pitch
BEEP_PERIOD    equ  d'250'         ; beep period

TIMEOUT   equ  d'300'*d'100'       ; sleep timeout period in 1/100s <----------

This was also near the end of the file

;--------------------------------------------------------------------------
; power down
;--------------------------------------------------------------------------

routine power_down

tris GPIO
movwf GPIO
nop
movfw GPIO

sleep                         ; standby mode <----------
Mod edit: code tags - JohnInTX

Last edited by a moderator:

#### JohnInTX

Joined Jun 26, 2012
4,654
I don't think the original full user guide manuals are still available for the MPLAB-IDE but if you punch in a search on the Microchip web site using the original part No's, you do get some helpful publications for using the older MPLAB-IDE.
Search Using DS33014 & DS51519, the latter has some of the older manual at the end.
Max.
Here's a manual for MPLAB 8.x and MPASM that went with it. Also an old quick start guide from MPLAB 6.x and Compiled Tips 'n Tricks.

Have fun!

#### Attachments

• 4.1 MB Views: 4
• 3.1 MB Views: 4
• 1 MB Views: 6
• 4.4 MB Views: 5
Last edited: