Siguiendo con el tema de las patillas A0, A1, A2,A3 que quedo pendiente con Fenix_in.
Pues te soy sincero que he leido casi todos los data sheets de las memorias EEprom y en ninguna he visto que las patillas A0, A1, A2,A3 se han para cambiar la direccion del esclavo si he leido que se usan para direccionar la memoria mas alla de los 16kbits y que en el data sheet de las 24Cxx que van de la C01 a la C16 dice lo siguiente:
Codigo:
8.4 A0, A1, A2
The A0, A1 and A2 pins are not used by the 24XX16.
They may be left floating or tied to either VSS or VCC.
y tambien dice:
Codigo:
3.6 Device Addressing
A control byte is the first byte received following the
Start condition from the master device (Figure 3-2).
The control byte consists of a four-bit control code.
For the 24XX16, this is set as ‘1010’ binary for read
and write operations. The next three bits of the control
byte are the block-select bits (B2, B1, B0). They are
used by the master device to select which of the eight
256 word-blocks of memory are to be accessed.
These bits are in effect the three Most Significant bits
of the word address. It should be noted that the
protocol limits the size of the memory to eight blocks
of 256 words, therefore the protocol can support only
one 24XX16 per system.
The last bit of the control byte defines the operation to
be performed. When set to ‘1’, a read operation is
selected. When set to ‘0’, a write operation is selected.
Following the Start condition, the 24XX16 monitors the
SDA bus checking the device type identifier being
transmitted and, upon receiving a ‘1010’ code, the
slave device outputs an Acknowledge signal on the
SDA line. Depending on the state of the R/W bit, the
24XX16 will select a read or write operation
Bueno no se quien tenga la razon si Cekit o la data Sheet
en fin ojala podamos desenmarañar este asunto. Hasta pronto.
Bueno el frecuencimetro "casi" funciona, es decir que funciona bien hasta los 65kHz, esto no es suficiente ni de coña, yo creo que esto se debe al desbordamiento de la variable que contiene la frecuencia. A ver si alguien que conozca bien como funciona el ccs me lo puede confirmar. Yo se el tamaño de las variables en c++, pero en ccs no lo tengo mu claro... ahi va el codigo. De momento esta hecho para un 16f876 pero tiene que ser para un 16f877, con cambiar el include y poca cosa mas ya funcionara.
Yo opino como tu Radon, a ver si alguien nos explica la forma de poderlo hacer con una eeprom externa si es que se puede.
Codigo:
#include <16f876.h>
#use delay(clock=4000000)
#define use_portb_lcd
#include <lcd.c>
#byte port_a=5
#byte port_b=6
#byte port_c=7
#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD
static float a=0;
#int_timer0
void timer()
{
static byte timer_0_count=0;
if (timer_0_count<1)timer_0_count++;
else
{
timer_0_count=0;
a=((GET_TIMER1()*8)/1000);
lcd_gotoxy(0,1);
printf(lcd_putc,"f %03.1f KHz",a);
a=0;
set_timer1(0);
}
}
void main()
{
set_tris_a(0x1F);
set_tris_b(0);
set_tris_c(0xFF);
SETUP_TIMER_1(T1_EXTERNAL_SYNC);
set_timer1(0);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256); // interrupcion cada 64ms*2=128ms
set_timer0(0);
enable_interrupts(int_timer0);
enable_interrupts(global);
lcd_init();
while(1)
{
}
}
A ver, ok funciona asi, supongamos que limitamos la memoria a 30 datos, la idea es q cada vez q un dato sea recibido, sea enviado a una posicion "buffer" de RAM, el programa kedaria de esta forma (mas o menos)
Codigo:
indf equ 00h ;IND0
fsr equ 04h ;FSR
txbf_0 equ 10h ;Direccion ilustrativa de principio de buffer
txbf_29 equ 2Eh ;Ultima posicion de memoria (para 30 datos I2C)
incio
;rutina de inicializacion y preparacion de puertos y otras configuraciones
rcv_dt
;receptor de datos
;Esta rutina seria la encargada de recibir los datos y colocarlos en el buffer usando direccionamiento
;indirecto, usando este metodo, el proceso es muy rapido.
save_ram movlw txbf_0 ;Apunta a la 1ra posicion de RAMbuffer
movwf fsr
nx_dt call rcv_dt ;Lee el bus
movf rxdata, w ;Carga los datos en el buffer
movwf indf ;y los envia a la direccion apuntada por el FSR
incf fsr, f ;Verifica limite
movf fsr, w
xorlw txbf_29+1 ;Verifica si completo los 30 datos
btfss status, z
goto nx_dt ;NO: Continua con la sig lectura
return ;SI: Termina el programa
Ahora, este codigo tiene como condicion q se deben recibir los 30 datos, una buena idea seria hacer "pooling" al registro q maneja el stop bit, al recibirlo entonces se saldria de la rutina y se iria a otra para mostrar los datos o para guardar los datos en la memoria serial