I've been trying to get some code working on the 12F1822 which works fine on the 16F690
I can't explain why there should be a big difference in operation. I've gone through the datasheet trying to find differences between teh two chips and making any necessary adjustments.
All I am trying to do at this stage is prove correct operation of the UART, so I have written a simple echo routine.
Code:
; __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _MCLRE_OFF & _PWRTE_OFF & _BOREN_OFF & _CLKOUTEN_OFF
; __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
Include "modedefs.bas"
DEFine OSC 8
define INTHAND myint
RX_Byte var byte
goto init
asm
myint:
btfss PIR1,5
goto int_out
bcf PIR1,5
movfw RCREG
movwf _RX_Byte
movwf TXREG
nop
btfss PIR1,TXIF
goto $-1
int_out:
retfie
endasm
init:
TRISA = %00000010 ; set pins for serial data
ANSELA = 0 ; set all pins digital
PORTA = %00000000
pause 200
asm
movfw RCREG
movfw RCREG
movfw RCREG
endasm
; Power on
; Initialise variables
Restart:
; Initialise SFR's
;EUSART
TXSTA = %10100100
RCSTA = %10010000
BAUDCON = %00000000
SPBRG = 12 '38400 baud
;SPBRGH = 0
;INTERRUPTS
INTCON = %11000000
PIE1 = %00100000 ; interrrupt on data received
;OSCILLATOR
OSCCON = %01110011
;PORT A
TRISA = %00000010 ; set pins for serial data
ANSELA = 0 ; set all pins digital
PORTA = 255
;COMPARATOR
CM1CON0 = 0
main:
while 1
if (RCSTA.1 = 1) or (RCSTA.2 = 1) then
gosub Clear_err
endif
wend
Clear_err:
RCSTA = 0
@ movfw RCREG
@ movfw RCREG
@ movfw RCREG
RCSTA = %10010000
return
stop
The chip seems to repeatedly reset itself.
Any help getting this going will be very much appreciated. I have tried loits of variations of the commands in case there is a datasheet error ( I recall from previous experience with the 12F1822 I found a datasheet error).
Chris
Bookmarks