News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Anyone have a simple led demo for a pic18f25k42

Started by TimB, Nov 02, 2025, 05:05 PM

Previous topic - Next topic

TimB


Hello

I'm looking to develop a prog for an i2c slave on a pic18f25k42 and see that Proteus 8 has a model. I tried simple code to see if the model at least works to flash and LED but nothing..

Not sure if its my code or the Model does not work. Looking at the PPS stuff using the port as a regular output require no setting up

Below is my code

'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config_Start
  FEXTOSC = OFF              ;Oscillator not enable
  RSTOSC = HFINTOSC_64MHZ    ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:
  CLKOUTEN = OFF             ;CLKOUT function is disable
  PR1WAY = ON                ;PRLOCK bit can be cleared and set only onc
  CSWEN = ON                 ;Writing to NOSC and NDIV is allowe
  FCMEN = ON                 ;Fail-Safe Clock Monitor enable
  MCLRE = EXTMCLR            ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
  PWRTS = PWRT_64            ;PWRT set at 64m
  MVECEN = ON                ;Multi-vector enabled, Vector table used for interrupt
  IVT1WAY = ON               ;IVTLOCK bit can be cleared and set only onc
  LPBOREN = OFF              ;ULPBOR disable
  BOREN = SBORDIS            ;Brown-out Reset enabled , SBOREN bit is ignore
  BORV = VBOR_2P45           ;Brown-out Reset Voltage (VBOR) set to 2.45
  ZCD = OFF                  ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCO
  PPS1WAY = ON               ;PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycl
  STVREN = ON                ;Stack full/underflow will cause Rese
  DEBUG = OFF                ;Background debugger disable
  XINST = OFF                ;Extended Instruction Set and Indexed Addressing Mode disable
  WDTCPS = WDTCPS_31         ;Divider ratio 1:65536; software control of WDTP
  WDTE = ON                  ;WDT enabled regardless of slee
  WDTCWS = WDTCWS_7          ;window always open (100%); software control; keyed access not require
  WDTCCS = SC                ;Software Contro
  BBSIZE = BBSIZE_512        ;Boot Block size is 512 word
  BBEN = OFF                 ;Boot block disable
  SAFEN = OFF                ;SAF disable
  WRTAPP = OFF               ;Application Block not write protecte
  WRTB = OFF                 ;Configuration registers (300000-30000Bh) not write-protecte
  WRTC = OFF                 ;Boot Block (000000-0007FFh) not write-protecte
  WRTD = OFF                 ;Data EEPROM not write-protecte
  WRTSAF = OFF               ;SAF not Write Protecte
  LVP = ON                   ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignore
  CP = OFF                   ;PFM and Data EEPROM code protection disable
Config_End

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------






  '**** Compiler Defs *****
    Declare Create_Coff = On



     Device 18F25K42


     Xtal 64

     Osc_64MHz()

     TrisB = %1111000

     while 1 = 1


        delayms 1000
        High  portb.0
        delayms 1000
        Low  portb.0


     Wend





'------------------------------------------------------------------------------------
' Setup the internal oscillator to operate at 64MHz
' Input     : None
' Output    : None
' Notes     : None
''

    Proc Osc_64MHz()
       OSCCON1 = $60               ' NOSC HFINTOSC, NDIV 1
       OSCCON3 = $00               ' CSWHOLD may proceed, SOSCPWR Low power
       OSCEN   = $00               ' MFOEN disabled, LFOEN disabled, ADOEN disabled, SOSCEN disabled, EXTOEN disabled, HFOEN disabled
       OSCFRQ  = $08               ' HFFRQ 64_MHz
       OSCTUNE = $00
    EndProc

Pepe

'------------------------------------------------------------
' PIC18F25K42 - LED Intermitente con Oscilador Interno 64 MHz
'------------------------------------------------------------
Device = 18F25K42

'------------------------------------------------------------
' CONFIGURACIÓN DE FUSES
'------------------------------------------------------------
Config_Start
  FEXTOSC = OFF              ; Oscilador externo deshabilitado
  RSTOSC = HFINTOSC_64MHZ    ; HFINTOSC con HFFRQ = 64 MHz y CDIV = 1
  CLKOUTEN = OFF              ; CLKOUT deshabilitado
  PR1WAY = On                 ; PRLOCK solo se puede cambiar una vez
  CSWEN = On                  ; Cambio de reloj permitido
  FCMEN = On                  ; Fail-Safe Clock Monitor habilitado
  MCLRE = EXTMCLR             ; Pin MCLR habilitado
  PWRTS = PWRT_64             ; Power-up timer = 64 ms
  MVECEN = On                 ; Vectores múltiples habilitados
  IVT1WAY = On                ; IVTLOCK solo se puede cambiar una vez
  LPBOREN = OFF               ; BOR bajo voltaje deshabilitado
  BOREN = SBORDIS             ; BOR habilitado
  BORV = VBOR_2P45            ; Nivel BOR = 2.45 V
  ZCD = OFF                   ; Detector de cruce por cero deshabilitado
  PPS1WAY = On                ; PPSLOCK solo se puede cambiar una vez
  STVREN = On                 ; Reset por desbordamiento de pila habilitado
  Debug = OFF                 ; Depuración deshabilitada
  XINST = OFF                 ; Juego extendido deshabilitado
  WDTCPS = WDTCPS_31          ; WDT 1:65536 (por software)
  WDTE = OFF                  ; WDT deshabilitado
  WDTCWS = WDTCWS_7           ; Ventana WDT siempre abierta
  WDTCCS = SC                 ; Control por software
  BBSIZE = BBSIZE_512         ; Boot Block = 512 palabras
  BBEN = OFF                  ; Boot Block deshabilitado
  SAFEN = OFF                 ; SAF deshabilitado
  WRTAPP = OFF                ; Sin protección de escritura
  WRTB = OFF
  WRTC = OFF
  WRTD = OFF
  WRTSAF = OFF
  LVP = OFF                   ; Deshabilita programación de bajo voltaje
  Cp = OFF                    ; Protección de código deshabilitada
Config_End

'------------------------------------------------------------
' CONFIGURACIÓN DEL RELOJ INTERNO
'------------------------------------------------------------
Declare Xtal = 64
Declare Optimiser_Level = 3
Declare Create_Coff On
Declare Reminders off
Declare Watchdog Off

'------------------------------------------------------------
' PROGRAMA PRINCIPAL
'------------------------------------------------------------
Call Osc_64MHz()           ' Configura el oscilador interno

TRISB = %11111110          ' RB0 como salida
LATB.0  = 0                  ' Inicializa en bajo

Do
    Toggle LATB.0
    DelayMS 500
Loop

  Proc Osc_64MHz()
   OSCCON1 = %01100000     ' Fuente HFINTOSC, sin división
   OSCCON3 = %00000000     ' Configuración estándar
   OSCEN   = %00000000     ' Solo HFINTOSC habilitado
   OSCFRQ  = %00001000     ' Frecuencia = 64 MHz
   OSCTUNE = 0
EndProc




TimB

Many thanks Pepe


The issue was Proteus does not the 18f25k42. I thought it did but selected a 18f25k22. No wonder the code did not work


I need to write a i2c slave for a device with at least 3 HPWM ports. Not may have that and are supported in Proteus. There are chips that can fit my requirements but they are long in the tooth. The Pic18f27Q10 is newer but I found the sim of that device in Proteus was flaky.