I am having the most awful trouble getting things up and running with my PIC12F1822.
I'm using MPLAB 8.86, an ICD3 and have the chip, in a DIP package set up in a breadboard on my desk. As far as I can see, the connections are all reliable and okay. Things were working okay until yesterday evening and I've not moved/touched anything.
The schematic looks like this:
Before I write any code which does any input based on switches or gets data from serial, I just want to twiddle some LEDs so I know everything is working.
Here's my code :
list p=12F1822 ; list directive to define processor
#include <p12F1822.inc> ; processor specific variable definitions
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
#DEFINE LED1 PORTA,.2 ;Status LED connected to Port A bit 1
D1 EQU 0x7D ;temp register, used during delay
D2 EQU 0x7E ;temp register, used during delay
D3 EQU 0x7F
ORG 0x0000 ; processor reset vector
GOTO START
;----------------------------------------------------------------------------;
;DELAY ROUTINE, FORCES THE PIC TO WASTE TIME FOR 0.1Seconds AT 16MHz;
DELAY
MOVLW 0X35
MOVWF D1
MOVLW 0XE0
MOVWF D2
MOVLW 0X01
MOVWF D3
DELAY_0
DECFSZ D1, F
GOTO $+2
DECFSZ D2, F
GOTO $+2
DECFSZ D3, F
GOTO DELAY_0
;4 CYCLES
GOTO $+1
GOTO $+1
;4 CYCLES (INCLUDING CALL)
RETURN
;------------------------------------------
START
;DEVICE CONFIG STUFF
BANKSEL TRISA
MOVLW B'00000000' ;EVERYTHING ELSE IS OUTPUT
MOVWF TRISA
BANKSEL OSCCON
MOVLW B'01111010' ;PLL DISABLED, 16MHZ CLOCK SPEED, INTERNAL CLOCK
MOVWF OSCCON
BANKSEL ANSELA
CLRF ANSELA ;ALL PINS AS DIGITAL
BANKSEL ADCON1
MOVLW B'00001111'
MOVWF ADCON1 ;ALSO TURNS OFF ANALOG THINGS
BANKSEL CM1CON0 CLRF CM1CON0 ;ALL COMPARATORS OFF
BANKSEL PORTA
CLRF PORTA ;CLEAR EVERYTHING ON PORT A BEFORE WE START, EXIT WITH BANK0 SELECTED
LOOP
;BLINK THAT LED LIKE YOUR LIFE DEPENDED ON IT
BCF LED1
CALL DELAY
BSF LED1
CALL DELAY
GOTO LOOP
END
Nothing too exciting.
When I make this and then program it in in release mode I just get one LED stuck on.
When I make this in debug mode and then try to step through with the debugger/ICD3/MPLAB - I can't reliably get the code to run.
Specifically, the program counter seems to be jumping around all over the place.
To my understanding, when you reset the MCU using the yellow button in MPLAB, the program should go to the top and then wait for you to either run or step through - like this:
The location of the PC is indicated by the green arrow - mine keeps showing up in places which are not the start! It shows up in all manner of places e.g.
This makes debugging a pain - and - indicates that something is really wrong.
I have no idea what - has anyone else come across anything like this?
It isn't limited to this code snippet either. In [This Example] after a reset the PC jumps in at BANKSEL OSCCON (line 138) and when running seems get get stuck inside AUXHELLOWORLD (i.e. the LED keeps flashing forever).
Any insight you might have would be most appreciated Best D