Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Back to PIC assembler..

Status
Not open for further replies.

mramos1

Active Member
OK. I spent $300 on junk compilers over the last 3 weeks, and this afternoon said I need to do it in ASM. I downloaded MPLAB, installed it. Wrote the code, that I know will need lots of work (but include it if someone wants to assemble it in their ASM, it will have errors as I can not get past the processor type).. I can not quickbuild it. I did not try their WINASM, I went in the editor, typed my code, do a quick build and error with the processor, which is listed in their pulldown.

I am using the 12f509.. I did not see a .INC file for any 509 chip in Program Files\MPLAbs either.

Do I need to find an older MPLAB program to write this code, or download a .INC for it?

Or anyone have an assembler they like. I wanted to use MPLAB for the debugger, but not locked into it. Here is the code, nasty, but just tring to get it to make a .HEX file, I will clean it up from there.. Also I had the variables as EQU starting at open RAM, but the MPLAB seemed to like that format. Main objective is to get it to make .hex.

Code:
	list p=12f509
	#include p12f509.inc
	CONFIG     WDT=ON, WDTPS=256
	CONFIG     OSCS=ON, OSC=XT

BUZZ 	equ	portB.1			;piezo buzzer pin
LDR		equ	portB.0			;LDR/cap pin

variables	udata
count	res	1			;how many highs when cap is discharging
dcount	res	1			;delay counter
lcount	res	1			;loop counter to read LDR

	org 0
	goto top
	code
top
	movlw	b'00000000'		;set buzzer and LDR as output
	tris	portb	
	bcf		LDR				;ground out LDR/cap
	call delay				;let cap charge
	movlw	b'00000001'		;flip LDR for input
	tris	portb
	clrf	count			;zero counters, count = number of highs from RC, lcount is passes to check
	clrf	lcount
loop
	btfsc	LDR				;if bit is high
	incf	count			; increment count
	decfsz	lcount,f		;decrement loop counter
	goto loop				;if loop counter <> 0 loop	
	btfsc	count,7			;test bit 7 if more than 128 highs
	goto	buzz			;if true go buzz
nap
	sleep					;else sleep wait for WDT
	goto top			
buzz
	clrf	lcount
noise
	bsf		buzz			;set piezo high
	call	delay			;pause
	bcf		buzz			;clr piezo
	call delay				;pause
	decfsc	lcount			;if lcount is <> 0
	gotot	noise			;then more noise
	goto nap				;else to nap

	end	
;
;
;
delay	clrf	dcount
delay1
	decfsz	dcount,f
	goto delay1
	return
 
Last edited:
The MPLAB I have is version 7.01 I quickly found the include file with the name P12F509. I've included mine but had to change the name from .inc to .h
 

Attachments

  • P12F509.h
    3.9 KB · Views: 289
Still no go. I also found there are pic12f509.dev files as well as the .INC files..

I am running 7.31. Can not imagine they would drop the chip as I just bought them :)

Can you paste the code in yours and see if it will assemble it (with lots of errors).. If so I will
go fine that version.
 
Do you know that Micochip have a forum for PIC advice in their web site? They have some very experienced contributors including some who work for Micochip
 
ljcox said:
Do you know that Micochip have a forum for PIC advice in their web site? They have some very experienced contributors including some who work for Micochip

Will go see if I can find it. I have had very good luck here. But it is a good option. Thanks
 
It compiles for me with the following errors,

Code:
Make: The target "C:\MyProjects\PicStuff\Internet Code\MrAmos.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p12F509 "MrAmos.asm" /l"MrAmos.lst" /e"MrAmos.err"
Error[176]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 3 : CONFIG Directive Error:  (processor "12F509" is invalid for CONFIG directive)
Error[176]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 4 : CONFIG Directive Error:  (processor "12F509" is invalid for CONFIG directive)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 6 : Symbol not previously defined (portB.1)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 7 : Symbol not previously defined (portB.0)
Error[149]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 9 : Directive only allowed when generating an object file
Error[149]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 16 : Directive only allowed when generating an object file
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 19 : Symbol not previously defined (portb)
Error[126]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 19 : Argument out of range (0000 not between 0005 and 0009)
Error[128]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 20 : Missing argument(s)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 21 : Symbol not previously defined (delay)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 23 : Symbol not previously defined (portb)
Error[126]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 23 : Argument out of range (0000 not between 0005 and 0009)
Error[128]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 27 : Missing argument(s)
Message[305] C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 28 : Using default destination of 1 (file).
Error[128]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 39 : Missing argument(s)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 40 : Symbol not previously defined (delay)
Error[128]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 41 : Missing argument(s)
Error[113]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 42 : Symbol not previously defined (delay)
Warning[207] C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 43 : Found label after column 1. (decfsc)
Error[122]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 43 : Illegal opcode (lcount)
Warning[207] C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 44 : Found label after column 1. (gotot)
Error[122]   C:\MYPROJECTS\PICSTUFF\INTERNET CODE\MRAMOS.ASM 44 : Illegal opcode (noise)
Skipping link step.  Not all sources built successfully.
BUILD FAILED: Sun Jun 11 11:58:17 2006

I'm on V7.30

Mike.
 
P.S.

There is a template file in C:\Program Files\Microchip\MPASM Suite\Template\Code\f509temp.asm

Mike.
 
Hello

Try this way. It complies 100%

Code:
	LIST
; P12F509.INC  STANDARD HEADER FILE, VERSION 1.00    MICROCHIP TECHNOLOGY, INC.
	NOLIST
        IFNDEF __12F509
	   MESSG "PROCESSOR-HEADER FILE MISMATCH.  VERIFY SELECTED PROCESSOR."
        ENDIF
;==========================================================================
;
;       REGISTER DEFINITIONS
;
;==========================================================================

W                           	EQU     H'0000'
F                            	EQU     H'0001'

;----- REGISTER FILES -----------------------------------------------------

INDF                         	EQU     H'0000'
TMR0                        	EQU     H'0001'
PCL                          	EQU     H'0002'
STATUS		EQU     H'0003'
FSR                          	EQU     H'0004'
OSCCAL                       	EQU     H'0005'
GPIO                         	EQU     H'0006'

;----- STATUS BITS --------------------------------------------------------

GPWUF                        	EQU     H'0007'
PA0                          	EQU     H'0005'
NOT_TO                       	EQU     H'0004'
NOT_PD                       	EQU     H'0003'
Z                            	EQU     H'0002'
DC                           	EQU     H'0001'
C                            	EQU     H'0000'

;----- OPTION BITS --------------------------------------------------------

NOT_GPWU                     	EQU     H'0007'
NOT_GPPU                     	EQU     H'0006'
T0CS                         	EQU     H'0005'
T0SE                         	EQU     H'0004'
PSA                          	EQU     H'0003'
PS2                          	EQU     H'0002'
PS1                          	EQU     H'0001'
PS0                          	EQU     H'0000'

;----- OSCCAL BITS --------------------------------------------------------

CAL6                         	EQU     H'0007'
CAL5                         	EQU     H'0006'
CAL4                         	EQU     H'0005'
CAL3                         	EQU     H'0004'
CAL2                         	EQU     H'0003'
CAL1                         	EQU     H'0002'
CAL0		EQU     H'0001'

;==========================================================================
;
;       RAM DEFINITION
;
;==========================================================================

        __MAXRAM H'3F'

;==========================================================================
;
;       CONFIGURATION BITS
;
;==========================================================================

_MCLRE_ON                    	EQU     H'0FFF'
_MCLRE_OFF                   	EQU     H'0FEF'
_CP_ON                       	EQU     H'0FF7'
_CP_OFF                     	EQU     H'0FFF'
_WDT_ON                   	EQU     H'0FFF'
_WDT_OFF                 	EQU     H'0FFB'
_LP_OSC                   	EQU     H'0FFC'
_XT_OSC                   	EQU     H'0FFD'
_INTRC_OSC             	EQU     H'0FFE'
_EXTRC_OSC            	EQU     H'0FFF'
	LIST
	__CONFIG 	_WDT_ON & _INTRC_OSC & _MCLRE_ON & _CP_OFF
#DEFINE 	BUZZ	GPIO,1
;BUZZ 	EQU	GPIO,1		;PIEZO BUZZER PIN
;LDR	EQU	PORTB.0		;LDR/CAP PIN
#DEFINE	LDR	GPIO,0
;VARIABLES	UDATA
COUNT	EQU	0X0A		;HOW MANY HIGHS WHEN CAP IS DISCHARGING
DCOUNT	EQU	0X08		;DELAY COUNTER
LCOUNT	EQU	0X09		;LOOP COUNTER TO READ LDR
	
TOP	
	
	MOVLW	B'00000000'		;SET BUZZER AND LDR AS OUTPUT
	TRIS	GPIO	
	BCF	LDR		;GROUND OUT LDR/CAP
	CALL 	DELAY		;LET CAP CHARGE
	MOVLW	B'00000001'		;FLIP LDR FOR INPUT
	TRIS	GPIO
	CLRF	COUNT		;ZERO COUNTERS, COUNT = NUMBER OF HIGHS FROM RC, LCOUNT IS PASSES TO CHECK
	CLRF	LCOUNT
LOOP
	BTFSC	LDR		;IF BIT IS HIGH
	INCF	COUNT,F		; INCREMENT COUNT
	DECFSZ	LCOUNT,F		;DECREMENT LOOP COUNTER
	GOTO 	LOOP		;IF LOOP COUNTER <> 0 LOOP	
	BTFSC	COUNT,7		;TEST BIT 7 IF MORE THAN 128 HIGHS
	GOTO	BUZZ1		;IF TRUE GO BUZZ
NAP
	SLEEP			;ELSE SLEEP WAIT FOR WDT
	GOTO 	TOP			
BUZZ1
	CLRF	LCOUNT
NOISE
	BSF	BUZZ		;SET PIEZO HIGH
	CALL	DELAY		;PAUSE
	BCF	BUZZ		;CLR PIEZO
	CALL 	DELAY		;PAUSE
	DECFSZ	LCOUNT,F		;IF LCOUNT IS <> 0
	GOTO	NOISE		;THEN MORE NOISE
	GOTO 	NAP		;ELSE TO NAP

DELAY	CLRF	DCOUNT
DELAY1
	DECFSZ	DCOUNT,F
	GOTO 	DELAY1
	RETLW	.0
	END
 
I am using the 12f509.. I did not see a .INC file for any 509 chip in Program Files\MPLAbs either.

I have MPLAB IDE 7.40 installed and the file P12C509.INC can be found in the "C:\Program Files\Microchip\MPASM Suite" directory.

I think the "CONFIG" directive only works with the PIC18 family. You have to use the older __CONFIG directive.
 
I also worked through the code before it would assemble without error.

Study, study, study (grin).

Kind regards, Mike

Code:
        list p=12f509
        #include p12f509.inc
;
        __config   _MCLRE_OFF & _CP_OFF &_WDT_ON & _IntRC_OSC

#define BUZZ    GPIO,1          ; piezo buzzer pin
#define LDR     GPIO,0          ; LDR/cap pin

        org     h'0007'         ; start of RAM
count   res     1               ; how many highs when cap is discharging
dcount  res     1               ; delay counter
lcount  res     1               ; loop counter to read LDR


        org     h'0000'

        movwf   OSCCAL          ; calibrate INTOSC

top
        movlw   b'00000000'     ; set buzzer and LDR as output
        tris    GPIO            ;
        bcf     LDR             ; ground out LDR/cap
        call    delay           ; let cap charge
        movlw   b'00000001'     ; flip LDR for input
        tris    GPIO            ;
        clrf    count           ; zero counters, count = number of highs from RC, lcount is passes to check
        clrf    lcount          ;
loop
        btfsc   LDR             ; if bit is high
        incf    count,f         ; increment count
        decfsz  lcount,f        ; decrement loop counter
        goto    loop            ; if loop counter <> 0 loop    
        btfsc   count,7         ; test bit 7 if more than 128 highs
        goto    buzz            ; if true go buzz
nap
        sleep                   ; else sleep wait for WDT
        goto    top            
buzz
        clrf    lcount
noise
        bsf     BUZZ            ; set piezo high
        call    delay           ; pause
        bcf     BUZZ            ; clr piezo
        call    delay           ; pause
        decfsz  lcount,f        ; if lcount is <> 0
        goto    noise           ; then more noise
        goto    nap             ; else to nap
;
delay   clrf    dcount
delay1
        decfsz  dcount,f
        goto    delay1
        retlw   0
;
        end
 
Mike K8LH.

I dropped your modified code in, same errors.

MPLAB has a popup box "error in parameter 12F509" and then this.

Code:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p12F509 "hck509.asm" /l"hck509.lst" /e"hck509.err"
Halting build on first failure as requested.
BUILD FAILED: Sun Jun 11 08:58:59 2006

The .err file is empty.

Maybe I will remove MPLAB and reinstall it. Also, I might have an old version from way back (pre 2000) on the machine as well and maybe the path is grabbing it..

Also, the GPIO did not work for pin equates, but I found it would take portb. Why I had them in the code...

Will try csaba's version before I remove it. But something is wacked out. I did try the winasm and got 30 errors, so maybe I will forget the IDE for now.

But thanks to both of you for checking it out. Looks like it is my machine.
 
OK, I un-installed a 2002 version 6.something (in program files\MPLAB IDE) and the 7.30 version (new one). reinstalled, had to reboot. Hate Windows. Now it can not find the build tool from inside the IDE, but beats the error I was getting.

I then went in the microchip directory, ran the winasm (the Nigel way) and assembled with no errors (Mike's version).. Too many Mike's on this forum. hahaha.. AND, it friggin works..... Woohooo........... Dropped the pic in the circuit and WORKING...

Anyway, so I have my start now.. I just need to remove all the crap MPLAB installed, since it is broke, and keep the WINASM..

Thanks guys again.. Would be nice to have the debugger with symbols.

Pommie, I installed 7.3 as well, but it does not work here for some reason. But I installed a couple compilers, and they probably grab .HEX and .ASM or broke something.
 
Last edited:
I've never really liked using absolute addresses for my variables.

Code:
;variables    Udata
Count     Equ    0x0a        ;how Many Highs When Cap Is Discharging
Dcount    Equ    0x08        ;delay Counter
Lcount    Equ    0x09        ;loop Counter To Read Ldr
I do like this method "res" like the old intel DS, why isn't it used more often?

Code:
        org     h'0007'         ; start of RAM
count   res     1               ; how many highs when cap is discharging
dcount  res     1               ; delay counter
lcount  res     1               ; loop counter to read LDR
 
I'm happy to hear you're making progress. Kinda' sounds like your MPLAB is somehow messed up.

Take care. Mike
 
Yea, it is for sure. But the MPWINASM works, and notepad++ so I am good.
I will attach MPLABs another day.

Looks like you can not go sleep sleep sleep to get 6 second delay, but datasheet leads me to believe memory is not touched, so off to fix that now.

But it is so nice to hear it beeps :)

Thanks again

Mike
 
for mramos1

try to write the second line of the programm:

#include <p12f509.inc>


instead of:

#include p12f509.inc


write the two < and > and try again and see
 
try to write the second line of the programm:

#include <p12f509.inc>

instead of:

#include p12f509.inc
write the two < and > and try again and see

hi moanna,

You are about 4 years plus too late...:) thats was June 2006.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top