bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
movlw 0x01 ;content of eeprom
call write_eeprom;
.....
clrf counter
loop:
....
code depends how do you select the data to send to EEPROM
...
....
incf [B]counter[/B],f
btfss status,z ; // seems OK
goto loop
....
clrf counter
loop:
....
eeprom data here ?
code depends how do you select the data to send to EEPROM
...
....
incf counter,f
btfss status,z ; // seems OK
goto loop
starting counter : movlw .255 and reduce it until zero and if it's zero, writing process is finished ?
is your decision !where should I put my data ?
Movlw 12 // nb of data in bloc 1
movwf N ; // counter of data in bloc
clrf Counter,f
// star of the first bloc
// choose the correct bank if necessary
movlw Adresse_1erbloc
movwf FSR
Suivant:
mowf INDF,W
// now W contains the data of bloc1
call write_eeprom;
incf Counter,f // pointer adresse EEPROM
inc FSR,f // pointer inside the bloc
decfsz N;f // counter of data in the bloc
goto Suivant
// treat Next Blocs
Movlw 13 // nb of data in bloc 2
movwf N ; // counter of data in bloc
clrf Counter,f
// star of the second bloc
// choose the correct bank if necessary
movlw Adresse_2embloc
movwf FSR
Suivant1 :
mowf INDF,W
// now W contains the data of bloc1
call write_eeprom;
incf Counter,f // pointer adresse EEPROM
inc FSR,f // pointer inside the bloc
decfsz N;f // counter of data in the bloc
goto Suivant1
....etc...
movlw Adresse_2em_bloc
mowf Adresse_of_the_bloc
call StoreBloc13
movlw Adresse_3em_bloc
mowf Adresse_of_the_bloc
call StoreBloc13
movlw Adresse_4em_bloc
mowf Adresse_of_the_bloc
call StoreBloc13
....
movlw Adresse_19em_bloc
mowf Adresse_of_the_bloc
call StoreBloc13
........ ??? .......
StoreBloc13:
Movlw 13 // nb of data in bloc x
movwf N ; // counter of data in bloc
clrf Counter,f
// star of the second bloc
// choose the correct bank if necessary
movf Adresse_of_the_bloc,w
movwf FSR
Suivantx :
mowf INDF,W // now W contains the data of blocx
call write_eeprom;
incf Counter,f // pointer adresse EEPROM
inc FSR,f // pointer inside the bloc
decfsz N;f // counter of data in the bloc
goto Suivantx
return
read_eeprom_transmit
;wait for 200ms before sending datas, tested on 300ms more stable
movf LEDTimer,w ;for every 200 milliseconds, it sets on initialization
btfss STATUS,Z ;check the counter if it's already zero
return
;test with 200 ms counter
;DEBUG
;bsf PORTB,POWERLED
;DEBUG
;==========COMMAND HEADER==========
call initPCbuffer
movlw 0x0F ;send data 0x0F into the buffer
call addPCbuffer
movlw 0x55 ;send data 0x55 into the buffer
call addPCbuffer
;==========COMMAND HEADER==========
;==========READ AND TRANSMIT DATA 8 BYTES BEGIN HERE==============
movlw .0
movwf Addr_Counter
loop_rd
movf Addr_Counter,W
movwf nTheEEAddress ;set the address equal to Addr_Counter
call eeRead ;read data from the address from eeprom
call addPCbuffer ;put data on buffer before transmitting
incf Addr_Counter,f
;=================check if address counter is equal to 7 ( finish sending 8 bytes)
movf Addr_Counter,W
xorlw 0x08
btfss STATUS,Z
goto loop_rd
;==========READ AND TRANSMIT DATA 8 BYTES END HERE==============
;==========COMMAND FOOTER==========
movlw 0x0D ;send data 0x0F into the buffer
call addPCbuffer
;==========COMMAND FOOTER==========
call resetPCbuffer
bsf TX_Flag,TX2REMOTE ; this is flag usart module to start transmit
;==========Transmit the buffer=====
;reload the timer begin here
;DEBUGGING PURPOSE WITH 200MS, FOR SEEING THE NEXT STATE IS RUNNING ON HARDWARE
movlw .2 ;test with 200 milliseconds
BANKSEL LEDTimer ;Init the counter
movwf LEDTimer ;to 2 ( 200milliseconds )
;DEBUGGING PURPOSE WITH 200MS, FOR SEEING THE NEXT STATE IS RUNNING ON HARDWARE
;reload the timer end here
incf State,1
return
;STATE 2 END
;===========================================================================================
;===========================================================================================
;STATE 3 BEGIN
;check_byte
;4.When 8 bytes are received from IR-TESTER check if all swapped bytes match with 8 bytes previously read from eeprom
;If you save all 8 bytes received overwrite previous data on eeprom with new data, toggle led ON-OFF-ON-OFF or OFF-ON-OFF-ON
;5.Repeat procedure 3-4 for the next address ie. address 0x08,0x10,0x18 and so on.
check_byte
;wait for 200ms before checking 8 bytes data begin here
movf LEDTimer,w ;for every 200 milliseconds, it sets on initialization
btfss STATUS,Z ;check the counter if it's already zero
return
;test with 200 ms before checking 8 bytes data end here
;=======================CHECK RECEIVED BYTE AND BLINK LED BEGIN HERE=========
BANKSEL RX_Flag
btfss RX_Flag,EOF_FROM_REMOTE ;check RX_Flag
goto no_rx_flag ;do this if RX_Flag is not set
goto rx_flag_set ;do this if RX_Flag is set
no_rx_flag
;DEBUG
;bsf LED_Standby,0
;DEBUG
decf State,1
return
rx_flag_set
;==========READ AND COMPARE DATA 8 BYTES AND WRITE RECEIVED DATA TO EEPROM==BEGIN HERE==============
movlw .0
movwf Addr_Counter
call resetPCbuffer ;reset the pointer of PCbuffer into the first byte
read_compare
;data from call readPCbuffer is stored in W register
movf Addr_Counter,W
movwf nTheEEAddress ;set the address equal to Addr_Counter
call eeRead ;read data from the address from eeprom
;SWAP READING RESULT FROM EEPROM
swapf nTheEEData,1
;READ FROM BUFFER
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
;READ FROM BUFFER
;store data from buffer to Swap_data
movwf Swap_data
;COMPARE BETWEEN nTheEEData with W register ( from PCbuffer)
xorwf nTheEEData
;Check the comparison match with status register, is it zero ? zero means match
btfss STATUS,Z
goto invalid_byte
goto valid_byte
invalid_byte
;resend the bytes again
decf State,1
return
valid_byte
;SAVE SWAPPED BYTE
;eeprom address
movf Addr_Counter,W
movwf nTheEEAddress
;eeprom data
;movwf Swap_data
movf Swap_data,W
movwf nTheEEData
call eeWrite
;SAVE SWAPPED BYTE
incf Addr_Counter,f
;=================check if address counter is equal to 7 ( finish sending 8 bytes)
movf Addr_Counter,W
xorlw 0x08
btfss STATUS,Z
goto read_compare
;BLINK LED ON-OFF-ON-OFF
bsf LED_Flag,0
;==========READ AND COMPARE DATA 8 BYTES AND WRITE RECEIVED DATA TO EEPROM==BEGIN HERE==============
;reload the timer begin here
;DEBUGGING PURPOSE WITH 200MS, FOR SEEING THE NEXT STATE IS RUNNING ON HARDWARE
movlw .2 ;test with 200 milliseconds
BANKSEL LEDTimer ;Init the counter
movwf LEDTimer ;to 2 ( 200milliseconds )
;DEBUGGING PURPOSE WITH 200MS, FOR SEEING THE NEXT STATE IS RUNNING ON HARDWARE
;reload the timer end here
incf State,1
return
;STATE 3 END
;=======================================================================================================
;Repeat procedure 3-4 for the next address ie. address 0x08,0x10,0x18 and so on..
;=================check if address counter is equal to 7 ( finish sending 8 bytes)
incf Addr_Counter,f // counter evoluate betwwen 0 to 7 inside each bloc of 8 bytes
btfss Addr_Counter, 3 ; //test bit3 =8
goto read_compare
movlw 0x8
addwf Add_Counter,f ; reinit at next adresse modulo 8
btfss STATUS,Z ; if 248+8=256 =>0 because byte size
goto read_compare
;BLINK LED ON-OFF-ON-OFF
bsf LED_Flag,0
;State3
....
movf Addr_Counter,w ; adresse for EEPROM
Andlw 0x07 ; Mask to keep only base adresse 0 to 7
result in W
so use it for adressing data in PCBuffer
.....
;=================check if address counter is equal to 7 ( finish sending 8 bytes)
incf Addr_Counter,f ; Addr_Counter (masked) evolute betwwen 0 to 7 inside each bloc of 8 bytes for PCbuffer adress, not for eeprom adress
btfss STATUS,Z ; if 255+1 =>256 =>0 because byte size for aAddr_counter
goto read_compare
;BLINK LED ON-OFF-ON-OFF
bsf LED_Flag,0
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?