Tagge
Joined: 23 Aug 2005 Posts: 93
|
Migration from 16F870 to 16F876A? |
Posted: Wed Jun 13, 2007 1:33 am |
|
|
Hi, first, in this case its an asm code Im working with, but as "our" forum is the best at the net I thought to submit it here, hope you dont mind. And maybe its some fun for you to dig in some "old" asm code?
When changing from 16F870 to 16F876A the internal ee-prom stopped working, is this some known issue? the way to read and write are the same, all adresses are the same and so on..
Heres the code that seems to be the problem?..
Code: |
list p=16f876A
include "p16f876A.inc" ; Include file, change directory if needed
__CONFIG 0x3F31
ORG 0x000 ; START RESET VECTOR
GOTO MAIN
ORG 0x004
; main with some code...
; ************ INITIATION PROCESSOR *****
INIT
BANKSEL OPTION_REG ;SETS WHICH INTERRUPTS THAT SHOUD BE USED
MOVLW B'00000111' ;SET PRESCALER TO TMR0 AND 1:256
MOVWF OPTION_REG
MOVLW B'00000000'
MOVWF INTCON
MOVLW B'00111111'
MOVWF TRISA ;'0'=output, '1'= input
MOVLW B'00001111'
MOVWF TRISB
MOVLW B'10000001'
MOVWF TRISC
MOVLW B'00000100' ;SET A/D TO A0,A1 AND A3 TO ANALOG INPUT WITH VDD AND VSS AS REF.
MOVWF ADCON1
BANKSEL PORTA
MOVLW B'01001001' ;SET A/D CONVERTER TO FOSC/8 START WITH CHANNEL1, A/D CONVERTER ACTIVE
MOVWF ADCON0
MOVLW B'00110000' ;SET TIMER1 TO 1:8 PRESCALER, OCSILLATOR SHUT OFF, INTERNAL CLK, TIMER OFF
MOVWF T1CON
CLRF TMR1H ;CLEAR TIMER REGISTER
CLRF TMR1L ;
CLRF PORTA ;CLEAR PORTA, PORTB AND PORT C TO HAVE DEFINED START VALUES
CLRF PORTB
CLRF PORTC
BSF PORTC,1 ;TO GET BETTER HOLDING PERFORMANS OF ACTUATOR
CLRF STATE
CLRF ERR_TYP
MOVLW .10
MOVWF AD_CON ;A/D VALUES HAS TO BE HIGH TEN TIMES IN A ROW BEFORE ACTUATOR IS SWITCHED OFF
MOVLW .15 ;NUMBER OF BLINKS BEFORE SETTING ERROR, HAS TO BE CHANGED IN STATE1, STATE5 AND STATE7 ASWELL
MOVWF COUNTER
CLRF STATE ;SET SYSTEM TO START IN STATE 0
CLRF FLAGGA ;CLEAR FLAGGREGITRET
CLRF TEMP
CLRF TEMP1
CLRF HTEMP1
CLRF HTEMP2
MOVLW .4 ;SET AMOUNT OF TIME FOR TMR1 TO TIME OUT BEFORE SWITCH BETWEEN SB AND PS
MOVWF SBPSTMR
MOVLW .10
MOVWF PEEPT
MOVLW .1
MOVWF PEEPT1
CALL LOADSTAT
RETURN
;---------------------------------------
; EE-prom write and read
;*********** WRITE EEPROM *************
SAVESTAT BSF STATUS,RP1
BSF STATUS,RP0
SAVEST1 BTFSC EECON1,WR
GOTO $-1
BCF STATUS,RP0
MOVLW 0x01 ; EEPROM address
MOVWF EEADR
MOVF STATE, W ; VALUE
MOVWF EEDATA
BSF STATUS, RP0
BCF EECON1, EEPGD
BSF EECON1, WREN
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF EECON1, WR
BCF EECON1, WREN
;GOTO ESAVE
SAVEST2 BTFSC EECON1,WR
GOTO $-1
BCF STATUS,RP0
MOVLW 0x02 ; EEPROM address
MOVWF EEADR
MOVF RUN,W ; VALUE
MOVWF EEDATA
BSF STATUS, RP0
BCF EECON1, EEPGD
BSF EECON1, WREN
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF EECON1, WR
BCF EECON1, WREN
ESAVE BCF STATUS, RP0
BCF STATUS, RP1
RETURN
LOADSTAT BSF STATUS, RP1
BCF STATUS, RP0
MOVLW 0x01 ; EEPROM address
MOVWF EEADR
BSF STATUS, RP0
BCF EECON1, EEPGD
BSF EECON1, RD
BCF STATUS, RP0
MOVF EEDATA, W
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF TEMP ; Save read value into temp
MOVLW .1
SUBWF TEMP, W
BTFSC STATUS, Z
GOTO STATOK
MOVLW .2
SUBWF TEMP, W
BTFSC STATUS, Z
GOTO STATOK
MOVLW .4
SUBWF TEMP,W
BTFSC STATUS, Z
GOTO STATOK
MOVLW .32
SUBWF TEMP, W
BTFSC STATUS, Z
GOTO STATOK
; NO VALID VALUE IN EEPROM
MOVLW .1
MOVWF TEMP
STATOK MOVF TEMP, W
MOVWF STATE
BSF STATUS, RP1
BCF STATUS, RP0
MOVLW 0x02 ; EEPROM address
MOVWF EEADR
BSF STATUS, RP0
BCF EECON1, EEPGD
BSF EECON1, RD
BCF STATUS, RP0
MOVF EEDATA, W
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF RUN
RETURN
|
|
|