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 support@ccsinfo.com

problem in read and write smart card with using PIC16F887

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



Joined: 03 Mar 2008
Posts: 8

View user's profile Send private message

problem in read and write smart card with using PIC16F887
PostPosted: Thu May 08, 2008 11:09 am     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 08, 2008 11:16 am     Reply with quote

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))
Guest








PostPosted: Thu May 08, 2008 11:46 am     Reply with quote

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??
CollegeStudent



Joined: 04 Feb 2009
Posts: 1

View user's profile Send private message

PostPosted: Wed Feb 04, 2009 11:48 am     Reply with quote

Did you get this to work?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 04, 2009 3:49 pm     Reply with quote

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.
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