Hello!
I need a asm program for pic18f4523 with blinks led's connected to port b with a delay of 500ms. I am using mpasm.
;******************************************************************************
; This file is a basic template for assembly code for a PIC18F4523. 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 PIC18F2423/2523/4423/4523 Data Sheet for additional *
; information on the architecture and instruction set. *
; *
;******************************************************************************
; *
; Filename: *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
;******************************************************************************
; *
; Files Required: P18F4523.INC *
; *
;******************************************************************************
LIST P=18F4523 ;directive to define processor
#include <P18F4523.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
CONFIG OSC=INTIO67, PWRT=ON, BOREN=OFF, WDT=OFF, MCLRE=ON, LPT1OSC=OFF, PBADEN=OFF
CONFIG LVP=OFF, XINST=OFF, DEBUG=OFF
;******************************************************************************
;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: movlw b'01100010' ; set internal osc to 4 mhz
movwf OSCCON
; *** main code goes here ***
;******************************************************************************
;End of program
END
What is the config for using external osc @ 20 MHz?
[syntax = assembly]
;SUBROUTINE
delay_500ms: ; Delay = 0.5 seconds Clock frequency = 20 MHz
movlw 0x16
movwf d1
movlw 0x74
movwf d2
movlw 0x06
movwf d3
Delay_0
decfsz d1, f
goto dly0
decfsz d2, f
dly0 goto dly1
decfsz d3, f
dly1 goto Delay_0
return
[/syntax]
movlw b'11111111'
movwf PORTD
call delay_500ms
movlw 'b00000000'
movwf PORTD
.......................................
Please explain the below code of yours.
bsf PORTD,0 ; TURN ON PORTD,0
bcf PORTD,0 ; TURN OFF PORTD,0
I've attached my project to view.
[syntax = assembly]
;LIST P=18F4523
#include <P18F4523.INC>
;Configuration bits
;Oscillator selected = EXT 20 MHZ
CONFIG OSC=HS, PWRT=ON, WDT=OFF, MCLRE=ON, LPT1OSC=OFF, PBADEN=OFF
CONFIG LVP=OFF, XINST=OFF, DEBUG=OFF, BOREN=OFF
LEDPORT Equ PORTA ;set constant LEDPORT = 'PORTA'
SWPORT Equ PORTB ;set constant SWPORT = 'PORTA'
LEDTRIS Equ TRISA ;set constant for TRIS register
SWTRIS EQU TRISB
SW1 Equ 0 ;set constants for the switches
SW2 Equ 1
SW3 Equ 2
SW4 Equ 3
LED1 Equ 0 ;and for the LED's
LED2 Equ 1
LED3 Equ 2
LED4 Equ 3
;end of defines
;Variable definitions
CBLOCK 0x000
; variable for the Delay routine.
ENDC
ORG 0x0000 ;Reset vector This code will start executing when a reset occurs.
;goto Main ;go to start of main code
Main
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
movlw b'00000000' ;set PortA 4 inputs, 4 outputs
movwf LEDTRIS
movlw b'00001111' ;set PortA 4 inputs, 4 outputs
movwf SWTRIS
clrf LEDPORT ;set all outputs low
clrf SWPORT
Scan
btfss SWPORT, SW1
call Switch1
btfss SWPORT, SW2
call Switch2
btfss SWPORT, SW3
call Switch3
btfss SWPORT, SW4
call Switch4
goto Scan
goto Main
Switch1 clrf LEDPORT ;turn all LED's off
bsf LEDPORT, LED1 ;turn LED1 on
retlw 0x00
Switch2 clrf LEDPORT ;turn all LED's off
bsf LEDPORT, LED2 ;turn LED2 on
retlw 0x00
Switch3 clrf LEDPORT ;turn all LED's off
bsf LEDPORT, LED3 ;turn LED3 on
retlw 0x00
Switch4 clrf LEDPORT ;turn all LED's off
bsf LEDPORT, LED4 ;turn LED4 on
retlw 0x00
END ;End of program
[/syntax]
simulate with the attached file.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?