I also posted this thread on the Microchip forums, but I haven't received a useful answer yet, so I'ma try it here - maybe there is somebody who can help me.
While writing very basic programs for the PIC16F684, I stumbled across a strange behavior. After putting the chip out of the programming socket on my breadboard, it runs perfectly, but when I remove the power supply (5V) and reattach it, it won't run. I made the following observations:
- after putting it back into the programmer (without re-programming), it starts working again
- when it doesn't work, the clock-out is still toggling at expected rate, but the other ports are low (the should toggle all outputs slowly, but it doesn't)
- with a bit of luck and inserting the chip the right way on the breadboard (first make the outputs connect, then the power supply), you can get it to work again.
- connecting the leads to the chip in that way won't do the trick
- when /MCLR is turned on, you can reset the chip when putting the resistor to ground, but you can't get the chip to start again when putting the resistor to +5V.
I guess it has something to do with POR, BOR or /MCLR but since I'm a newbie to PIC programming I don't know what's the cause of the behavior. Is the configuration correct?
The setup is the PIC16F684 connected to +5V on a breadboard and LEDs on the outputs.
Here is the code I'm using - it should toggle all pins at a slow rate (except /MCLR and CLKOUT)
Code:
While writing very basic programs for the PIC16F684, I stumbled across a strange behavior. After putting the chip out of the programming socket on my breadboard, it runs perfectly, but when I remove the power supply (5V) and reattach it, it won't run. I made the following observations:
- after putting it back into the programmer (without re-programming), it starts working again
- when it doesn't work, the clock-out is still toggling at expected rate, but the other ports are low (the should toggle all outputs slowly, but it doesn't)
- with a bit of luck and inserting the chip the right way on the breadboard (first make the outputs connect, then the power supply), you can get it to work again.
- connecting the leads to the chip in that way won't do the trick
- when /MCLR is turned on, you can reset the chip when putting the resistor to ground, but you can't get the chip to start again when putting the resistor to +5V.
I guess it has something to do with POR, BOR or /MCLR but since I'm a newbie to PIC programming I don't know what's the cause of the behavior. Is the configuration correct?
The setup is the PIC16F684 connected to +5V on a breadboard and LEDs on the outputs.
Here is the code I'm using - it should toggle all pins at a slow rate (except /MCLR and CLKOUT)
Code:
list p=16f684
#include <p16f684.inc>
;----------------- Configuration -----------------;
__CONFIG _FOSC_INTOSCCLK & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF
ERRORLEVEL -302
;------------------- Variables -------------------;
; Bank0 = 20h-7Fh
CBLOCK 0x020
Delay1: 1
Delay2: 1
ENDC
;-------------------- Macros ---------------------;
BANK0 MACRO
BCF STATUS,RP0
ENDM
BANK1 MACRO
BSF STATUS,RP0
ENDM
MOVLF MACRO lit,file
MOVWF lit
MOVWF file
ENDM
Delay MACRO time
MOVLW time
CALL Delaybegin
ENDM
;----------- Reset Vector & Interrupts ------------;
ORG 0x000 ; processor reset vector
Goto Start ; go to beginning of program
ORG 0x004 ; interrupt vector location
RETFIE ; return from interrupt
;--------------------Start-------------------------;
ORG 0x010
Start:
BANK0
CLRF PORTA
CLRF PORTC
MOVLF 0x07,CMCON0
BANK1
clrf ANSEL ; =0 digital I/O, =1 analog input
MOVLF b'00000000',TRISA ; data direction TRIS 0: output, 1: input (Hi-Z mode)
MOVLF b'00000000',TRISC ; all outputs
BANK0
;-------------------Main Loop-----------------------;
Loop:
CLRF PORTA ; turn LEDs off
CLRF PORTC
Delay 0xFF
DECF PORTA ; trun them back on again; 0x000000-1 = 0x111111
DECF PORTC
Delay 0xFF
goto Loop
;------------------Sub routines---------------------;
Delaybegin:
MOVWF Delay2
CLRF Delay1
delloop:
DECFSZ Delay1
GOTO delloop
DECFSZ Delay2
GOTO delloop
RETURN
END