| View previous topic :: View next topic |
| Author |
Message |
AltPic8088
Joined: 12 Mar 2026 Posts: 2
|
| Problem with PIC16F13115 and a GPIO (SOLVED) |
Posted: Thu Mar 12, 2026 5:31 pm |
|
|
Good afternoon.
I need to migrate a small project to the PIC16F13115 from the PIC12F1840 that I am currently using.
The only problem I have in the entire migration is the RA5 output, which does not change state.
The code I am using to test is the following:
| Code: |
#INCLUDE <16F13115.h>
#FUSES WDT // Utilizamos el perro guardián.
#FUSES PUT_64MS // Habilita el power uP timer en 64ms.
#FUSES NOMCLR // Utilizamos el pin MCLR como E/S.
#FUSES PROTECT // Proteje el código del microcontrolador.
#FUSES NOBROWNOUT // No hay reset por bajo voltaje.
#FUSES NOCLKOUT // Utiliza los pines de clk como E/S.
#FUSES FCMEN // Monitor de falla de clock.
#FUSES NOWRT // No hay protección de registros especiales.
#FUSES STVREN // Si la pila se llena, generará un reset.
#FUSES NODEBUG // No utilizaremos código de debug.
#FUSES WDT2048 // Utilizamos el perro guardián cada 2 segundos.
#FUSES NOLVP // No utilizaremos programación a bajo voltaje.
#FUSES NOBOOTBLOCK // No deja espacio para el booteo.
#USE delay (Clock = 32000000,restart_wdt) // Reloj = 32Mhz.
//------------------------------------------------
// Inicialización
//------------------------------------------------
void Inicializacion(void)
{
setup_oscillator(OSC_HFINTRC_32MHZ);
output_a(0x00);
delay_ms(100);
setup_wdt(WDT_2S);
}
//------------------------------------------------
// MAIN
//------------------------------------------------
void main()
{
Inicializacion();
setup_adc_ports(NO_ANALOGS);
while(TRUE) {
output_high(PIN_A5);
delay_ms(500);
output_low(PIN_A5);
delay_ms(500);
restart_wdt();
}
}
|
Does anyone have an idea where I might be going wrong? I checked the datasheet, consulted AI, etc., but I still can’t figure it out.
I thought it might be a CCS error, but the affected registers shown in the assembly file seem to be correct.
Best regards!
Last edited by AltPic8088 on Thu Mar 12, 2026 9:04 pm; edited 1 time in total |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9627 Location: Greensville,Ontario
|
|
Posted: Thu Mar 12, 2026 6:53 pm |
|
|
don't use that PIC but 2 things come up
1) RA5 is a pin selectable pin.. so you might have to actually select it....
there's a 'sticky' up top about 'how to use'...
2) get rid of the WDT ! you really shouldn't use/enable it until your program is 100% tested and ready for sale. ONLY then should you enable the WDT ,after having calculating the correct WDT 'timeout period'.
3) delete the 'protect' fuse
I'm sure others who use the PIC will reply soon.... |
|
 |
AltPic8088
Joined: 12 Mar 2026 Posts: 2
|
|
Posted: Thu Mar 12, 2026 9:02 pm |
|
|
Thank you very much for the response, Temtronic.
The solution was to add the following configuration lines:
| Code: |
#FUSES RSTOSC_HFINTRC_32MHZ // Oscilador interno con PLL a 32Mhz.
#FUSES NOCLKOUT
#FUSES NOEXTOSC // No utilizamos el oscilador externo.
|
Greetings! |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9627 Location: Greensville,Ontario
|
|
Posted: Fri Mar 13, 2026 5:52 am |
|
|
| Great to see 'SOLVED' in a post ! |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20051
|
|
Posted: Fri Mar 13, 2026 6:58 am |
|
|
Or use the correct clock setup:
| Code: |
#USE delay (INTERNAL = 32000000,restart_wdt) // Reloj = 32Mhz.
|
Your original setup was saying the clock was 32MHz, but not telling the
complex 'where' to get this from. Setting this with the fuses is more
complex (especially on a lot of the later chips), while just specifying it in
the delay line, tells the compiler what fuses it has to set to get this. |
|
 |
|