Hola.
Os indico lo que hice:
Codigo:
#include <16F876.h>
#use fast_io(A)
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT, NOWRT
#include <2402.c> // SDA=PIN_C4 , SCL = PIN_C3
#include <lcd_c.c>
void main()
{
int dato1,dato2,dato3;
EEPROM_ADDRESS direccion;
init_ext_eeprom();
lcd_init();
dato1 = 2; //Codigo secreto correcto (2)
dato2 = 9; //Código incorrecto (9)
direccion = 100;
while(1)
{
lcd_putc("f"
;
if(input(PIN_A0))
{
write_ext_eeprom(direccion,dato1); //Grabación del dato correcto (2)
delay_ms(1000);
}
if(input(PIN_A1))
{
write_ext_eeprom(direccion,dato2); //Grabación de un dato incorrecto (9)
delay_ms(1000);
}
dato3 = read_ext_eeprom(direccion);
if (dato3==2) //¿El código de la tarjeta es 2?
{
lcd_gotoxy(1,1);
printf(lcd_putc,"Codigo OK"
;
output_high(PIN_C0); //Abre puerta
delay_ms(2000);
output_low(PIN_C0);
}
else
{
lcd_gotoxy(1,1);
printf(lcd_putc,"Codigo falso"
;
delay_ms(2000);
}
}
}
Los pines de la tarjeta SLE 4442 son los siguientes:
1: VCC ---> a 5V
2: RST
3: CLK (SCL) ---> a RC3 mediante pullup
4: N.C.
5:GND
6: N.C.
7: I/O (SDA) ---> a RC4 mediante pullup
8:N.C.
Un saludo
Hola LordLafebre.
Me miro más detenidamente el fichero 2402.c que por si no tienes instalado el CCS te lo pego.
Codigo:
///////////////////////////////////////////////////////////////////////////
//// Library for a MicroChip 24LC02B configured for a x8 org ////
//// ////
//// init_ext_eeprom(); Call before the other functions are used ////
//// ////
//// write_ext_eeprom(a, d); Write the byte d to the address a ////
//// ////
//// d = read_ext_eeprom(a); Read the byte d from the address a ////
//// ////
//// b = ext_eeprom_ready(); Returns TRUE if the eeprom is ready ////
//// to receive opcodes ////
//// ////
//// The main program may define EEPROM_SDA ////
//// and EEPROM_SCL to override the defaults below. ////
//// ////
//// Pin Layout ////
//// ----------------------------------------------------------- ////
//// | | ////
//// | 1: NC Not Connected | 8: VCC +5V | ////
//// | | | ////
//// | 2: NC Not Connected | 7: WP GND | ////
//// | | | ////
//// | 3: NC Not Connected | 6: SCL EEPROM_SCL and Pull-Up | ////
//// | | | ////
//// | 4: VSS GND | 5: SDA EEPROM_SDA and Pull-Up | ////
//// ----------------------------------------------------------- ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996, 2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#endif
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS BYTE
#define EEPROM_SIZE 256
void init_ext_eeprom() {
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
BOOLEAN ext_eeprom_ready() {
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xa0); // then the device is ready.
i2c_stop();
return !ack;
}
void write_ext_eeprom(BYTE address, BYTE data) {
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(address);
i2c_write(data);
i2c_stop();
}
BYTE read_ext_eeprom(BYTE address) {
BYTE data;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(address);
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
return(data);
}
La verdad que cuando lo probé lo hice tal cual está y funcionó.
Hola:
Bueno, aqui pongo algo de lo que entendi, lo que no me quedo claro es:
7-Leer el valor de I/O y almacenarlo en el micro.
como puedo leer...?
por lo otro hice algo como esto, la conexion esta asi:
SLE PIC
CLK----BO
I/O-----B1
RST-----B2
Codigo:
"Smart Cards
i var byte
PORTB=0 "Encero el puerto B
high portb.2 "rst en 1 (1)
high portb.0:pause 50: low portb.0 "pulso de 50 ms para clk (2)
low portb.2 "rst en 0 (3)
high portb.0:pause 50: low portb.0 "pulso de 50 ms para clk (4)
"-
"leer el valor de I/O (5)
"-
for i=0 to 31
high portb.0 "Volver al punto 6 32 veces
pause 50
low portb.0
pause 50
next i
low portb.0
low portb.2
Ruego un poquito de paciencia...
con algo como esto no me he metido nunca...
Y el data me marea sinceramente
, luego del mensaje tuyo Pikman me quedaron claras algunas cosas...
Gracias Ariel por la paciencia
Hola LordLafebre, primera ves que posteo en PICBasic
y espero me entiendas, luego de que le das el pulso de reloj (flanco ascendente) a la tarjeta, revisas el estado del pin I/O que seria la entrada de datos, según el dato almacenado en la tarjeta será el estado en que se encuentre I/O, en este primer pulso tendrás el D0 del primer byte, al segundo pulso D1 del primer byte y así sucesivamente asta completar los 4 bytes o 32 pulsos:
Codigo:
PORTB=0 "Encero el puerto B
high portb.2 "rst en 1 (1)
high portb.0:pause 50: low portb.0 "pulso de 50 ms para clk (2)
low portb.2 "rst en 0 (3)
for i=0 to 31
high portb.0 "Volver al punto 6 32 veces
----
AQUI VERIFICAS EL ESTADO DE I/O
SI LO ENTERIOR ES 1 PONES EN HIGH BIT.7 DEL BYTES4
BORRAS EL CARRY DEL STATUS
ROTAS A LA DERECHA 1 POSICION BYTE4
ROTAS A LA DERECHA 1 POSICION BYTE3
ROTAS A LA DERECHA 1 POSICION BYTE2
ROTAS A LA DERECHA 1 POSICION BYTE1
----
pause 50
low portb.0
pause 50
next i
low portb.0
low portb.2
Espero me puedas entender, ya que como sabe de Basic no calo nada 
Un saludo, suerte
Atte. CARLOS