Hi,
I've written he following program to test the writting in the falsh program memory internal write in 16f877.
I am supposed to have first porta = 0x03, then it will be 0xFF
I simulated it with MPLAB SIM and it is not working.
Please would you show me the error that i've done.
Thank you
List p=16f877
include<p16f877.inc>
__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
errorlevel-302
ADDRL EQU 0X20
ADDRH EQU 0X21
VALUEL EQU 0X22
VALUEH EQU 0X23
;;;;;;;;;;;;;**********PORT CONFIG***********;;;;;;;;;;;;;;;;;;;;;;;
ORG 0X0000
BANK0 macro
bcf STATUS,RP0
BCF STATUS,RP1
endm
BANK1 macro
BSF STATUS,RP0
BCF STATUS,RP1
endm
;;;;;;;;;;;;;;;;;****************PORT OUTPUT CONFIG**************;;;;;;;;;;;
BANKSEL OPTION_REG
BCF OPTION_REG,5 ; SET THE PIN RA4 AS Internal instruction cycle clock (CLKOUT)
BANK1
MOVLW B'00000111'
MOVWF ADCON1 ; SET ALL THE PINS TO DEGITALS INPUT/OUTPUT
MOVLW 0xff
MOVWF TRISB ;
movwf TRISD
movwf TRISC
MOVWF TRISE
MOVLW 0x00 ;
MOVWF TRISA
BANK0
GOTO TEST
TEST ORG 0X0020
MOVLW b'00000011'
MOVWF PORTA
IN MOVLW 0x22
MOVWF ADDRL
CLRF ADDRH
MOVLW 0XFF
MOVWF VALUEL
MOVLW 30
MOVWF VALUEH
BSF STATUS, RP1 ;
BCF STATUS, RP0 ;Bank 2
MOVF ADDRL, W ;Write address
MOVWF EEADR ;of desired
MOVF ADDRH, W ;program memory
MOVWF EEADRH ;location
MOVF VALUEL, W ;Write value to
MOVWF EEDATA ;program at
MOVF VALUEH, W ;desired memory
MOVWF EEDATH ;location
BSF STATUS, RP0 ;Bank 3
BSF EECON1, EEPGD ;Point to Program memory
BSF EECON1, WREN ;Enable writes
;Only disable interrupts
MOVLW 0x55 ;Write 55h to
MOVWF EECON2 ;EECON2
MOVLW 0xAA ;Write AAh to
MOVWF EECON2 ;EECON2
BSF EECON1, WR ;Start write operation
NOP ;Two NOPs to allow micro
NOP ;to setup for write
;Only enable interrupts
BCF EECON1, WREN ;Disable writes
GOTO TEST
END
I've written he following program to test the writting in the falsh program memory internal write in 16f877.
I am supposed to have first porta = 0x03, then it will be 0xFF
I simulated it with MPLAB SIM and it is not working.
Please would you show me the error that i've done.
Thank you
List p=16f877
include<p16f877.inc>
__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
errorlevel-302
ADDRL EQU 0X20
ADDRH EQU 0X21
VALUEL EQU 0X22
VALUEH EQU 0X23
;;;;;;;;;;;;;**********PORT CONFIG***********;;;;;;;;;;;;;;;;;;;;;;;
ORG 0X0000
BANK0 macro
bcf STATUS,RP0
BCF STATUS,RP1
endm
BANK1 macro
BSF STATUS,RP0
BCF STATUS,RP1
endm
;;;;;;;;;;;;;;;;;****************PORT OUTPUT CONFIG**************;;;;;;;;;;;
BANKSEL OPTION_REG
BCF OPTION_REG,5 ; SET THE PIN RA4 AS Internal instruction cycle clock (CLKOUT)
BANK1
MOVLW B'00000111'
MOVWF ADCON1 ; SET ALL THE PINS TO DEGITALS INPUT/OUTPUT
MOVLW 0xff
MOVWF TRISB ;
movwf TRISD
movwf TRISC
MOVWF TRISE
MOVLW 0x00 ;
MOVWF TRISA
BANK0
GOTO TEST
TEST ORG 0X0020
MOVLW b'00000011'
MOVWF PORTA
IN MOVLW 0x22
MOVWF ADDRL
CLRF ADDRH
MOVLW 0XFF
MOVWF VALUEL
MOVLW 30
MOVWF VALUEH
BSF STATUS, RP1 ;
BCF STATUS, RP0 ;Bank 2
MOVF ADDRL, W ;Write address
MOVWF EEADR ;of desired
MOVF ADDRH, W ;program memory
MOVWF EEADRH ;location
MOVF VALUEL, W ;Write value to
MOVWF EEDATA ;program at
MOVF VALUEH, W ;desired memory
MOVWF EEDATH ;location
BSF STATUS, RP0 ;Bank 3
BSF EECON1, EEPGD ;Point to Program memory
BSF EECON1, WREN ;Enable writes
;Only disable interrupts
MOVLW 0x55 ;Write 55h to
MOVWF EECON2 ;EECON2
MOVLW 0xAA ;Write AAh to
MOVWF EECON2 ;EECON2
BSF EECON1, WR ;Start write operation
NOP ;Two NOPs to allow micro
NOP ;to setup for write
;Only enable interrupts
BCF EECON1, WREN ;Disable writes
GOTO TEST
END