18F25K22 Help


Closed Thread
Results 1 to 18 of 18

Thread: 18F25K22 Help

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    88

    Default 18F25K22 Help

    Hello All,

    OK, I've been on here for hours trying to research the information, but can't find exactly what I'm looking for. Even exhausted my efforts on Google, the manual and Datasheet (for what I could interpret).

    I want to make all my ports digital. I have tried the adcon1 = 15 and even Darrell's alldigital.php. It doesn't work correctly. I am trying to implement some simple code, but it doesn't behave properly. What am I doing wrong?

    Code:
    ;----[18F25K22 Hardware Configuration]------------------------------------------
    #IF __PROCESSOR__ = "18F25K22"
      #DEFINE MCU_FOUND 1
    #CONFIG
      CONFIG  FOSC = INTIO67     ; Internal oscillator block
      CONFIG  PLLCFG = OFF       ; Oscillator used directly
      CONFIG  PRICLKEN = OFF     ; Primary clock can be disabled by software
      CONFIG  FCMEN = OFF        ; Fail-Safe Clock Monitor disabled
      CONFIG  IESO = OFF         ; Oscillator Switchover mode disabled
      CONFIG  PWRTEN = OFF       ; Power up timer disabled
      CONFIG  BOREN = SBORDIS    ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
      CONFIG  BORV = 190         ; VBOR set to 1.90 V nominal
      CONFIG  WDTEN = ON         ; WDT is always enabled. SWDTEN bit has no effect
      CONFIG  WDTPS = 32768      ; 1:32768
      CONFIG  CCP2MX = PORTC1    ; CCP2 input/output is multiplexed with RC1
      CONFIG  PBADEN = OFF       ; PORTB<5:0> pins are configured as digital I/O on Reset
      CONFIG  CCP3MX = PORTB5    ; P3A/CCP3 input/output is multiplexed with RB5
      CONFIG  HFOFST = ON        ; HFINTOSC output and ready status are not delayed by the oscillator stable status
      CONFIG  T3CMX = PORTC0     ; T3CKI is on RC0
      CONFIG  P2BMX = PORTB5     ; P2B is on RB5
      CONFIG  MCLRE = INTMCLR    ; RE3 input pin enabled; MCLR disabled
      CONFIG  STVREN = ON        ; Stack full/underflow will cause Reset
      CONFIG  LVP = OFF          ; Single-Supply ICSP disabled
      CONFIG  XINST = OFF        ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
      CONFIG  DEBUG = OFF        ; Disabled
      CONFIG  CP0 = OFF          ; Block 0 (000800-001FFFh) not code-protected
      CONFIG  CP1 = OFF          ; Block 1 (002000-003FFFh) not code-protected
      CONFIG  CP2 = OFF          ; Block 2 (004000-005FFFh) not code-protected
      CONFIG  CP3 = OFF          ; Block 3 (006000-007FFFh) not code-protected
      CONFIG  CPB = OFF          ; Boot block (000000-0007FFh) not code-protected
      CONFIG  CPD = OFF          ; Data EEPROM not code-protected
      CONFIG  WRT0 = OFF         ; Block 0 (000800-001FFFh) not write-protected
      CONFIG  WRT1 = OFF         ; Block 1 (002000-003FFFh) not write-protected
      CONFIG  WRT2 = OFF         ; Block 2 (004000-005FFFh) not write-protected
      CONFIG  WRT3 = OFF         ; Block 3 (006000-007FFFh) not write-protected
      CONFIG  WRTC = OFF         ; Configuration registers (300000-3000FFh) not write-protected
      CONFIG  WRTB = OFF         ; Boot Block (000000-0007FFh) not write-protected
      CONFIG  WRTD = OFF         ; Data EEPROM not write-protected
      CONFIG  EBTR0 = OFF        ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR1 = OFF        ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR2 = OFF        ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTR3 = OFF        ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
      CONFIG  EBTRB = OFF        ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    ' -----[ Initialization ]-------------------------------------------------------
     
    Reset:
    
      OSCCON = %01010000             ' 4MHz 
      ADCON1 = 15                    ' set to digital outputs
      TRISA = %00000000              ' sets pin as input (1) or output (0)
      TRISB = %00000001              ' sets pin as input (1) or output (0)
      TRISC = %10001100              ' sets pin as input (1) or output (0)
      PORTA = %00000000              ' sets outputs as high (1) or low (0)
      PORTB = %00000000              ' sets outputs as high (1) or low (0)
      PORTC = %00000000              ' sets outputs as high (1) or low (0)
    
    ' -----[ Variables ]------------------------------------------------------------
     
        led1          var   porta.1  ' LED 1
        led2          var   porta.2  ' LED 2
        led3          var   portb.1  ' LED 3
        led4          var   portb.2  ' LED 4
    
    action:
          
        led1 = 1
        pause 500
    
        led2 = 1
        pause 500
    
        led3 = 1
        pause 500
    
        led4 = 1
        pause 5000
    This code should sequence on in half second intervals and stay on at the end. I had more code, but what was happening was it was sequencing on and then resetting after the sequence. I've tried putting code that made it hold in a loop, but when the LED's sequence on and it reaches the 5 second mark, the whole thing resets.

    Also, when the code goes from LED1 to LED2, LED1 turns off. The rest stay on, but LED1 always turns off.

    Any thoughts? I've spent over 6 hours trying to figure this out.

    Thanks,
    Tony

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: 18F25K22 Help

    since you have
    CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset



    Code:
    ;Reset:  probably not a good name for a label
    startup:
    
      OSCCON = %01010000             ' 4MHz 
     ;ADCON1 = 15                    what ?
    ansela=0
    
    ;TRISB = %00000001              ' sets pin as input (1) or output (0)   ???????????????  
    ; TRISC = %10001100             ' sets pin as input (1) or output (0)  ?  for what reason
    TRISB = %11111100 
    TRISA = %11111100
    
      PORTA =0  
      PORTB =0  ' sets outputs as high (1) or low (0)
      PORTC = %00000000              ' sets outputs as high (1) or low (0) why ?
    
    
    ' -----[ Variables ]------------------------------------------------------------
     
        led1          var   porta.1  ' LED 1
        led2          var   porta.2  ' LED 2
        led3          var   portb.1  ' LED 3
        led4          var   portb.2  ' LED 4
    
    action:
          
        led1 = 1
        pause 500
    
        led2 = 1
        pause 500
    
        led3 = 1
        pause 500
    
        led4 = 1
        pause 5000
    
    while 1  ; loop forever

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: 18F25K22 Help

    just noticed the wend fell off

    Code:
    while 1  ; loop forever
    wend

  4. #4
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: 18F25K22 Help

    The settings are the way they are because that code is from a much larger piece of code. I am utilizing 23 I/O pins, so those are the settings for those pins.

    Since the larger portion of code was not working, I dumbed it down to see where my problem was. It's a lot easier for me to diagnose this way. I just can't figure out why it resets itself after the last command. I even put a loop at the end which would only exit after a button was pressed. It would hold there for one time and then after the button was pressed once, it would run through the sequencing and reset as stated earlier without holding in the hold loop.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: 18F25K22 Help

    an erased chip is all nop's
    a program not in a closed loop will execute all the remaining nop's till it hits the end of pgm memory, it then wraps back to location 0000 ie looks like a reset

    adcon1=15 is an invalid setting and may cause issues

    I had assumed the leds were on b0,b1, a0,a1 my mistake in the tris settings

  6. #6
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: 18F25K22 Help

    Actually, I tried multiple settings. I searched throughout this site and even found one instance where Darrel suggested adcon1 = 15, so I tried that. After my post, I changed it to:

    Code:
      ADCON1 = %00001110             ' set to digital outputs
    The end code I had after the last LED pause was:

    Code:
     while program = 1
    
      pause 100
    
     wend      
    
        relay1 = 0
        relay2 = 0
        relay3 = 0
        relay4 = 0
          
        led1 = 0
        led2 = 0
        led3 = 0
        led4 = 0
    
    goto action
    As stated, when the program is initially run, the program waits until the button was pressed. Once pressed, it then runs through the sequence continuously, never stopping at the while loop.

    Now, I did put in the necessary variable at the top of the code so it would acknowledge the button and when it would be pressed, I'm just out of ideas. Anybody have any?

    Thanks,
    Tony

Similar Threads

  1. migration from 16F876a to 18F25k22
    By MOUNTAIN747 in forum General
    Replies: 26
    Last Post: - 19th March 2012, 21:33
  2. Config 18F25K22
    By mpardinho in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2011, 19:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts