Config statement for MPASM for PIC18F65K22

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
treez
Posts: 161
Joined: Sat Dec 27, 2008 8:39 am

Config statement for MPASM for PIC18F65K22

Post by treez » Sun Oct 05, 2014 6:52 am

Hello,
Please can you provide a code snippet showing how to do a config statement for PIC18F65K22, I cannt get it to build.
In fact , please also advise on problems with my code that won't build.....there don't seem to be errors yet the assembler in MPLABX is giving build failed...

Code: Select all

;ACTIVE HIGH IS ASSUMED THROUGHOUT
;TURN OFF ALL PULLUPS
;WHERE IS THE RESET ADDRESS?
 list p=18f65k22       	  ;list directive to define processor
#include <p18f65k22.inc>    ;processor specific definitions
;   config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _CPD_OFF)

temp1     equ	h'20         ;register for setting ch 1 temperature
temp2     equ	h'21         ;register for setting ch 2 temperature
temp3     equ	h'22         ;register for holding ch 3 temperature
tempb     equ	h'23         ;register for holding board temperature
dip8      equ   h'24         ;holds dipswitch settings
ana_8bit  equ   h'25         ;holds ADC reading converted to 8 bit from 12 bit
ana_hi    equ   h'26         ;holds the ADRESH register
ana_lo    equ   h'27         ;holds the ADRESL register
ext_in    equ   h'28         ;holds the external connector inputs

; *** DECLARE MACRO'S ***
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;**** bank switching ****

;*** TURN LEDS ON AND OFF
ON1 macro               ;Turn on chan1
    bsf PORTE,RE1
    endm

OFF1 macro               ;Turn off chan1
    bcf PORTE,RE1
    endm

ON2 macro               ;Turn on chan2
    bsf PORTE,RE0
    endm

OFF2 macro               ;Turn off chan2
    bcf PORTE,RE0
    endm

ON3 macro               ;Turn on chan2
    bsf PORTG,RG0
    endm

OFF3 macro               ;Turn off chan2
    bcf PORTG,RG0
    endm

;****** READ TEMP ******************


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

; ********  Read dipswitchs into dip8 register ********
read_dips   macro
    bsf dip8,0      ;DIPSWITCH 1 = MODE
    btfss   PORTB,RB0
    bcf dip8,0

    bsf dip8,1      ;DIPSWITCH 2, Power bit 0
    btfss   PORTB,RB1
    bcf dip8,1

    bsf dip8,2      ;DIPSWITCH 3, power bit 1
    btfss   PORTB,RB2
    bcf dip8,2

    bsf dip8,3      ;DIPSWITCH 4, polarity of 0-10V
    btfss   PORTB,RB3
    bcf dip8,3

    bsf dip8,4      ;DIPSWITCH 5, Temp threshold = 80c or 90c
    btfss   PORTB,RB4
    bcf dip8,4

    bsf dip8,5      ;DIPSWITCH 6, unused
    btfss   PORTB,RB5
    bcf dip8,5

    bsf dip8,6      ;DIPSWITCH 7, unused
    btfss   PORTC,RC5
    bcf dip8,6

    bsf dip8,7      ;DIPSWITCH 8, fan or no fan
    btfss   PORTE,RE6
    bcf dip8,7
    endm
;-----------------------------------------------


;****** READ EXTERNAL CONNECTOR DIGITAL INPUTS *******
read_ext_conn   macro
    bsf ext_in,0   ;extconn PIN 1, UNUSED
    btfss   PORTD,RD4
    bcf ext_in,0

    bsf ext_in,1   ;extconn PIN 3; RESET
    btfss   PORTD,RD5
    bcf ext_in,1

    bsf ext_in,2   ;extconn PIN 4; CH1_ON/OFF
    btfss   PORTD,RD6
    bcf ext_in,2

    bsf ext_in,3   ;extconn PIN 5; CH2_ON/OFF
    btfss   PORTD,RD7
    bcf ext_in,3

    bsf ext_in,4   ;extconn PIN 6; CH3_ON/OFF
    btfss   PORTC,RC7
    bcf ext_in,4

    bsf ext_in,5   ;extconn PIN 7; UNUSED
    btfss   PORTC,RC6
    bcf ext_in,5

    bsf ext_in,6   ;extconn PIN 8; UNUSED
    btfss   PORTC,RC0
    bcf ext_in,6

    bsf ext_in,7  ;extconn PIN 10; CLEAR
    btfss   PORTC,RC1
    bcf ext_in,7
    endm
; *****************************************

; **** output a tripped signal ****
output_trip macro
    bsf PORTA, RA4
    endm

; *****output a non-tripped signal ****
no_output_trip macro
    bcf PORTA, RA4
    endm

;***** Make ADC reading 8 bit from 12 bit ***********
ana_to_8bit    macro
    movf    ADRESH,w
    movwf   ana_8bit
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

   

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;SET UP THE ADC
setupADC    macro
    movlw   h'00
    movwf   ADCON0  ;channel select, godone, ADON

    movlw   h'10
    movwf   ADCON1  ;vref

    movlw   h'3E
    movwf   ADCON2  ;Right justified, acquisition time
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    org 04

start
    nop
    goto    start
    end

waltr
Support Volunteer
Posts: 2823
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Config statement for MPASM for PIC18F65K22

Post by waltr » Mon Oct 06, 2014 10:23 am

Your config statement is commented out so it is just ignored.
is giving build failed...
What are the build errors???????????????????

treez
Posts: 161
Joined: Sat Dec 27, 2008 8:39 am

Re: Config statement for MPASM for PIC18F65K22

Post by treez » Mon Oct 06, 2014 11:29 am

well ive got the code building now,
but I still don't know how to get it to build with the config statement not commented out...

Code: Select all

; XXX DIPSWITCH POLARITY:- XXX
;DIP 1...ON = EXTERNAL CONNECTOR CONTROL
;DIP 2...ON = LOGIC HIGH
;DIP 3...ON = LOGIC HIGH
;DIP 4...OFF = 10V is for max current
;DIP 5...OFF = 80degC, ON = 90degC
;DIP 6... UNUSED
;DIP 7... UNUSED
;DIP 8...ON = NO FAN FITTED, OFF = FAN FITTED

; XXX  EXTERNAL CONTROL CONNECTOR POLARITY:- XXX
;CLEAR = ACTIVE HIGH
;RESET = ACTIVE HIGH
;CH1...HIGH = ON, LOW = OFF
;CH2...HIGH = ON, LOW = OFF
;CH3...HIGH = ON, LOW = OFF


;Code for 3 channel led driver on the updated 550587 PCB
;REMEMBER RESET ADDRESS
;remember to   set the oscillator
 list p=18f65k22       	  ;list directive to define processor
#include <p18f65k22.inc>    ;processor specific definitions
;   config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _CPD_OFF)


;DEFINE OUTPUTS
#define ch1     LATE,LATE1
#define ch2     LATE,LATE0
#define ch3     LATG,LATG0
#define ind_led LATC,LATC2
#define fan_con LATE,LATE2
#define trip    LATA,LATA4

;DEFINE INPUTS FROM DIPSWITCH
;Note that the new board has pullups on the dipswitch,
;whereas 550587 PCB had pull downs, thus logic is reversed.
#define mode        dip8,0  ;low = external connector sets power via 0-10V
#define current_LSB dip8,1  ;00 -> 3.52A, 01 -> 2.64A, 10 -> 1.76A, 11 -> OFF
#define current_MSB dip8,2
#define polarity    dip8,3  ;high = 10V gives max current
#define T80_T90     dip8,4  ;high = 80degC, low=90degC
#define fan_fitted  dip8,8  ;high = fan fitted, low = no fan fitted

;DEFINE INPUTS FROM EXTERNAL CONENCTOR
#define re_set  ext_in,1
#define ch1_ext ext_in,2
#define ch2_ext ext_in,3
#define ch3_ext ext_in,4
#define clear   ext_in,7

temp1     equ	0x20         ;register for setting ch 1 temperature
temp2     equ	0x21         ;register for setting ch 2 temperature
temp3     equ	0x22         ;register for holding ch 3 temperature
tempb     equ	0x23         ;register for holding board temperature
dip8      equ   0x24         ;holds dipswitch settings
ana_8bit  equ   0x25         ;holds ADC reading converted to 8 bit from 12 bit
ana_hi    equ   0x26         ;holds the ADRESH register
ana_lo    equ   0x27         ;holds the ADRESL register
ext_in    equ   0x28         ;holds the external connector inputs
del1    equ     0x29         ;Delay register
del2    equ     0x2A         ;Delay register

; *** DECLARE MACRO'S ***
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

;**** bank switching ****

;*** TURN LEDS ON AND OFF
ON1 macro               ;Turn on chan1
    bsf LATE,LATE1
    endm

OFF1 macro               ;Turn off chan1
    bcf LATE,LATE1
    endm

ON2 macro               ;Turn on chan2
    bsf LATE,LATE0
    endm

OFF2 macro               ;Turn off chan2
    bcf LATE,LATE0
    endm

ON3 macro               ;Turn on chan2
    bsf LATG,LATG0
    endm

OFF3 macro               ;Turn off chan2
    bcf LATG,LATG0
    endm

;****** READ TEMP ******************


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

; ********  Read dipswitchs into dip8 register ********
;Remember that the new PCB has pullups, wheras 550587 PCB had pull downs
;..thus logic in the program is reversed
read_dips   macro
    bsf dip8,0      ;DIPSWITCH 1 = MODE
    btfss   PORTB,RB0
    bcf dip8,0

    bsf dip8,1      ;DIPSWITCH 2, Power bit 0
    btfss   PORTB,RB1
    bcf dip8,1

    bsf dip8,2      ;DIPSWITCH 3, power bit 1
    btfss   PORTB,RB2
    bcf dip8,2

    bsf dip8,3      ;DIPSWITCH 4, polarity of 0-10V
    btfss   PORTB,RB3
    bcf dip8,3

    bsf dip8,4      ;DIPSWITCH 5, Temp threshold = 80c or 90c
    btfss   PORTB,RB4
    bcf dip8,4

    bsf dip8,5      ;DIPSWITCH 6, unused
    btfss   PORTB,RB5
    bcf dip8,5

    bsf dip8,6      ;DIPSWITCH 7, unused
    btfss   PORTC,RC5
    bcf dip8,6

    bsf dip8,7      ;DIPSWITCH 8, fan or no fan
    btfss   PORTE,RE6
    bcf dip8,7
    endm
;-----------------------------------------------


;****** READ EXTERNAL CONNECTOR DIGITAL INPUTS *******
read_ext_conn   macro
    bsf ext_in,0   ;extconn PIN 1, UNUSED
    btfss   PORTD,RD4
    bcf ext_in,0

    bsf ext_in,1   ;extconn PIN 3; RESET
    btfss   PORTD,RD5
    bcf ext_in,1

    bsf ext_in,2   ;extconn PIN 4; CH1_ON/OFF
    btfss   PORTD,RD6
    bcf ext_in,2

    bsf ext_in,3   ;extconn PIN 5; CH2_ON/OFF
    btfss   PORTD,RD7
    bcf ext_in,3

    bsf ext_in,4   ;extconn PIN 6; CH3_ON/OFF
    btfss   PORTC,RC7
    bcf ext_in,4

    bsf ext_in,5   ;extconn PIN 7; UNUSED
    btfss   PORTC,RC6
    bcf ext_in,5

    bsf ext_in,6   ;extconn PIN 8; UNUSED
    btfss   PORTC,RC0
    bcf ext_in,6

    bsf ext_in,7  ;extconn PIN 10; CLEAR
    btfss   PORTC,RC1
    bcf ext_in,7
    endm
; *****************************************

; **** output a tripped signal ****
output_trip macro
    bsf LATA, LATA4
    endm

; *****output a non-tripped signal ****
no_output_trip macro
    bcf LATA, LATA4
    endm

;***** Make ADC reading 8 bit from 12 bit ***********
ana_to_8bit    macro
    movf    ADRESH,w
    movwf   ana_8bit
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;SET UP THE ADC
setupADC    macro
    movlw   0x00
    movwf   ADCON0  ;channel select, godone, ADON

    movlw   0x10
    movwf   ADCON1  ;vref

    movlw   0x3E
    movwf   ADCON2  ;Right justified, acquisition time
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

; ************ Define analog pins ***********8
ana_pins    macro
    movlw   0xFC    ;
    movwf  ANCON0
    movlw   0x0F    ;
    movwf  ANCON1
    movlw   0x00    ;
    movwf   ANCON2
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Disable the comparators
comparator_off    macro
    movlw   0x00
    movwf   CM1CON
    movlw   0x00
    movwf   CM2CON
    movlw   0x00
    movwf   CM3CON
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Disable interrupts
no_interrupts   macro
    clrf    INTCON
    movlw   0x80
    movwf   INTCON2
    clrf    INTCON3
    clrf        PIE1
    clrf        PIE2
    clrf        PIE3
    clrf        PIE4
    clrf        PIE5
    clrf        PIE6
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

; Disable pullups
no_pullups  macro
    clrf    PADCFG1
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; disable open drain outputs
no_opendrain    macro
    clrf    ODCON1
    clrf    ODCON2
    clrf    ODCON3
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX


;xxxxxxxxxxxxxxxxxxxxxxx
;set up ports as inputs or outputs
setup_ports    macro
    movlw   0x2C
    movwf   TRISA
    movlw   0x3F
    movwf   TRISB
    movlw   0xE3
    movwf   TRISC
    movlw   0xF0
    movwf   TRISD
    movlw   0x40
    movwf   TRISE
    movlw   0xFE
    movwf   TRISF
    movlw   0x24
    movwf   TRISG
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXX

;XXXXXXXXXXXXXXXXXXXXXXXXXX
;Make all NC pins low (they are already made to outputs)
;They are outputs for noise immunity reasons
NC_pins_low macro
    bcf LATA,LATA0
    bcf LATA,LATA1
    bcf LATA,LATA6
    bcf LATA,LATA7

    bcf LATB,LATB6
    bcf LATB,LATB7

    bcf LATD,LATD0
    bcf LATD,LATD1
    bcf LATD,LATD2
    bcf LATD,LATD3

    bcf LATE,LATE3
    bcf LATE,LATE4
    bcf LATE,LATE5
    bcf LATE,LATE7

;    bcf PORTF,RF0
    endm

;DEFINES TO NAME OUTPUTS
;INITIALISE OUTPUTS THAT ARE CONNECTED
;defines for dip8 bits and ext_con bits


    org 0x04

start
;SETUP JOBS
    setup_ports
    no_pullups
    no_opendrain
    NC_pins_low
    ana_pins
    comparator_off
    setupADC
    no_interrupts

here
;Turn LEDs off
    OFF1
    OFF2
    OFF3
    goto    here


delay_ms
    movlw   0xFF
    movwf   del1
zzz
    movlw   0xFF
    movwf   del2
yyy
    decfsz  del2,f
    goto    yyy
    decfsz  del1,f
    goto    zzz
    retlw   0x00


    end

User avatar
phalanx
Non-SFE Guru
Posts: 1991
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Config statement for MPASM for PIC18F65K22

Post by phalanx » Mon Oct 06, 2014 1:19 pm

In MPLABX, make sure you have MPASM selected for your project
Click: Window -> PIC Memory Views -> Configuration Bits
Enter your configuration settings
Click the Generate Source Code to Output button
Include the generated code in your project

-Bill

Post Reply