Pic 18f45k20

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I just got my PICkit 3 with a PIC 18F45K20 and I am very excited to start.:D

My problem is I haven't been able to configure my __CONFIG word. Before when I used a PIC12 I didn't really have to worry much about what the __CONFIG word said because I had sample code. Basically I am trying to use the PIC as a fast oscillator that sends data out one of the ports. So I would prefer to use the PLL enabled oscillator setting that allows internal oscillations of up to 64 MHz. I am not interested in BOREN,Watchdog timer or the other config options that are used because I don't need them for my application. The line where I have

Rich (BB code):
 list      p=18f45k20
is highlighted red except for 20 so maybe there is also a problem there. Here is the code that won't compile...

Rich (BB code):
list      p=18f45k20         ; list directive to define processor
#include <p18f45k20.inc>        ; processor specific variable definitions

	__CONFIG _FOSC_HSPLL_1H


;******************** INITIALIZATION PROTOCOL **************************

	org     0x000				; BIG BANG
	goto	Initialize			; Initialization call

;Interrupt Vector	
	org 	0x004
	retfie

	org		0x005				; Start of Programm Memory Vector

Initialize

end
 

Markd77

Joined Sep 7, 2009
2,806
Start with this and see how you get on.
From the template:

Rich (BB code):
;****************************************************************************** 
;                                                                             * 
;   This file is a basic code template for code generation on the             * 
;   PIC18F45K20. This file contains the basic code building blocks to build   * 
;   upon.                                                                     * 
;                                                                             * 
;   Refer to the MPASM User's Guide for additional information on features    * 
;   of the assembler.                                                         * 
;                                                                             * 
;   Refer to the respective data sheet for additional information on the      * 
;   instruction set.                                                          * 
;                                                                             * 
;****************************************************************************** 
;                                                                             * 
;    Filename:         xxx.asm                                                * 
;    Date:                                                                    * 
;    File Version:                                                            * 
;    Author:                                                                  * 
;    Company:                                                                 * 
;                                                                             * 
;****************************************************************************** 
;                                                                             * 
;    Files Required: P18F45K20.INC                                            * 
;                                                                             * 
;****************************************************************************** 
;                                                                             * 
;    Notes:                                                                   * 
;                                                                             * 
;****************************************************************************** 
;                                                                             * 
;    Revision History:                                                        * 
;                                                                             * 
;****************************************************************************** 
 
;------------------------------------------------------------------------------ 
; PROCESSOR DECLARATION 
;------------------------------------------------------------------------------ 
 
     LIST      P=PIC18F45K20          ; list directive to define processor 
     #INCLUDE <P18F45K20.INC>         ; processor specific variable definitions 
 
;------------------------------------------------------------------------------ 
; 
; CONFIGURATION WORD SETUP 
; 
; The 'CONFIG' directive is used to embed the configuration word within the  
; .asm file. The lables following the directive are located in the respective  
; .inc file.  See the data sheet for additional information on configuration  
; word settings. 
; 
;------------------------------------------------------------------------------ 
 
     CONFIG FOSC = INTIO7, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF 
     CONFIG BORV = 18, WDTEN = OFF, WDTPS = 1, MCLRE = ON, HFOFST = ON 
     CONFIG LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC, STVREN = OFF 
     CONFIG LVP = OFF,  XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF 
     CONFIG CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF 
     CONFIG WRT2 = OFF, WRT3 = OFF, WRTB = OFF, WRTC = OFF, WRTD = OFF 
     CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF 
     CONFIG EBTRB = OFF 
 
;------------------------------------------------------------------------------ 
; 
; VARIABLE DEFINITIONS 
; 
;------------------------------------------------------------------------------ 
 
    CBLOCK 0x60 ; Sample GPR variable register allocations 
        MYVAR1  ; user variable at address 0x60 
        MYVAR2  ; user variable at address 0x61 
        MYVAR3  ; user variable at address 0x62 
    ENDC 
     
 
 
W_TEMP         EQU        0x000  ; w register for context saving (ACCESS) 
STATUS_TEMP    EQU        0x001  ; status used for context saving  
BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving 
 
;------------------------------------------------------------------------------ 
; EEPROM INITIALIZATION 
; 
; The 18F45K20 has non-volatile EEPROM starting at 0xF00000 
;  
;------------------------------------------------------------------------------ 
 
DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F45K20 
 
    DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3 
 
;------------------------------------------------------------------------------ 
; RESET VECTOR 
;------------------------------------------------------------------------------ 
 
RES_VECT  ORG     0x0000            ; processor reset vector 
          GOTO    START             ; go to beginning of program 
 
;------------------------------------------------------------------------------ 
; HIGH PRIORITY INTERRUPT VECTOR 
;------------------------------------------------------------------------------ 
 
ISRH      ORG     0x0008 
 
          ; Run the High Priority Interrupt Service Routine 
          GOTO    HIGH_ISR              
 
;------------------------------------------------------------------------------ 
; LOW PRIORITY INTERRUPT VECTOR 
;------------------------------------------------------------------------------ 
 
ISRL      ORG     0x0018 
           
          ; Run the High Priority Interrupt Service Routine 
          GOTO    LOW_ISR              
 
;------------------------------------------------------------------------------ 
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE 
;------------------------------------------------------------------------------ 
 
HIGH_ISR   
 
          ; Insert High Priority ISR Here 
 
          RETFIE  FAST 
 
;------------------------------------------------------------------------------ 
; LOW PRIORITY INTERRUPT SERVICE ROUTINE 
;------------------------------------------------------------------------------ 
 
LOW_ISR 
          ; Context Saving for Low ISR 
          MOVWF   W_TEMP              ; save W register 
          MOVFF   STATUS, STATUS_TEMP ; save status register 
          MOVFF   BSR, BSR_TEMP       ; save bankselect register 
 
          ; Insert Low Priority ISR Here 
 
          ; Context Saving for Low ISR 
          MOVFF   BSR_TEMP, BSR       ; restore bankselect register 
          MOVF    W_TEMP, W           ; restore W register 
          MOVFF   STATUS_TEMP, STATUS ; restore status register 
          RETFIE 
 
;------------------------------------------------------------------------------ 
; MAIN PROGRAM 
;------------------------------------------------------------------------------ 
 
START 
 
          ; Insert User Program Here 
 
          GOTO $                      ; loop program counter 
 
          END
 

t06afre

Joined May 11, 2009
5,934
Where did you get that information from? Was it on the datasheet?
The include file for your chip. Is a good start for you as PIC programmer. If you work with MPLAB assembler. You may find the files C:\Program Files\Microchip\MPASM Suite. The config settings will be near the end always. This may also help http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2123&param=en024286
I will also recommend that at least read this document. http://ww1.microchip.com/downloads/en/DeviceDoc/41370C.pdf even if you do plan to do any work in C. As it will provide many hints and tips for a person new to PIC18F series and MPLAB.
 

Markd77

Joined Sep 7, 2009
2,806
They are in a folder like this if you have MPLAB installed.
It would be nice if it was mentioned more prominently in the help files and datasheets because they are very useful.
c:/Program Files/Microchip/MPASM Suite/Template/Code
 

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I am having trouble setting up a simple oscillator. I set my config fosc to be HSPLL and I set my osccon to make my internal clock 64MHz. I just compliment PORTA and I should be getting oscillations on most of the ports except 4 and 8 I believe. I am not getting any oscillations can you see what is wrong. I also cannot set my FSR0H register to a number but I have no trouble setting my FSR0L register. This is my first attempt at writing for a PIC18. Here is the code.

Rich (BB code):
------------------------------------------------------------------------------ 
; PROCESSOR DECLARATION 
;------------------------------------------------------------------------------ 
 
     LIST      P=PIC18F45K20          ; list directive to define processor 
     #INCLUDE <P18F45K20.INC>         ; processor specific variable definitions 
 
;------------------------------------------------------------------------------ 
; 
; CONFIGURATION WORD SETUP 
; 
; The 'CONFIG' directive is used to embed the configuration word within the  
; .asm file. The lables following the directive are located in the respective  
; .inc file.  See the data sheet for additional information on configuration  
; word settings. 
; 
;------------------------------------------------------------------------------ 
 
     CONFIG FOSC = HSPLL, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF 
     CONFIG BORV = 18, WDTEN = OFF, WDTPS = 1, MCLRE = ON, HFOFST = ON 
     CONFIG LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC, STVREN = OFF 
     CONFIG LVP = OFF,  XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF 
     CONFIG CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF 
     CONFIG WRT2 = OFF, WRT3 = OFF, WRTB = OFF, WRTC = OFF, WRTD = OFF 
     CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF 
     CONFIG EBTRB = OFF 
	
 
;------------------------------------------------------------------------------ 
; 
; VARIABLE DEFINITIONS 
; 
;------------------------------------------------------------------------------ 	
    CBLOCK 0x000 ; Sample GPR variable register allocations 
 		PLCounter
		ExtraCounter
    ENDC 
     
 
 
W_TEMP         EQU        0x000  ; w register for context saving (ACCESS) 
STATUS_TEMP    EQU        0x001  ; status used for context saving  
BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving 
 
;------------------------------------------------------------------------------ 
; EEPROM INITIALIZATION 
; 
; The 18F45K20 has non-volatile EEPROM starting at 0xF00000 
;  
;------------------------------------------------------------------------------ 
 
DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F45K20 
 
    DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3 
 
;------------------------------------------------------------------------------ 
; RESET VECTOR 
;------------------------------------------------------------------------------ 
 
RES_VECT  ORG     0x0000            ; processor reset vector 
          GOTO    START             ; go to beginning of program 
 
;------------------------------------------------------------------------------ 
; HIGH PRIORITY INTERRUPT VECTOR 
;------------------------------------------------------------------------------ 
 
ISRH      ORG     0x0008 
 
          ; Run the High Priority Interrupt Service Routine 
          GOTO    HIGH_ISR              
 
;------------------------------------------------------------------------------ 
; LOW PRIORITY INTERRUPT VECTOR 
;------------------------------------------------------------------------------ 
 
ISRL      ORG     0x0018 
           
          ; Run the High Priority Interrupt Service Routine 
          GOTO    LOW_ISR              
 
;------------------------------------------------------------------------------ 
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE 
;------------------------------------------------------------------------------ 
 
HIGH_ISR   
 
          ; Insert High Priority ISR Here 
 
          RETFIE  FAST 
 
;------------------------------------------------------------------------------ 
; LOW PRIORITY INTERRUPT SERVICE ROUTINE 
;------------------------------------------------------------------------------ 
 
LOW_ISR 
          ; Context Saving for Low ISR 
          MOVWF   W_TEMP              ; save W register 
          MOVFF   STATUS, STATUS_TEMP ; save status register 
          MOVFF   BSR, BSR_TEMP       ; save bankselect register 
 
          ; Insert Low Priority ISR Here 
 
          ; Context Saving for Low ISR 
          MOVFF   BSR_TEMP, BSR       ; restore bankselect register 
          MOVF    W_TEMP, W           ; restore W register 
          MOVFF   STATUS_TEMP, STATUS ; restore status register 
          RETFIE 
 
;------------------------------------------------------------------------------ 
; MAIN PROGRAM 
;------------------------------------------------------------------------------ 
 
START 
		movlw	0x03
		movwf	PLCounter

		movlw	0x06
		movwf	ExtraCounter
		
		MOVLB	B'00001111'
		CLRF 	PORTA 
		MOVLW 	0xE0 					; Configure I/O
		MOVWF 	ANSEL 					; for digital inputs
		MOVLW 	0xC0 					; Value used to
		MOVWF 	TRISA 					; Set RA<5:0> as outputs

		bsf		OSCCON,0
		bsf		OSCCON,1
		bsf		OSCCON,2	
		bsf		OSCCON,4
		bsf		OSCCON,5
		bsf		OSCCON,6


		movlw	0x10					; start loading pixels at RAM location x10	
		movwf	FSR0L,1
		movlw	0x50					; start loading pixels at RAM location x10
		movwf	FSR0H,1
Test
	nop
	nop
	nop
	nop
Freq
		decfsz	PLCounter
		goto	Freq
		movlw	0x03
		movwf	PLCounter
		comf	PORTA
		goto	Freq
END
 
Thread starter Similar threads Forum Replies Date
TBayBoy Microcontrollers 4
V Programming & Languages 13
Top