Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help with assembly for pic18 microcontroller

Status
Not open for further replies.

me1234

Newbie level 3
Newbie level 3
Joined
Dec 8, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,306
; assignment.asm
title"assignment.asm"
list p=18f452, f=inhx32
#include<p18f452.inc>

delaycnt equ 0x04
org 0x00
CLRF PORTA; initalizing port A by clearing output
CLRF PORTC; initalizing port C by clearing output
goto start


start MOVLW b'00000001' ;move literal value 1 to working register
MOVWF TRISA ;set RA <0> as input and rest as output
MOVLW b'11111100' ;move literal value 3 to working register
MOVWF TRISC ;set RC <1:0> as input and rest as output

loop BCF PORTA,0
BCF PORTC,0
BCF PORTC,0
call delay1

BSF PORTA,0
call delay2

delay1 movlw d'34' ;loop 50 micro seconds
movwf delaycnt

delayloop1 nop
nop
nop
nop
decfsz delaycnt, f
goto delayloop1
nop
nop
nop
nop
nop
nop
return
end


delay2 movlw d'70' ;loop 100 micro seconds
movwf delaycnt

delayloop2 nop
nop
nop
nop
decfsz delaycnt, f
goto delayloop2
nop
nop
nop
nop
return
end

IM GETTING AN ERROR SAYING DELAY2 HAS NOT BEEN DEFINED BUT I DNT UNDERSTAND WHY? COULD SOMEONE PLEASE HELP ME OUT?
ANOTHER STRANGE THING THAT HAPPENS IS THAT IF I DEFINE DELAY2 BEFORE DELAY1, THEN IT SAYS DELAY1 HAS NOT BEEN DEIFNED!!
HELP WOULD BE APPRECIATED!!
THANK YOU IN ADVANCE!!
 

MOVLW b'11111100' ;move literal value 3 to working register
MOVWF TRISC ;set RC <1:0> as input and rest as output

is wrong, It should be

MOVLW b'00000011' ;move literal value 3 to working register
MOVWF TRISC ;set RC <1:0> as input and rest as output

Try this code

Code:
;assignment.asm
title"assignment.asm"
list p=18f452, f=inhx32
#include<p18f452.inc>

delaycnt	equ 0x04
org 0x00
CLRF PORTA; initalizing port A by clearing output
CLRF PORTC; initalizing port C by clearing output
goto start


start:
MOVLW b'00000001' ;move literal value 1 to working register
MOVWF TRISA ;set RA <0> as input and rest as output
MOVLW b'11111100' ;move literal value 3 to working register
MOVWF TRISC ;set RC <1:0> as input and rest as output

loop	 BCF PORTA,0
BCF PORTC,0
BCF PORTC,0
call delay1

BSF PORTA,0
call delay2

delay1:
movlw d'34' ;loop 50 micro seconds
movwf delaycnt

delayloop1:
nop
nop
nop
nop
decfsz delaycnt, f
goto delayloop1
nop
nop
nop
nop
nop
nop
return 
end	


delay2:
movlw d'70';loop 100 micro seconds
movwf delaycnt

delayloop2:
nop
nop
nop
nop
decfsz delaycnt, f
goto delayloop2
nop
nop
nop
nop
return 
end
 
Last edited:

Hi,

As what Jayanth has said plus a couple of other things.

PortA defaults to Analogue Inputs at power on, so you must change them to digital ports - ADCON1

The reason you have a problem with your second delay is the use of the 'end' instruction.
It denotes the end of the whole program code, you have used one after each delay, so its just ignoring delay2.

After your 'call delay2' that should be the end of your program loop, but there is nothing there to stop it going into the dealy1 routine.
It needs to be directed back to your loop.

You need to specify what speed oscillator you are using, I assume from your delays its 20mhz.

You need to specify this in you code by means of the Config statements.
I have added the correct one for 20mhz and a few other essential statements


Your code runs ok, if you use the Mplab, Debugger, 'Sim'ulator you can use its Stopwatch with the BreakPoints to check your timings.



Code:
	; assignment.asm
	title"assignment.asm"
	list p=18f452, f=inhx32
	#include<p18f452.inc>

	
	CONFIG WDT=OFF					; Disable watchdog timer
	CONFIG DEBUG = OFF				; Disable Debug Mode
	CONFIG LVP = OFF				; Disable low voltage programming
	CONFIG OSC=HS					; for 20mhz


	
delaycnt equ 0x04


	org 0x00
	goto start
	
	
start
	movlw	0x07		; set ports to digital from the power on default of analogue
	movwf	ADCON1
	CLRF PORTA			; initalizing port A by clearing output
	CLRF PORTC			; initalizing port C by clearing output
	MOVLW b'00000001'   ;move literal value 1 to working register
	MOVWF TRISA 		;set RA <0> as input and rest as output
	MOVLW b'00000011' 	;move literal value 3 to working register
	MOVWF TRISC 		;set RC <1:0> as input and rest as output
	
loop BCF PORTA,0
	BCF PORTC,0
	BCF PORTC,0
	call delay1
	
	BSF PORTA,0
	call delay2

	goto	loop
	
delay1 movlw d'34' ;loop 50 micro seconds
	movwf delaycnt
	
delayloop1 nop
	nop
	nop
	nop
	decfsz delaycnt, f
	goto delayloop1
	nop
	nop
	nop
	nop
	nop
	nop
	return
	
	
	
delay2 movlw d'70' ;loop 100 micro seconds
	movwf delaycnt
	
delayloop2 nop
	nop
	nop
	nop
	decfsz delaycnt, f
	goto delayloop2
	nop
	nop
	nop
	nop
	return
	end
 

Attachments

  • ScreenShot002.jpg
    ScreenShot002.jpg
    94 KB · Views: 65

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top