|
|
View previous topic :: View next topic |
Author |
Message |
Einly
Joined: 10 Sep 2003 Posts: 60
|
How to read eeprom card (telephone card) using PIC? |
Posted: Thu Jan 06, 2005 1:41 am |
|
|
I am using PIC 16f876 to read a telecard. I tried using i2c_read() to read it but the program hang. I suspect it is waiting for something to happen.
Below is my program:
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_C5
#define EEPROM_SCL PIN_C4
#endif
#include <16f876.h>
#use delay(clock=20000000)
#fuses hs, nowdt, nolvp, noprotect
#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,PARITY=N)
#byte PORTB=6
#byte PORTC=7
#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS byte
#define EEPROM_SIZE 256
void init_ext_eeprom();
void write_ext_eeprom(byte MSB_address, byte LSB_address, byte data);
byte read_ext_eeprom(byte MSB_address, byte LSB_address);
byte i;
void main()
{
byte MSB, LSB, data0;
byte result1;
byte b=0x53;
set_tris_b(0);
set_tris_c(0x84);
portc=0;
init_ext_eeprom();
output_high(PIN_B7);
delay_ms(1000);
output_low(PIN_B7);
do
{
printf("%x\n\r",b);
for(i=0;i<64;i++)
{
result1=read_ext_eeprom(0,i);
printf("%x \r",result1);
delay_ms(300);
}
}while(1);
}
void init_ext_eeprom() {
output_float(eeprom_scl);
output_float(eeprom_sda);
}
void write_ext_eeprom(byte MSB_address, byte LSB_address, byte data) {
i2c_start();
i2c_write(0xa0);
i2c_write(MSB_address);
i2c_write(LSB_address);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
byte read_ext_eeprom(byte MSB_address,byte LSB_address)
{
byte data2;
i2c_start();
i2c_write(0xa0);
i2c_write(MSB_address);
i2c_write(LSB_address);
i2c_start();
i2c_write(0xa1);
data2=i2c_read(0);
i2c_stop();
return(data2);
}
I connect PIN C5 to SDATA of the telecard, PIN C4 to the SCLK of the telecard. Vcc of the telecard to 5V and GND to 0V.
My I know what should I do to correct my mistake? Can I use this method? Is there any address on the telecard that could not be read?
Thanks _________________ Einly |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jan 06, 2005 7:48 am |
|
|
Those are probably smart cards. |
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
|
Posted: Thu Jan 06, 2005 10:03 am |
|
|
not knowing the cards, do you have your pull up resistors on the SDA and SCL lines? .. 3.3K or so |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
|
|
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
|