1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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

    Code ( (Unknown Language)):
    1.  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...

    Code ( (Unknown Language)):
    1.  
    2. list      p=18f45k20         ; list directive to define processor
    3. #include <p18f45k20.inc>        ; processor specific variable definitions
    4.  
    5.     __CONFIG _FOSC_HSPLL_1H
    6.  
    7.  
    8. ;******************** INITIALIZATION PROTOCOL **************************
    9.  
    10.     org     0x000               ; BIG BANG
    11.     goto    Initialize          ; Initialization call
    12.  
    13. ;Interrupt Vector  
    14.     org     0x004
    15.     retfie
    16.  
    17.     org     0x005               ; Start of Programm Memory Vector
    18.  
    19. Initialize
    20.  
    21. end
     
  2. Markd77

    Senior Member

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

    Code ( (Unknown Language)):
    1. ;******************************************************************************
    2. ;                                                                             *
    3. ;   This file is a basic code template for code generation on the             *
    4. ;   PIC18F45K20. This file contains the basic code building blocks to build   *
    5. ;   upon.                                                                     *
    6. ;                                                                             *
    7. ;   Refer to the MPASM User's Guide for additional information on features    *
    8. ;   of the assembler.                                                         *
    9. ;                                                                             *
    10. ;   Refer to the respective data sheet for additional information on the      *
    11. ;   instruction set.                                                          *
    12. ;                                                                             *
    13. ;******************************************************************************
    14. ;                                                                             *
    15. ;    Filename:         xxx.asm                                                *
    16. ;    Date:                                                                    *
    17. ;    File Version:                                                            *
    18. ;    Author:                                                                  *
    19. ;    Company:                                                                 *
    20. ;                                                                             *
    21. ;******************************************************************************
    22. ;                                                                             *
    23. ;    Files Required: P18F45K20.INC                                            *
    24. ;                                                                             *
    25. ;******************************************************************************
    26. ;                                                                             *
    27. ;    Notes:                                                                   *
    28. ;                                                                             *
    29. ;******************************************************************************
    30. ;                                                                             *
    31. ;    Revision History:                                                        *
    32. ;                                                                             *
    33. ;******************************************************************************
    34.  
    35. ;------------------------------------------------------------------------------
    36. ; PROCESSOR DECLARATION
    37. ;------------------------------------------------------------------------------
    38.  
    39.      LIST      P=PIC18F45K20          ; list directive to define processor
    40.      #INCLUDE <P18F45K20.INC>         ; processor specific variable definitions
    41.  
    42. ;------------------------------------------------------------------------------
    43. ;
    44. ; CONFIGURATION WORD SETUP
    45. ;
    46. ; The 'CONFIG' directive is used to embed the configuration word within the  
    47. ; .asm file. The lables following the directive are located in the respective  
    48. ; .inc file.  See the data sheet for additional information on configuration  
    49. ; word settings.
    50. ;
    51. ;------------------------------------------------------------------------------
    52.  
    53.      CONFIG FOSC = INTIO7, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF
    54.      CONFIG BORV = 18, WDTEN = OFF, WDTPS = 1, MCLRE = ON, HFOFST = ON
    55.      CONFIG LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC, STVREN = OFF
    56.      CONFIG LVP = OFF,  XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF
    57.      CONFIG CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF
    58.      CONFIG WRT2 = OFF, WRT3 = OFF, WRTB = OFF, WRTC = OFF, WRTD = OFF
    59.      CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    60.      CONFIG EBTRB = OFF
    61.  
    62. ;------------------------------------------------------------------------------
    63. ;
    64. ; VARIABLE DEFINITIONS
    65. ;
    66. ;------------------------------------------------------------------------------
    67.  
    68.     CBLOCK 0x60 ; Sample GPR variable register allocations
    69.         MYVAR1  ; user variable at address 0x60
    70.         MYVAR2  ; user variable at address 0x61
    71.         MYVAR3  ; user variable at address 0x62
    72.     ENDC
    73.      
    74.  
    75.  
    76. W_TEMP         EQU        0x000  ; w register for context saving (ACCESS)
    77. STATUS_TEMP    EQU        0x001  ; status used for context saving  
    78. BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving
    79.  
    80. ;------------------------------------------------------------------------------
    81. ; EEPROM INITIALIZATION
    82. ;
    83. ; The 18F45K20 has non-volatile EEPROM starting at 0xF00000
    84. ;  
    85. ;------------------------------------------------------------------------------
    86.  
    87. DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F45K20
    88.  
    89.     DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
    90.  
    91. ;------------------------------------------------------------------------------
    92. ; RESET VECTOR
    93. ;------------------------------------------------------------------------------
    94.  
    95. RES_VECT  ORG     0x0000            ; processor reset vector
    96.           GOTO    START             ; go to beginning of program
    97.  
    98. ;------------------------------------------------------------------------------
    99. ; HIGH PRIORITY INTERRUPT VECTOR
    100. ;------------------------------------------------------------------------------
    101.  
    102. ISRH      ORG     0x0008
    103.  
    104.           ; Run the High Priority Interrupt Service Routine
    105.           GOTO    HIGH_ISR              
    106.  
    107. ;------------------------------------------------------------------------------
    108. ; LOW PRIORITY INTERRUPT VECTOR
    109. ;------------------------------------------------------------------------------
    110.  
    111. ISRL      ORG     0x0018
    112.            
    113.           ; Run the High Priority Interrupt Service Routine
    114.           GOTO    LOW_ISR              
    115.  
    116. ;------------------------------------------------------------------------------
    117. ; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
    118. ;------------------------------------------------------------------------------
    119.  
    120. HIGH_ISR  
    121.  
    122.           ; Insert High Priority ISR Here
    123.  
    124.           RETFIE  FAST
    125.  
    126. ;------------------------------------------------------------------------------
    127. ; LOW PRIORITY INTERRUPT SERVICE ROUTINE
    128. ;------------------------------------------------------------------------------
    129.  
    130. LOW_ISR
    131.           ; Context Saving for Low ISR
    132.           MOVWF   W_TEMP              ; save W register
    133.           MOVFF   STATUS, STATUS_TEMP ; save status register
    134.           MOVFF   BSR, BSR_TEMP       ; save bankselect register
    135.  
    136.           ; Insert Low Priority ISR Here
    137.  
    138.           ; Context Saving for Low ISR
    139.           MOVFF   BSR_TEMP, BSR       ; restore bankselect register
    140.           MOVF    W_TEMP, W           ; restore W register
    141.           MOVFF   STATUS_TEMP, STATUS ; restore status register
    142.           RETFIE
    143.  
    144. ;------------------------------------------------------------------------------
    145. ; MAIN PROGRAM
    146. ;------------------------------------------------------------------------------
    147.  
    148. START
    149.  
    150.           ; Insert User Program Here
    151.  
    152.           GOTO $                      ; loop program counter
    153.  
    154.           END
     
    Eric007 and peter_morley like this.
  3. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Where did you get that information from? Was it on the datasheet?
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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
     
  6. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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.

    Code ( (Unknown Language)):
    1. ------------------------------------------------------------------------------
    2. ; PROCESSOR DECLARATION
    3. ;------------------------------------------------------------------------------
    4.  
    5.      LIST      P=PIC18F45K20          ; list directive to define processor
    6.      #INCLUDE <P18F45K20.INC>         ; processor specific variable definitions
    7.  
    8. ;------------------------------------------------------------------------------
    9. ;
    10. ; CONFIGURATION WORD SETUP
    11. ;
    12. ; The 'CONFIG' directive is used to embed the configuration word within the  
    13. ; .asm file. The lables following the directive are located in the respective  
    14. ; .inc file.  See the data sheet for additional information on configuration  
    15. ; word settings.
    16. ;
    17. ;------------------------------------------------------------------------------
    18.  
    19.      CONFIG FOSC = HSPLL, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF
    20.      CONFIG BORV = 18, WDTEN = OFF, WDTPS = 1, MCLRE = ON, HFOFST = ON
    21.      CONFIG LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC, STVREN = OFF
    22.      CONFIG LVP = OFF,  XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF
    23.      CONFIG CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF
    24.      CONFIG WRT2 = OFF, WRT3 = OFF, WRTB = OFF, WRTC = OFF, WRTD = OFF
    25.      CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    26.      CONFIG EBTRB = OFF
    27.    
    28.  
    29. ;------------------------------------------------------------------------------
    30. ;
    31. ; VARIABLE DEFINITIONS
    32. ;
    33. ;------------------------------------------------------------------------------    
    34.     CBLOCK 0x000 ; Sample GPR variable register allocations
    35.         PLCounter
    36.         ExtraCounter
    37.     ENDC
    38.      
    39.  
    40.  
    41. W_TEMP         EQU        0x000  ; w register for context saving (ACCESS)
    42. STATUS_TEMP    EQU        0x001  ; status used for context saving  
    43. BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving
    44.  
    45. ;------------------------------------------------------------------------------
    46. ; EEPROM INITIALIZATION
    47. ;
    48. ; The 18F45K20 has non-volatile EEPROM starting at 0xF00000
    49. ;  
    50. ;------------------------------------------------------------------------------
    51.  
    52. DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F45K20
    53.  
    54.     DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
    55.  
    56. ;------------------------------------------------------------------------------
    57. ; RESET VECTOR
    58. ;------------------------------------------------------------------------------
    59.  
    60. RES_VECT  ORG     0x0000            ; processor reset vector
    61.           GOTO    START             ; go to beginning of program
    62.  
    63. ;------------------------------------------------------------------------------
    64. ; HIGH PRIORITY INTERRUPT VECTOR
    65. ;------------------------------------------------------------------------------
    66.  
    67. ISRH      ORG     0x0008
    68.  
    69.           ; Run the High Priority Interrupt Service Routine
    70.           GOTO    HIGH_ISR              
    71.  
    72. ;------------------------------------------------------------------------------
    73. ; LOW PRIORITY INTERRUPT VECTOR
    74. ;------------------------------------------------------------------------------
    75.  
    76. ISRL      ORG     0x0018
    77.            
    78.           ; Run the High Priority Interrupt Service Routine
    79.           GOTO    LOW_ISR              
    80.  
    81. ;------------------------------------------------------------------------------
    82. ; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
    83. ;------------------------------------------------------------------------------
    84.  
    85. HIGH_ISR  
    86.  
    87.           ; Insert High Priority ISR Here
    88.  
    89.           RETFIE  FAST
    90.  
    91. ;------------------------------------------------------------------------------
    92. ; LOW PRIORITY INTERRUPT SERVICE ROUTINE
    93. ;------------------------------------------------------------------------------
    94.  
    95. LOW_ISR
    96.           ; Context Saving for Low ISR
    97.           MOVWF   W_TEMP              ; save W register
    98.           MOVFF   STATUS, STATUS_TEMP ; save status register
    99.           MOVFF   BSR, BSR_TEMP       ; save bankselect register
    100.  
    101.           ; Insert Low Priority ISR Here
    102.  
    103.           ; Context Saving for Low ISR
    104.           MOVFF   BSR_TEMP, BSR       ; restore bankselect register
    105.           MOVF    W_TEMP, W           ; restore W register
    106.           MOVFF   STATUS_TEMP, STATUS ; restore status register
    107.           RETFIE
    108.  
    109. ;------------------------------------------------------------------------------
    110. ; MAIN PROGRAM
    111. ;------------------------------------------------------------------------------
    112.  
    113. START
    114.         movlw   0x03
    115.         movwf   PLCounter
    116.  
    117.         movlw   0x06
    118.         movwf   ExtraCounter
    119.        
    120.         MOVLB   B'00001111'
    121.         CLRF    PORTA
    122.         MOVLW   0xE0                    ; Configure I/O
    123.         MOVWF   ANSEL                   ; for digital inputs
    124.         MOVLW   0xC0                    ; Value used to
    125.         MOVWF   TRISA                   ; Set RA<5:0> as outputs
    126.  
    127.         bsf     OSCCON,0
    128.         bsf     OSCCON,1
    129.         bsf     OSCCON,2   
    130.         bsf     OSCCON,4
    131.         bsf     OSCCON,5
    132.         bsf     OSCCON,6
    133.  
    134.  
    135.         movlw   0x10                    ; start loading pixels at RAM location x10 
    136.         movwf   FSR0L,1
    137.         movlw   0x50                    ; start loading pixels at RAM location x10
    138.         movwf   FSR0H,1
    139. Test
    140.     nop
    141.     nop
    142.     nop
    143.     nop
    144. Freq
    145.         decfsz  PLCounter
    146.         goto    Freq
    147.         movlw   0x03
    148.         movwf   PLCounter
    149.         comf    PORTA
    150.         goto    Freq
    151. END    
     
Loading...