View previous topic :: View next topic |
Author |
Message |
EricKoh1985
Joined: 03 Mar 2008 Posts: 8
|
problem in read and write smart card with using PIC16F887 |
Posted: Thu May 08, 2008 11:09 am |
|
|
i have a problem in read and write smart card with using PIC16F887 chip.
My smart card model is ST14C02C.
The datasheet can be find at http://www.datasheetcatalog.com/datasheets_pdf/S/T/1/4/ST14C02C.shtml
Since i do not have any sample code for this smart card, so i have try to modified some other I2C EEPROM's source code, but it does not work with my smart card.
Below is my circuit and source code.
Code: |
#include <16F887.h>
#include <stdio.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#include <2402.c> // EEPROM driver
#define hi(x) (*(&x+1))
//-----------------------------------
void write_word(int16 address, int16 data)
{
init_ext_eeprom();
write_ext_eeprom(address, data); // Write LSB
write_ext_eeprom(address+1, data >> 8); // Write MSB
}
//----------------------------------
int16 read_word(int16 address)
{
int16 retval;
init_ext_eeprom();
retval = read_ext_eeprom(address); // Read LSB
hi(retval) = read_ext_eeprom(address +1); // Read MSB
return(retval);
}
//----------------------------------
void main()
{
int8 data =0x02;
int16 address =0x19;
int16 value;
printf("Hello");
while (true)
{
write_word(address, data);
value = read_word(address);
if (value==0x02)
{
printf("value read = %ld \n\r", value);
}
}
}
|
circuit diagram link: http://www.imagehosting.com/show.php/1742009_1.JPG.html
In the circuit diagram, 24C02B is an I2C EEPROM
Hope can get some advice from you guys. Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 08, 2008 11:16 am |
|
|
Quote: | #define hi(x) (*(&x+1)) |
What is your compiler version ? If you have vs. 4.021 or later,
you must change the hi() macro to this:
Code: | #define hi(x) (*((int8 *)&x+1)) |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu May 08, 2008 11:46 am |
|
|
the code:
Quote: |
#define hi(x) (*((int8 *)&x+1))
|
does not work with my smart card.
i have a question would like to ask:
how can i read smart card's data thru I2C and display that data thru UART?? |
|
![](templates/subSilver/images/spacer.gif) |
CollegeStudent
Joined: 04 Feb 2009 Posts: 1
|
|
Posted: Wed Feb 04, 2009 11:48 am |
|
|
Did you get this to work? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 3:49 pm |
|
|
On this page,
http://www.ccsinfo.com/content.php?page=compexamples
it says that CCS includes a Smart Card example file with the compiler:
Quote: |
These are some of the additional libraries and examples included:
SIM/SMART Card - Access the contact and phone number information on a SIM/SMART card, commonly found on GSM/GPRS cell phones.
|
I looked in the Examples and Drivers directories and I can't find it.
If you own the compiler, I suggest that you email CCS support and
ask them if they can send you the file. Make sure to give them your
user Reference number so they know you own the compiler. |
|
![](templates/subSilver/images/spacer.gif) |
|