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.

Newbie: Can't flash LED on 18F1320

Status
Not open for further replies.

jjd

New Member
Hello, I'm writing first time code assembly.

18F1320 trying to flash LED program hangs after movfw TRISA. Delay works fine, but won't go to the loop.

Code:
	#include		<p18F1320.inc>


 ;code protect disabled
 	CONFIG     CP0=OFF
 ;Oscillator switch enabled, RC oscillator with OSC1 as I/O pin.
 	CONFIG     OSC=INTIO1
;internal oscillator 
	CONFIG	WDT=OFF
	CONFIG LVP=OFF



		cblock 	100h 		;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc

	

  
	movlw 	0b01100010    ;4mhz
	movwf 	OSCCON 


main

	movlw	0b11000000
	movwf	LATA
	movwf	TRISA

   ; (Hangs right here...)

	
Loop	
	movlw	0b00000001
	movwf	PORTA			;set bit 0 on
	
	call	Delay			;this waits for a while!
	movlw	0b00000000
	movwf	PORTA
		
	call	Delay
	goto	Loop			;go back and do it again




Delay
	movlw	d'1'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	d'1'
	movwf	counta
	movlw	d'1'
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	run

	end
 
Read the data sheet

Code:
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
CLRF LATA ; Alternate method
; to clear output
; data latches
MOVLW 0x7F ; Configure A/D
MOVWF ADCON1 ; for digital inputs
MOVLW 0xD0 ; Value used to
; initialize data
; direction
MOVWF TRISA ; Set RA<3:0> as outputs
; RA<7:4> as inputs

And start with one of these

Code:
;******************************************************************************
;   This file is a basic template for assembly code for a PIC18F1320. Copy    *
;   this file into your project directory and modify or add to it as needed.  *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on the         *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the PIC18F1220/1320 Data Sheet for additional information on the *
;   architecture and instruction set.                                         *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:                                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             * 
;******************************************************************************
;                                                                             *
;    Files Required: P18F1320.INC                                             *
;                                                                             *
;******************************************************************************

	LIST P=18F1320		;directive to define processor
	#include <P18F1320.INC>	;processor specific variable definitions

;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please 
;see the .inc file for futher details on notation.  Below are a few examples.



;   Oscillator Selection:
    CONFIG	OSC = LP             ;LP

;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used. 
; More variables may be needed to store other special function registers used
; in the interrupt routines.

		CBLOCK	0x080
		WREG_TEMP	;variable used for context saving 
		STATUS_TEMP	;variable used for context saving
		BSR_TEMP	;variable used for context saving
		ENDC

		CBLOCK	0x000
		EXAMPLE		;example of a variable in access RAM
		ENDC

;******************************************************************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here

		ORG	0xf00000

		DE	"Test Data",0,1,2,3,4,5

;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

		ORG	0x0000

		goto	Main		;go to start of main code

;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

		ORG	0x0008

		bra	HighInt		;go to high priority interrupt routine

;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

		ORG	0x0018

		movff	STATUS,STATUS_TEMP	;save STATUS register
		movff	WREG,WREG_TEMP		;save working register
		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


		movff	BSR_TEMP,BSR		;restore BSR register
		movff	WREG_TEMP,WREG		;restore working register
		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie

;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.

HighInt:

;	*** high priority interrupt code goes here ***


		retfie	FAST

;******************************************************************************
;Start of main program
; The main program code is placed here.

Main:

;	*** main code goes here ***


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

		END

Read the header of the template
 
Last edited:
Hi,

Incase you haven't been able to get your code working from be80bes comments here's a working example.
 

Attachments

  • led1320.asm
    2.4 KB · Views: 116
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top