|
|
View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
Write EEPROM |
Posted: Sun May 28, 2017 11:40 pm |
|
|
Hi
I would like to write an eeprom starting from address 00 to 0B, but
I found out, only address 00 until 03 were written into the eeprom.
How to make it write all this 12 addresses ?
Here is my code.
Code: |
#include <18F4550.h>
#DEVICE ADC=10
#fuses HSPLL,NOWDT,PROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#include <string.h>
#include <input.c>
#include <stdio.h>
#include <stdlib.h>
#include <usb_cdc.h>
#include "24256.c"
void read_string_eeprom(char *buffer, int16 start_addr, int8 no_chars)
{
int8 count;
for (count=0;count<no_chars;count++)
{
buffer[count]=read_ext_eeprom(start_addr++);
}
buffer[count]='\0';
}
void main()
{
char c;
int8 i ;
unsigned char d;
unsigned char key;
int8 buffer[100];
char m="A";
char n="Z";
char o="S";
char p="K";
usb_init_cs();
while (TRUE)
{
usb_task();
if (usb_cdc_kbhit())
{
c=usb_cdc_getc();
if (c=='\n') {putc('\r'); putc('\n');}
if (c=='\r') {putc('\r'); putc('\n');}
while(true)
{
ART:
d = usb_cdc_getc();
if(d=='W') // push A
{
while (key!=32) // push SPACE BAR to stop
{
if(usb_cdc_kbhit())
{key=usb_cdc_getc();}
{
init_ext_eeprom();
printf(usb_cdc_putc, "\n");
for(i = 0; i<3; i=i+4)
{
write_ext_eeprom(i, m);
write_ext_eeprom(i+1, n);
write_ext_eeprom(i+2, o);
write_ext_eeprom(i+3,p);
}
for(i = 0; i < 12; i=i+4 )
{
read_string_eeprom(buffer, i, 4);
printf(usb_cdc_putc,buffer);
printf(usb_cdc_putc,"\r");
}
}
} key=0; // to initialize 'key' not as SPACE BAR
}
}
}
}
}
|
|
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon May 29, 2017 12:21 am |
|
|
When do you think this will exit the for loop:
Code: | for(i = 0; i<3; i=i+4) |
Try
Code: | for(i = 0; i<12; i=i+4) |
Regards |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Mon May 29, 2017 12:52 am |
|
|
Hi alan,
Thanks it work!
Last edited by art on Mon May 29, 2017 1:00 am; edited 1 time in total |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon May 29, 2017 12:55 am |
|
|
You really think so?
for starts with i=0;
next round i=0+4 thus i= 4. Is this less than 3 or not? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|