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.
eeprom
Moderator: Benj
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: eeprom
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
You can find c code for reading and writing to and from EEPROM in the following post..
http://www.matrixmultimedia.com/mmforum ... ROM#p38249
Re: eeprom
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.
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.
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: eeprom
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
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
Re: eeprom
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.
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.