PIC18f24J10.asm file

Status
Not open for further replies.

charles01

New Member
hi
i have maneged to build a template file for the PIC18F24J10 and i want to add more lines of code (to follow) to this file so it runs as it says in the document AN1076
;******************************************************************************
; This file is a basic template for assembly code for a PIC18F24J10. Copy *
; this file into your project directory and modify or add to it as needed. *
; *
; The PIC18FXXXX architecture allows two interrupt configurations. This *
; template code is written for priority interrupt levels and the IPEN bit *
; in the RCON register must be set to enable priority levels. If IPEN is *
; left in its default zero state, only the interrupt vector at 0x008 will *
; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not *
; be needed. *
; *
; Refer to the MPASM User's Guide for additional information on the *
; features of the assembler. *
; *
; Refer to the PIC18FXXJXX Data Sheet for additional *
; information on the architecture and instruction set. *
; *
;******************************************************************************
; *
; Filename: *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
;******************************************************************************
; *
; Files required: P18F24J10.INC *
; *
;******************************************************************************

LIST P=18F24J10, F=INHX32 ;directive to define processor
#include <P18F24J10.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 FOSC = HS ;HS oscillator



;******************************************************************************
;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.

UDATA

WREG_TEMP RES 1 ;variable in RAM for context saving
STATUS_TEMP RES 1 ;variable in RAM for context saving
BSR_TEMP RES 1 ;variable in RAM for context saving

UDATA_ACS

EXAMPLE RES 1 ;example of a variable in access RAM


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

RESET_VECTOR CODE 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.

HI_INT_VECTOR CODE 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.

LOW_INT_VECTOR CODE 0x0018

bra LowInt ;go to low priority interrupt routine

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


CODE

HighInt:

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


retfie FAST

;******************************************************************************
;Low priority interrupt routine
; The low priority interrupt code is placed here.
; This code can be removed if low priority interrupts are not used.

LowInt:
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

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

Main:

; *** main code goes here ***


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

END
 
and the code i want to add is like this
; File: DMX512RecDemo.asm
; DMX512 Receiver
; This file uses a PIC18F24J10 device to receive DMX-512 data and store it
; into a 512 byte receive buffer.
; For demonstration purposes, a selected data slot is written to the
; CCP module. The CCP module is configured in PWM mode and the received
; data adjusts the duty cycle. If a resistor and LED is connected to the
; PWM output, the received DMX data can be visually observed.

list p=18f24j10 ; define target processor
#include <p18f24j10.inc> ; include processor specific definitions

; Configuration bits setup

CONFIG CCP2MX = ALTERNATE ; assign CCP2 output to pin RB3
CONFIG WDTEN = OFF ; To use ICD2 as a debugger disable Watch Dog Timer
CONFIG STVERN = ON ; Reset on stack overflow/underflow enabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing
; mode disabled (Legacy mode)
CONFIG CP0 = OFF ; Program memory is not code-protected
CONFIG FOSC = ECPLL ; EC oscillator, PLL enabled and under software
; control, CLKO function on OSC2
CONFIG FOSC2 = ON ; Clock selected by FOSC as system clock is enabled
; when OSCCON<1:0> = 00
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Two-Speed Start-up disabled
CONFIG WDTPS = 32768 ; 1:32768

; Constants

#define CHANNEL .510 ; select the receiver slot/channel

; Variables
CBLOCK 0x8
CountH ;16-bit counter
CountL
RxBuffer: .512 ; 512 bytes buffer allocation
ENDC
;******************************************************************************

ORG 0x0
Main
call SetupSerial ; Setup Serial port and buffers
MainLoop
; first loop, synchronizing with the transmitter

WaitBreak
btfsc PIR1,RCIF ; if a byte is received correctly
movf RCREG,W ; discard it
btfss RCSTA,FERR ; else
bra WaitBreak ; continue waiting until a frame error is detected
movf RCREG,W ; read the Receive buffer to clear the error condition
; second loop, waiting for the START code

WaitForStart
btfss PIR1,RCIF ; wait until a byte is correctly received
bra WaitForStart
btfsc RCSTA,FERR
bra WaitForStart
movf RCREG,W

; check for the START code value, if it is not 0, ignore the rest of the frame

andlw 0xff
bnz MainLoop ; ignore the rest of the frame if not zero

; init receive counter and buffer pointer

clrf CountL
clrf CountH
lfsr 0,RxBuffer

; third loop, receiving 512 bytes of data

WaitForData
btfsc RCSTA,FERR ; if a new framing error is detected (error or short frame)
bra RXend ; the rest of the frame is ignored and a new synchronization is
; attempted

btfss PIR1,RCIF ; wait until a byte is correctly received
bra WaitForData ;
movf RCREG,W ;
MoveData
movwf POSTINC0 ; move the received data to the buffer
; (auto-incrementing pointer)

incf CountL,F ; increment 16-bit counter
btfss STATUS,C
bra WaitForData
incf CountH,F
btfss CountH,1 ; check if 512 bytes of data received
bra WaitForData

;******************************************************************************

; when a complete frame is received
; use the selected CHANNEL data to control the CCP2 module duty cycle

RXend
lfsr 0,RxBuffer ; use indirect pointer 0 to address the receiver buffer
GetData
movlw LOW(CHANNEL) ; add the offset for the select channel
addwf FSR0L,F
movlw HIGH(CHANNEL)
addwfc FSR0H,F
movff INDF0,CCPR2L ; retrieve the data and assign MSB to control PWM2
bra MainLoop ; return to main loop

;******************************************************************************
; Setup Serial port and buffers

SetupSerial
; Clear the receive buffer
lfsr 0,RxBuffer
CBloop
clrf POSTINC0 ; clear INDF register then increment pointer
incf CountL,F
btfss STATUS,C
bra CBloop
incf CountH,F
btfss CountH,1
bra CBloop
; Setup EUSART

bsf TRISC,7 ; allow the EUSART RX to control pin RC7
bsf TRISC,6 ; allow the EUSART TX to control pin RC6
movlw 0x04 ; Disable transmission
movwf TXSTA ; enable transmission and CLEAR high baud rate
movlw 0x90
movwf RCSTA ; enable serial port and reception
bsf BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
clrf SPBRGH
movlw .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
movwf SPBRG

; Setup PWM module

movlw 0x0c ; configure CCP2 for PWM mode
movwf CCP2CON

; Timer2 control

movlw 0x04 ; enable Timer2, select a prescale of 1:1
movwf T2CON

; PWM period

movlw 0xFF ; 256 x .25us = 64us period
movwf PR2

; init I/O

movlw b'11110111' ; make pin RB3 (CCP2) output
movwf TRISB
return
END
 
i have added the asm file to the project 18f24j10 and ran the build all function
i got the followin errors and warnings
i dii not change the default asm file which is generated when you run the new project wizard
i am going to put the code which i used on the next post

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\My Project\18F24J10Proj.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F24J10 "C:\Program Files\Microchip\MPASM Suite\Template\Object\18F24J10TMPO.ASM" /l"18F24J10TMPO.lst" /e"18F24J10TMPO.err" /o"18F24J10TMP" /d__DEBUG=1
Error[176] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 47 : CONFIG Directive Error: (setting "STVERN" not found for the processor 18F24J10)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 153 : Found label after column 1. (Main)
Error[116] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 153 : Address label duplicated or different in second pass (Main)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 155 : Found label after column 1. (MainLoop)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 158 : Found label after column 1. (WaitBreak)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 166 : Found label after column 1. (WaitForStart)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 186 : Found label after column 1. (WaitForData)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 194 : Found label after column 1. (MoveData)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 210 : Found label after column 1. (RXend)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 212 : Found label after column 1. (GetData)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 223 : Found label after column 1. (SetupSerial)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 226 : Found label after column 1. (CBloop)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\My Project\18F24J10Proj.mcp' failed.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Wed Feb 03 22:27:46 2010
----------------------------------------------------------------------
BUILD FAILED
 
here is the code
Oscillator Selection:
CONFIG FOSC = HS ;HS oscillator
CONFIG CCP2MX = ALTERNATE ; assign CCP2 output to pin RB3
CONFIG WDTEN = OFF ; To use ICD2 as a debugger disable Watch Dog Timer
CONFIG STVERN = ON ; Reset on stack overflow/underflow enabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing
; mode disabled (Legacy mode)
CONFIG CP0 = OFF ; Program memory is not code-protected
;CONFIG FOSC = ECPLL ; EC oscillator, PLL enabled and under software
; control, CLKO function on OSC2
CONFIG FOSC2 = ON ; Clock selected by FOSC as system clock is enabled
; when OSCCON<1:0> = 00
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Two-Speed Start-up disabled
CONFIG WDTPS = 32768 ; 1:32768

; Constants

#define CHANNEL .510 ; select the receiver slot/channel

; Variables
CBLOCK 0x8
CountH ;16-bit counter
CountL
RxBuffer: .512 ; 512 bytes buffer allocation
ENDC


;******************************************************************************
;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.

UDATA

WREG_TEMP RES 1 ;variable in RAM for context saving
STATUS_TEMP RES 1 ;variable in RAM for context saving
BSR_TEMP RES 1 ;variable in RAM for context saving

UDATA_ACS

EXAMPLE RES 1 ;example of a variable in access RAM


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

RESET_VECTOR CODE 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.

HI_INT_VECTOR CODE 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.

LOW_INT_VECTOR CODE 0x0018

bra LowInt ;go to low priority interrupt routine

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


CODE

HighInt:

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


retfie FAST

;******************************************************************************
;Low priority interrupt routine
; The low priority interrupt code is placed here.
; This code can be removed if low priority interrupts are not used.

LowInt:
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

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

Main:

ORG 0x0
Main
call SetupSerial ; Setup Serial port and buffers
MainLoop
; first loop, synchronizing with the transmitter

WaitBreak
btfsc PIR1,RCIF ; if a byte is received correctly
movf RCREG,W ; discard it
btfss RCSTA,FERR ; else
bra WaitBreak ; continue waiting until a frame error is detected
movf RCREG,W ; read the Receive buffer to clear the error condition
; second loop, waiting for the START code

WaitForStart
btfss PIR1,RCIF ; wait until a byte is correctly received
bra WaitForStart
btfsc RCSTA,FERR
bra WaitForStart
movf RCREG,W

; check for the START code value, if it is not 0, ignore the rest of the frame

andlw 0xff
bnz MainLoop ; ignore the rest of the frame if not zero

; init receive counter and buffer pointer

clrf CountL
clrf CountH
lfsr 0,RxBuffer

; third loop, receiving 512 bytes of data

WaitForData
btfsc RCSTA,FERR ; if a new framing error is detected (error or short frame)
bra RXend ; the rest of the frame is ignored and a new synchronization is
; attempted

btfss PIR1,RCIF ; wait until a byte is correctly received
bra WaitForData ;
movf RCREG,W ;
MoveData
movwf POSTINC0 ; move the received data to the buffer
; (auto-incrementing pointer)

incf CountL,F ; increment 16-bit counter
btfss STATUS,C
bra WaitForData
incf CountH,F
btfss CountH,1 ; check if 512 bytes of data received
bra WaitForData

;******************************************************************************

; when a complete frame is received
; use the selected CHANNEL data to control the CCP2 module duty cycle

RXend
lfsr 0,RxBuffer ; use indirect pointer 0 to address the receiver buffer
GetData
movlw LOW(CHANNEL) ; add the offset for the select channel
addwf FSR0L,F
movlw HIGH(CHANNEL)
addwfc FSR0H,F
movff INDF0,CCPR2L ; retrieve the data and assign MSB to control PWM2
bra MainLoop ; return to main loop

;******************************************************************************
; Setup Serial port and buffers

SetupSerial
; Clear the receive buffer
lfsr 0,RxBuffer
CBloop
clrf POSTINC0 ; clear INDF register then increment pointer
incf CountL,F
btfss STATUS,C
bra CBloop
incf CountH,F
btfss CountH,1
bra CBloop
; Setup EUSART

bsf TRISC,7 ; allow the EUSART RX to control pin RC7
bsf TRISC,6 ; allow the EUSART TX to control pin RC6
movlw 0x04 ; Disable transmission
movwf TXSTA ; enable transmission and CLEAR high baud rate
movlw 0x90
movwf RCSTA ; enable serial port and reception
bsf BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
clrf SPBRGH
movlw .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
movwf SPBRG

; Setup PWM module

movlw 0x0c ; configure CCP2 for PWM mode
movwf CCP2CON

; Timer2 control

movlw 0x04 ; enable Timer2, select a prescale of 1:1
movwf T2CON

; PWM period

movlw 0xFF ; 256 x .25us = 64us period
movwf PR2

; init I/O

movlw b'11110111' ; make pin RB3 (CCP2) output
movwf TRISB
return


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

END
 
It looks as though it doesnt like STVERN config code and it has found more than 1 label for Main.

What is your exact issue / question with this code?

Wilksey
 
after disabling the lines with the error messages, i ran the build all tool and got warnings only but the program giving me the following warnings and erro on LINKEr SETUP

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\My Project\18F24J10TMP".
Clean: Deleted file "C:\My Project\18F24J10TMPO.err".
Clean: Deleted file "C:\My Project\18F24J10TMPO.lst".
Clean: Deleted file "C:\My Project\18F24J10Proj.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F24J10 "C:\Program Files\Microchip\MPASM Suite\Template\Object\18F24J10TMPO.ASM" /l"18F24J10TMPO.lst" /e"18F24J10TMPO.err" /o"18F24J10TMP" /d__DEBUG=1 /c-
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 155 : Found label after column 1. (MAINLOOP)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 158 : Found label after column 1. (WAITBREAK)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 166 : Found label after column 1. (WAITFORSTART)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 186 : Found label after column 1. (WAITFORDATA)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 194 : Found label after column 1. (MOVEDATA)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 210 : Found label after column 1. (RXEND)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 212 : Found label after column 1. (GETDATA)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 223 : Found label after column 1. (SETUPSERIAL)
Warning[207] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\18F24J10TMPO.ASM 226 : Found label after column 1. (CBLOOP)
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" "..\Program Files\Microchip\MPASM Suite\LKR\18f24j10_g.lkr" "18F24J10TMP" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"18F24J10Proj.cof" /M"18F24J10Proj.map" /W
MPLINK 4.35, Linker
Copyright (c) 2009 Microchip Technology Inc.
Error - section 'HI_INT_VECTOR' can not fit the absolute section. Section 'HI_INT_VECTOR' start=0x00000008, length=0x00000002
Errors : 1

Link step failed.
----------------------------------------------------------------------
Debug build of project `C:\My Project\18F24J10Proj.mcp' failed.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Thu Feb 04 09:09:11 2010

is this because i have not yet run the programmer software in which case i intend to use the PicKit 3 programmer

i would like to change my output from RB port to RC (CCP1 and CCP2 + TMR1 or TMR0) as a third oscillator output is this going to be a graet task?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…