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

How to read eeprom card (telephone card) using PIC?

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



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

How to read eeprom card (telephone card) using PIC?
PostPosted: Thu Jan 06, 2005 1:41 am     Reply with quote

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

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

PostPosted: Thu Jan 06, 2005 7:48 am     Reply with quote

Those are probably smart cards.
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 06, 2005 10:03 am     Reply with quote

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

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

PostPosted: Thu Jan 06, 2005 11:20 am     Reply with quote

http://www.sspsolutions.com/files/Introduction_to_Smart_Cards.pdf

Here is some code to read using a basic stamp

http://www.elecdesign.com/Articles/Index.cfm?AD=1&ArticleID=6229
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