Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can I repeat this part of code for 31 times ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
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

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,
 

use a for loop (in pseudo code)
start:
store 31 in a register
decrement register
...
code
...
get register value
decrement register value
compare register value with 0
goto start if register greater than 0
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top