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
Guys,
How can I repeat this part of code for 31 times ?
The code below is checking from address 0x00 to 0x07, I want to reuse these codes for 0x08 to 0x10, and so on until 0xFF,
Any ideas will be appreciated,
Thank you
How can I repeat this part of code for 31 times ?
The code below is checking from address 0x00 to 0x07, I want to reuse these codes for 0x08 to 0x10, and so on until 0xFF,
Any ideas will be appreciated,
Thank you
Code:
;=======================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 valid_byte ;do this if RX_Flag is set
;=======================CHECK RECEIVED BYTE AND BLINK LED END HERE===========
no_rx_flag:
;DEBUG
bsf LED_Flag,0
;DEBUG
decf State,1
return
valid_byte
;test the first byte received see if it's 0x00
;DEBUG
;bsf PORTB,POWERLED
;DEBUG
call resetPCbuffer ;reset the pointer of PCbuffer into the first byte
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
xorlw 0x00 ;check the first byte if it's 0x00
btfss STATUS,Z
goto invalid_byte_1
goto valid_byte_1
invalid_byte_1
decf State,1
return
valid_byte_1
;DEBUG
;bsf LED_Flag,0
;DEBUG
;save data in PCbuffer into eeprom
movlw 0x00
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;save data in PCbuffer into eeprom
;=====read the second byte
xorlw 0x10 ;check the first byte if it's 0x00
btfss STATUS,Z
goto invalid_byte_2
goto valid_byte_2
invalid_byte_2
decf State,1
return
valid_byte_2
;save the second byte to eeprom
movlw 0x01
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;DEBUG
;bsf LED_Flag,0
;DEBUG
;check the next byte received
;check the second byte
xorlw 0x20
btfss STATUS,Z
goto invalid_byte_3
goto valid_byte_3
invalid_byte_3
decf State,1
return
valid_byte_3
;save the second byte to eeprom
movlw 0x02
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;check the next byte received
xorlw 0x30
btfss STATUS,Z
goto invalid_byte_4
goto valid_byte_4
invalid_byte_4
decf State,1
return
valid_byte_4
;save byte to eeprom
movlw 0x03
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;check the next byte received
xorlw 0x40
btfss STATUS,Z
goto invalid_byte_5
goto valid_byte_5
invalid_byte_5
decf State,1
return
valid_byte_5
;save byte to eeprom
movlw 0x04
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;check the next byte received
xorlw 0x50
btfss STATUS,Z
goto invalid_byte_6
goto valid_byte_6
invalid_byte_6
decf State,1
return
valid_byte_6
;save byte to eeprom
movlw 0x05
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;check the next byte received
xorlw 0x60
btfss STATUS,Z
goto invalid_byte_7
goto valid_byte_7
invalid_byte_7
decf State,1
return
valid_byte_7
;save byte to eeprom
movlw 0x06
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;check the next byte received
xorlw 0x70
btfss STATUS,Z
goto invalid_byte_8
goto valid_byte_8
invalid_byte_8
decf State,1
return
valid_byte_8
;save byte to eeprom
movlw 0x07
movwf nTheEEAddress
call readPCbuffer ;call readPCbuffer read each byte received in PCbuffer,
movwf nTheEEData ;data received from PIR
call eeWrite ;save w to eeprom
;BLINK LED ON-OFF-ON-OFF
bsf LED_Flag,