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.

Eeprom write problem in 16f676

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Visit site
Activity points
1,763
Hi
i wrote following software for writing data in EEPROM of 16f676.
same program is given in data sheet. (i just modified little bit for inserting mem_add register and mem_data register)
every thing is fine but nothing is written in "EECON2"

i selected right bank(1) for writing in eecon2 but nothing happens.

can anybody tell me the reason?
 

Attachments

  • write_data.txt
    618 bytes · Views: 86

Hi,

Your code looks about right, but it needs time to complete the eeprom write, its relatively slow.

Much easier and your code is more portable if you use banksel ( the assembler works out the registers bank location, not you)

This is my 16F code modified for the 676 chip but have not been able to test fully.

Code:
WRITE_DATA
	banksel 0				; bank 0
	MOVF	MEM_DATA,W		;memory data register moves to wreg
	banksel	EEDAT
	movwf	EEDAT			; load Chours to EEdata
	banksel 0
	MOVF	MEM_ADD,W		 ;memory address register moves to wreg
	banksel	EEADR
	movwf	EEADR	
	banksel	EECON1
	bsf		EECON1,WREN		; enable write
	bcf		INTCON,GIE		; disable all ints
	movlw	0x55			;
    movwf	EECON2			; init write sequence
	movlw	0xAA			; using 2 instructions	
	movwf	EECON2			;
	bsf		EECON1,WR		; write data
	bsf		INTCON,GIE		; turn ints back on
	banksel 0

wd01 btfss	PIR1,EEIF		; is int bit on ie WRTDONE
	goto	wd01			; if done continue
	bcf		PIR1,EEIF		; reset interupt
 	banksel	EECON1
	bcf		EECON1,WREN		; disables write
	banksel 0				; select bank0
	return
 
thanks wp100 but please clear 1 thing i couldnt get that.
u used following instructions i really didnt understand them. please tell me about them
banksel EEDAT
banksel EECON1

does it mean that it selects relative register bank itself? means it selects the bank, in which, register exits?
 

thanks wp100 but please clear 1 thing i couldnt get that.
u used following instructions i really didnt understand them. please tell me about them
banksel EEDAT
banksel EECON1

does it mean that it selects relative register bank itself? means it selects the bank, in which, register exits?



Hi,

First thing banksel , like Org, is a Directive not an Instruction.

Directives are used by the Assembler and not actually compiled into machine code like the instructions - see Mplabs Help for full details.

When you use banksel followed by the system register you are about to use, it causes the system to select the ram Bank for that register.
The system will stay in that Bank until you change it, just the same as setting the Status bits like you used.

While you can use banksel PORTA to go in to bank 0 , its just easier to use banksel 0. Thats the only bank you can specify directly.

Apart from being easier to use and read in your code, it also means when you move to larger chips that have the system registers spread over 4 or more ram banks, when using banksel it will automatically find the correct bank for your code, even if they have moved into a different bank.
 
thanks alot sir wp100
i need some more help sir
in 16fxx,i want to add 2 numbers and get the result in decimal (that is equivalent to DAW in 18fxx MCU)
please send me the code.
i will b thankful to you
 

thanks alot sir wp100
i need some more help sir
in 16fxx,i want to add 2 numbers and get the result in decimal (that is equivalent to DAW in 18fxx MCU)
please send me the code.
i will b thankful to you


Hi,

DAW is not an instruction I have used, but see this link which might give you some helpful info that you can apply to your 16F code.
https://www.microchip.com/forums/m62642.aspx

You say you want to Add 2 numbers, but are they bcd or hex ?

When you say get the result in Decimal , do you mean in BCD or a three digit ascii decimal format; assuming you want to only add up to 256 decimal ?
 

numbers are in hex and result is may be in 3 digits like:
23H+AAH = CDH = 205D
I WILL PUT BOTH NMBERS IN 2 RAM ADDRESSES AND RUN THE ROUTINE WHICH WILL ADD BOTH AND GIVE THE RESULT IN DECIMAL.
 

above posts show that how to convert binary or hex to BCD but i need something else sir.
in 8051 the code is as follows
mov 30h,#45h ; copy 45h to ram 30h
mov a,30h ; move the stored number in 30h to a
add a,#30H ; ADD WITH 30H (45h + 30h = 75h )
da a ; DECIMAL ADJUSTMENT now the result is = 117d

in want to do same thing in PIC16xx
which will be equivalent routine in PIC16xx


result is
 

above posts show that how to convert binary or hex to BCD but i need something else sir.
in 8051 the code is as follows
mov 30h,#45h ; copy 45h to ram 30h
mov a,30h ; move the stored number in 30h to a
add a,#30H ; ADD WITH 30H (45h + 30h = 75h )
da a ; DECIMAL ADJUSTMENT now the result is = 117d

in want to do same thing in PIC16xx
which will be equivalent routine in PIC16xx


result is


Hi,

If your 2 numbers are in hex then after adding them together you need to use a hex to bcd converter to produce the decimal result you want.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top