Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Masking

Status
Not open for further replies.

prean

New Member
hey guys, does anyone know how to mask an 1byte to 512 bytes in assembly? or is it even possible? or would it be better to mask 256bytes to 512 bytes? oh its for the PIC16f690

thanx:(
 
Masking omits certain parts of a given byte, it doesn't increase the byte count, your post makes no sense.
 
ok how can i increase the byte count? i wana increase the data byte size to 512bytes so i can write the data to sd-card
 
Just think of two 8 bit registers. If you like name them as “upper byte” & “lower byte”.
Just think they don’t have any values, both are zeros.

Now you increment the “lower byte” now it contains “1”.Now again increment it, now it contains “2” likewise if you increment 255 times the “lower byte” contains “255” if you increment at this stage its value becomes “00” because the maximum value that an 8 bit register can hold is 255.At this stage you need to increment the “upper byte” by one. Because your value is 256.

So for every 256 times the “upper byte” increment by one.

If you have “1” in the “upper byte” & “00” in the “lower byte” then the whole 16bit pair contains 256 value.
If you have “2” in the “upper byte” & “00” in the “lower byte” then the whole 16bit pair contains 512 value.

Do you understand how these number system works?
 
ok i understand what u saying there. see what im trying to do is basically transfer data from the PIC16F690 to an sd card.we jus writing to the card,not reading.but the data comes in at 1Byte at a time.and the sd card writes in 512bytes. i can store all the values in the data eeprom of the PIC16F690 and when it reaches 256bytes, increase to 512 bytes and the write to the card. do you maybe have any ideas about this? or any codes that i use? thank u so much for your help. much appreciated. i wrote out a code jus to see how the eeprom on the PIC works. jus a basic counter problem. i got sum advise from someone on the forum who edited my code. however after loading the edited code onto the pic, it outputs the orginal loaded data,and does not increment by itself like a counter sholud do.

i added the eeprom below:

#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

cblock 0x70
DATA_EE_ADDR
DATA_EE_DATA
dly0
dly1
EE_ADR
W_DATA
R_DATA
endc

org 0
nop

;; intialise output ports
banksel ANSEL
movlw 0x00
movwf ANSEL
banksel ANSELH
movlw 0x00
movwf ANSELH
banksel TRISC
movlw 0x00
movwf TRISC
;; movlw 0xF0
;; movwf DATA_EE_DATA
;; movlw 0x00
;; movwf DATA_EE_ADDR

; To WRITE into EEPROM
banksel EE_ADR
movlw 0x00 ; EE_ADDR
movwf EE_ADR ; move 0x00 into EE_ADR
movlw 0x03 ; Writes Hous data into EEPROM
movwf W_DATA ; Data to be written
call EE_WR ; Write routine for EE_Addr



; To READ from EEPROM
movlw 0x00 ; EE_ADDR
movwf EE_ADR ; move 0x00 into EE_ADR
call EE_RD ; Read EEPROM Addr 0
movwf R_DATA ; Write into Hyst High register

; -------------------------------------------------------------------------------------------------
;EE_WR EEPROM DATA WRITE SEQUENCE
; -------------------------------------------------------------------------------------------------
EE_WR
banksel EECON1 ; Select Bank of EECON1
btfsc EECON1,WR ; Wait for write
goto $-1 ; to complete
banksel EE_ADR ;
movf EE_ADR,W ;
banksel EEADR ; (0x10C) Select Bank of EEADR
movwf EEADR ; Data Memory Address to write
banksel W_DATA ;
movf W_DATA,W ; Register containing data to be stored
banksel EEDATA ; (0x10D)
movwf EEDATA ; Data Memory Value to write
bsf STATUS,RP0 ;
bcf EECON1,EEPGD ; Point to DATA memory
bsf EECON1,WREN ; Enable writes
bcf INTCON,GIE ; Disable INTs.
movlw H'55' ;
movwf EECON2 ; (0x18C) Write 55h
movlw H'AA' ;
movwf EECON2 ; (0x18C) Write AAh
bsf EECON1,WR ; Set WR bit to begin write
bsf INTCON,GIE ; Enable INTs.
bcf EECON1,WREN ; Disable writes
banksel PIR2 ;
btfss PIR2,EEIF ; Wait for interrupt flag to be set
goto $-1 ; Current line -1
bcf PIR2,EEIF ; Clear the EEWRITE interrupt flag
return ; return to caller

; -------------------------------------------------------------------------------------------------
; EE_RD EEPROM DATA READ SEQUENCE ;
; -------------------------------------------------------------------------------------------------
EE_RD ;
movf EE_ADR,W ;
banksel EEADR ;
movwf EEADR ; Data Memory Address to read
banksel EECON1 ;
bcf EECON1,EEPGD ; Point to Data memory
bsf EECON1,RD ; EE Read
banksel EEDATA ;
movf EEDATA,W ; W = EEDATA
banksel R_DATA ;
movwf R_DATA ; Move W into EE_BYTE
movf R_DATA,W
banksel PORTC
movwf PORTC
incf EE_ADR,f ; increment EE_Addr with 1
return ; Value now in W, to be used

; -------------------------------------------------------------------------------------------------
; WRITE routine to write data ;
; into EEPROM memory Hours ;
; -------------------------------------------------------------------------------------------------
WriteEE: ;
movwf W_DATA ; Writes Hous data into EEPROM
call EE_WR ; Write routine for EE_Addr
incf EE_ADR,f ; increment EE_Addr with 1
return ; return to caller

end
 
Try this it reads the first 256 locations in the EEPROM.

Code:
Main		movlw 	0x00 		; EE pointer
		movwf 	EE_ADR 		; 

Read_Loop	call	EE_RD		;
		movf 	R_DATA,W	;	
		movwf	PORTC		;
		call	Delay		;call a 1Sec delay		
		incfsz	EE_ADR,F	;	
		goto	Read_Loop	;
Wait_Here	goto	Wait_Here


EE_RD ;
		movf 	EE_ADR,W 	;
		banksel EEADR 		;
		movwf 	EEADR 		; Data Memory Address to read
		banksel EECON1 		;
		bcf 	EECON1,EEPGD 	; Point to Data memory
		bsf 	EECON1,RD 	; EE Read
		banksel EEDATA 		;
		movf 	EEDATA,W 	; W = EEDATA
		banksel R_DATA 		;
		movwf 	R_DATA 		; Move W into R_DATA 	
		return
 
Last edited:
Gayan, I see with the poster you are going to have to spoon feed him all the way. I was the one who helped him out on the EE_Read and EE_Write code. I did not modify his code, I gave him a copy of my code that does work. As for incrementing or whatever else he wants to do, he'll have to write the code himself.

I see you have a "Call Delay" instruction in there. He's going to mail you back now and complain that it doesn’t work.
 
Gayan, I see with the poster you are going to have to spoon feed him all the way. I was the one who helped him out on the EE_Read and EE_Write code. I did not modify his code, I gave him a copy of my code that does work. As for incrementing or whatever else he wants to do, he'll have to write the code himself.

I see you have a "Call Delay" instruction in there. He's going to mail you back now and complain that it doesn’t work.

I must very careful when posting replies when situations like this.I'm Sorry SPDCHK.
 
thank you guys for your help. it mean alot. i was just alil confused. but i think i understand now.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top