Marksphotos main

Electronics main


Mistakes I've made so you don't have to.


Always initialize files. In the debugger they default to zero but on the PIC itself they don't. This causes something that works fine in the simulator to do very odd things.

Configuration word

Always double check it, and make sure that if you have defined MCLR, that you pull it high with a resistor. Also if you have enabled low voltage programming (LVP) on a PIC16F628 or similar that the PGM pin is pulled low with a resistor.
For most purposes the watchdog timer should be disabled.



Bank errors

These seem to be the ones that catch me out the most and are hardest to pin down.

This is the interrupt code in the Microchip template for the PIC12F675:

		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt

It looks fine, but when you enter the interrupt you could be in bank 1 so it's best to put:

	BCF STATUS, RP0		;Bank 0

after the first 4 lines. The next two lines will restore the bank to whatever it was before the interrupt.

I've made lots more mistakes so there is more to come later.