Hi,
I am trying to get from a 16F628 a 1 Hz square wave pulse on PORTB0 and it gets desperately stuck at 0V .
I've tied PORTB0 to a 2k Ohm resistor .
I've coded the program in assembler, compiled it with Mplab IDE and downloaded it to the
pic thanks to easypic4 dev board .
I use LS oscillator mode with a 32kHz crystal .
I've checked on RA6/OSC2/CLKOUT the sine wave that looks fine .
The main loop does nothing ,
The interrupt service routine loads PORTB at each Timer0 interrupt in W register, then 1 - W is computed and written to PORTB
As PORTB is initialized as 0, I thought it would oscillate between 0 and 1,
but it doesn't :-( .
Here is the code, if someone has some spare time :
#include "p16f628.inc"
__CONFIG _LP_OSC & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _CP_OFF
RESET org 0x0000
goto Main
INTERRUPTION org 0x0004
GOTO ISR
ISR
bcf INTCON, T0IF
movf PORTB, W
sublw 1
movwf PORTB
retfie
Main
bsf STATUS,RP0
bcf OPTION_REG, PSA
bcf OPTION_REG, PS2
bcf OPTION_REG, T0CS
bcf STATUS,RP0
CALL PORTB_INIT
bcf INTCON, T0IE
bcf INTCON, GIE
INF_LOOP
nop
goto INF_LOOP
PORTB_INIT
bsf STATUS,RP0
bcf TRISB,0
bcf STATUS, RP0
clrf PORTB
return
END
Thanks for your help,
Cédric
I am trying to get from a 16F628 a 1 Hz square wave pulse on PORTB0 and it gets desperately stuck at 0V .
I've tied PORTB0 to a 2k Ohm resistor .
I've coded the program in assembler, compiled it with Mplab IDE and downloaded it to the
pic thanks to easypic4 dev board .
I use LS oscillator mode with a 32kHz crystal .
I've checked on RA6/OSC2/CLKOUT the sine wave that looks fine .
The main loop does nothing ,
The interrupt service routine loads PORTB at each Timer0 interrupt in W register, then 1 - W is computed and written to PORTB
As PORTB is initialized as 0, I thought it would oscillate between 0 and 1,
but it doesn't :-( .
Here is the code, if someone has some spare time :
#include "p16f628.inc"
__CONFIG _LP_OSC & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _CP_OFF
RESET org 0x0000
goto Main
INTERRUPTION org 0x0004
GOTO ISR
ISR
bcf INTCON, T0IF
movf PORTB, W
sublw 1
movwf PORTB
retfie
Main
bsf STATUS,RP0
bcf OPTION_REG, PSA
bcf OPTION_REG, PS2
bcf OPTION_REG, T0CS
bcf STATUS,RP0
CALL PORTB_INIT
bcf INTCON, T0IE
bcf INTCON, GIE
INF_LOOP
nop
goto INF_LOOP
PORTB_INIT
bsf STATUS,RP0
bcf TRISB,0
bcf STATUS, RP0
clrf PORTB
return
END
Thanks for your help,
Cédric
Last edited: