eeprom

Subforum for the Matrix Online Courses, discuss the courses, highlight problems or suggest amendments

Moderator: Benj

Post Reply
juanlu
Posts: 8
Joined: Fri Sep 14, 2012 5:05 pm
Contact:

eeprom

Post by juanlu »

hi,

i am doing course of programming embeded pic, I have problem to write eeprom with assembler.
I have passed course programm to pic and does not work.

unsigned char counter;
asm{

movlw 0 // the first memory location
movwf _counter

next:
movff _counter, _eeadr // counter as address and data
movff _counter, _eedata

bcf _eecon1,7 // set access data memory
bcf _eecon1,6 // set EEPROM

bsf _eecon1,2 // enable wren

clrf _intcon // stop interrupts (if any)

movlw 0x55 // mandatory sequence
movwf _eecon2
movlw 0xAA
movwf _eecon2
bsf _eecon1,1

bcf _eecon1,2 // clear wren

wait:
btfsc _eecon1,1 // wait for bit 1 is zero
goto wait

incfsz _counter,1 // increment and skip if zero
goto next

movlw 0b11111110 // b0 to output
movwf _trisb

bsf _portb,0 // light LED0
}

Result light is set but memory does not change. It is allways FF.


Any idea about how to solve it? I have passed this programm to C and memory change according program.

Thanks.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: eeprom

Post by Enamul »

Hi,
You can find c code for reading and writing to and from EEPROM in the following post..
http://www.matrixmultimedia.com/mmforum ... ROM#p38249
Enamul
University of Nottingham
enamul4mm@gmail.com

juanlu
Posts: 8
Joined: Fri Sep 14, 2012 5:05 pm
Contact:

Re: eeprom

Post by juanlu »

thanks Enamul

my program translated to C is OK but not in assembler.
I am learning now and theoretically the assembler code works.

it seems that C variable counter is not known for assembler code.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Contact:

Re: eeprom

Post by JonnyW »

I do not know PIC assembler, but suggest you use 'counter' as an output to port B, not a fixed integer, to ensure this is being updated correctly. If the compiler did not recognise '_counter' it just would not compile and if it was not being incremented then the light would never light or would only loop once. Therefore I'd guess that the problem is not with _counter, but with some other part of the program.

You could try starting _counter at a non-zero value toensure it is looping correctly (and not just remaining at zero).

Try taking the C code equivalent and looking at the ASM generated for this. Add this ASM to your program and check this works. Then repeatedly strip this down until you are left with the program you have below. Starting with a program that works and breaking it into pieces is often an easier way to learn than starting with a blank page and building a new program.

Jonny

juanlu
Posts: 8
Joined: Fri Sep 14, 2012 5:05 pm
Contact:

Re: eeprom

Post by juanlu »

Thanks Jonny,

I have just located the problem and now program runs properly.

It was in chip configuration PIC MICRO CONFIGURATION (expert).
Options were ENABLE and it must be DISABLED according to learningn course. Then I change and everything ok.

Low voltage program must be DISABLED
Dedicated in circuit port must be DISABLED
Extended CPU must be DISABLED

I do not know exactly which one of these three options caused problem. Hope that once I advance in course can understand this issue.

Post Reply