CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

EEprom sequential read - working!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Joshua Lai



Joined: 19 Jul 2004
Posts: 42
Location: Malaysia, PJ

View user's profile Send private message Send e-mail

EEprom sequential read - working!
PostPosted: Tue Sep 20, 2005 7:40 pm     Reply with quote

I tried writing my own program to write and read eeprom, it is working !!

Quote:

#include <16F876.h>
#use delay(clock=20000000)
#use i2c(master,sda=PIN_C4,scl=PIN_C3)
#fuses hs,noprotect,nowdt,nolvp
#byte PORTB=6

int a, r;

main()
{
output_float(PIN_C3); //initialize eeprom
output_float(PIN_C4);

r=0;
set_tris_b(0);
portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);

i2c_start();
i2c_write(0xA0); //control write
i2c_write(0x00); //address (max 7FF8)
i2c_write(0x00);
i2c_write(0x01); //data (max page 64)
i2c_write(0x02);
i2c_write(0x04);
i2c_write(0x10);
i2c_write(0x20);
i2c_write(0x40);
i2c_write(0x80);
i2c_stop();
delay_ms(1000);

i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1); //control read

for(a=0;a<8;a++)
{ r = i2c_read();
portb=r; delay_ms(1000);
}

portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);

}


What I actually need to do is abitrary waveform generation. I need to store and read large amount of data in the eeprom, where time accuracy (sampling rate) is very important, fast is important also. So I have to count how much time PIC spent to read the eeprom.

Instead of using the built in driver 24256, I write my own program to read the eeprom. I found that I save at least hundred lines of assembly code.

But I don't really understand the assembly code, does i2c_read() same as sequential read in the eeprom datasheet?

I can also read out the eeprom data using hyperterminal (through PIC). But how can I use hyperterminal to write the eeprom? Because my icprog 1.04 showing error when verifying the eeprom. Type in the data on hyperterminal one by one is too slow.
Joshua Lai



Joined: 19 Jul 2004
Posts: 42
Location: Malaysia, PJ

View user's profile Send private message Send e-mail

Software or Hardware i2c
PostPosted: Fri Sep 23, 2005 11:07 pm     Reply with quote

PIC 16F876, PCM compliler 2.734

I found that I can use other pins for i2c as well! Previously I thought I can only use pin C3 and C4. What actually hardware i2c and software i2c? What advantages of using hardware or software i2c?

Now I understand that i2c_read(0) is without ACK, i2c_read(1) is with ACK.

I use PIC and hyperterminal to read the eeprom and found all the data inside is correct, although ic-prog failed to verify.

How fast can I read the eeprom to hyperterminal without error? I read the assembly code and found that the PIC will loop until some bit is set, so how to determine about how long to read the eeprom?
Joshua Lai



Joined: 19 Jul 2004
Posts: 42
Location: Malaysia, PJ

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 28, 2005 9:57 pm     Reply with quote

Quote:
#include <16F876.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#byte PORTB=6
#include <24256.C>

int i,d; long a;

main()
{
d=0;a=0;
set_tris_b(0);
portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);

init_ext_eeprom();

delay_ms(1);

write_ext_eeprom(0,0x02);
d = read_ext_eeprom(0);
portb=d; delay_ms(1000);


for(i=0;i<4;i++) //Write and read 1000 times
{
for(d=0;d<250;d++)
{
write_ext_eeprom(a,d);
d = read_ext_eeprom(a);
portb=d;
a=a+1;
}
}

portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);


for(a=0;a<30000;a++) //Read 30000 times
{
d = read_ext_eeprom(a);
portb=d;

}

portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);

i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1); //Sequential read 60000 times

for(a=0;a<60000;a++)
{ d = i2c_read();
portb=d;
}

portb=0x01; delay_ms(1000);
portb=0x00; delay_ms(1000);

}


I tried to measure the time for write/read using the 24256.c driver, and also the sequential read time using i2c directly.

Quote:

Write/Read Read Sequential Read
Cycles 1000 30000 60000
Time(s) 5 18 6
Time(us) 5000 600 100
for 1 cycle



I just looked at the LED and pressed the stopwatch, how to measure more accurately?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 29, 2005 6:06 am     Reply with quote

Toggle a pin and measure with an oscilloscope.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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