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.

Error in MPASM

Status
Not open for further replies.
wmmullaney said:
futz, there is no "Folder Options" in my "Tools" menu, Nigel, I did not save it with that extension, it appeared everywhere to be BLINK.ASM

EDIT: Oh, I found it in the View menu.
I was assuming Windows XP. Maybe you're running Win98?
 
Code:
LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	__config 0x3D18			;sets the configuration settings 
					;(oscillator type etc.)

	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
					;this is where the program starts running	
	movlw	0x07
	movwf	CMCON
;*****Set up the Constants**** 

STATUS         equ       03h                 ;Address of the STATUS register
TRISA            equ       85h                 ;Address of the tristate register for port A
PORTA           equ       05h                 ;Address of Port A
COUNT1         equ       08h                 ;First counter for our delay loops
COUNT2         equ       09h                 ;Second counter for our delay loops 

;****Set up the port**** 

                        bsf                  STATUS,5       ;Switch to Bank 1
                        movlw              00h                ;Set the Port A pins
                        movwf              TRISA             ;to output.
                        bcf                   STATUS,5       ;Switch back to Bank 0 

;****Turn the LED on**** 

Start               movlw               02h                   ;Turn the LED on by first putting 
                      movwf               PORTA            ;it into the w register and then                                                                            ;on the port 

;****Start of the delay loop 1**** 

Loop1          decfsz             COUNT1,1       ;Subtract 1 from 255
                  goto                Loop1            ;If COUNT is zero, carry on.
                  decfsz             COUNT2,1       ;Subtract 1 from 255
                  goto                Loop1            ;Go back to the start of our loop.                                                             ;This delay counts down from                                                                           ;255 to zero, 255 times

;****Delay finished, now turn the LED off**** 

                    movlw              00h              ;Turn the LED off by first putting
                    movwf              PORTA          ;it into the w register and then on                                                               ;the port 

;****Add another delay**** 

Loop2        decfsz             COUNT1,1           ;This second loop keeps the
                goto                Loop2                ;LED turned off long enough for 
                decfsz             COUNT2,1           ;us to see it turned off
                goto                Loop2                ; 

;****Now go back to the start of the program

                   goto                 Start               ;go back to Start and turn LED                                                                 ;on again 

;****End of the program**** 

end               ;Needed by some compilers, 
;and also just in case we miss                                ;the goto instruction.


Isn't a resistor needed in this schematic?
 

Attachments

  • pic_connection.gif
    pic_connection.gif
    12.9 KB · Views: 154
Last edited:
Just cleaned it up a little.

Code:
LIST    p=16F628                ; tell assembler what chip we are using
        include "P16F628.inc"   ; include the defaults for the chip
        __config        0x3D18  ; internal OSC, WDT off
        org     0x000           ; reset vector
        movlw   0x07
        movwf   CMCON
;*****Set up the Variables **** 
COUNT1  equ     20h             ; First counter for our delay loops
COUNT2  equ     21h             ; Second counter for our delay loops 
;****Set up the port**** 
        bsf     STATUS,RP0      ;Bank 1
        clrf    TRISA           ; PORTA all outputs.
        bcf     STATUS,RP0      ;Bank 0 
;****Turn the LED on**** 
Start   bsf     PORTA.1         ; RA1 = 1 (LED on)
;****Start of the delay loop 1**** 
Loop1   decfsz  COUNT1,f        ; subtract 1 from 255
        goto    Loop1          ; count1 > zero, repeat
        decfsz  COUNT2,f        ;Subtract 1 from 255
        goto    Loop1           ;Go back to the start of our loop.                                                                                         
;****Delay finished, now turn the LED off****     
    bcf     PORTA.1         ; RA1 = 0 (LED off)                                                   
;****Add another delay**** 
Loop2    decfsz  COUNT1,f        ;This second loop keeps the
        goto    Loop2           ;LED turned off long enough for 
        decfsz  COUNT2,f        ;us to see it turned off
        goto    Loop2           ; 
        goto    Start           ;go back to Start and turn LED  
        end
Ok I've yet to get rid of tabs in MPLAB, makes this look like a mess
 
Last edited:
blueroomelectronics said:
Ok I've yet to get rid of tabs in MPLAB, makes this look like a mess
I prefer tabs over spaces (faster editing cursor movement), but MPLAB seems hard coded to use 4 space tabs (at least I haven't found the settings for it yet). Since it uses 4 space tabs you have to use two almost everywhere.

This forum's code tag assumes 8 space tabs. To make your code look good you have to delete one of every pair of tabs in your code. Tis a pain in the rear.

EDIT: Found it. Go to Edit/Properties/'ASM' File Types. At the bottom you can set your tab size or switch to spaces.

Testing 8 space tabs... Oh, dat looks bootiful! :D No editing required. Just copy/paste into code tags.
Code:
	list	p=16F886
	include	<p16F886.inc>
	__CONFIG	_CONFIG1, _DEBUG_ON & _WDT_OFF & _LVP_OFF & _INTOSCIO
;	errorlevel	-302,-305       

	cblock	0x20
		d1,d2,d3
	endc

	org     0
init
	banksel	OSCCON
	movlw	b'01110001'
	movwf	OSCCON
	banksel	ANSEL
	clrf	ANSEL
	banksel	TRISA
	clrf	TRISA
	clrf	TRISB 
	clrf	TRISC
	clrf	PORTA
	clrf	PORTB
	clrf	PORTC
	bcf	STATUS, RP0

main    bsf	PORTA,5
	call	delay
	bcf	PORTA,5
	call	delay		
	goto	main

delay	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
delay_0	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay_0
	return

        end
 
Last edited:
wmmullaney said:
Doesn't the line "PORTA equ 05h" need to be added?
If you have the line, 'include "P16F628a.inc"' at the top of your code you already have all the proper equates included. Navigate to 'Program Files/Microchip/MPASM Suite' and open P16F628a.inc and have a look. Get in the habit of using those equate symbols in your code instead of the hex addresses. Makes things so much more readable and easily understood.

There's an include file there for every PIC. Use the proper one for whichever PIC you're using.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top