/*No I2C numero 0x96 tem um termometro tipo TMP100 da TI */
short letemp()
{
short Temp;
int k, i;
escreve_i2c(0,-1);
/* Fase 2: Le a temperatura (2 bytes) */
I22CONCLR = 0xff;
I22CONSET = 0x60;
k=2; Temp=0; i=1000;
do	{
	switch(I22STAT){	/* Terminou START; envia endereco */
		case 0x08: I22CONCLR=0x20;
		case 0x20: /* NACK do endreco: reenvia */
			I22DAT = ADDRTMP+1; /* Endereco i2c */
			I22CONCLR=8; i=1000; break;
		case 0x40:
			I22CONSET=4; I22CONCLR=8; i=1000; break;
/* Recebeu dado: Le dado */
		case 0x50: Temp = (Temp << 8) | I22DAT;
/* Ultimo dado: Envia STOP */
			if(!(--k)) I22CONSET=0x10;
			I22CONCLR=8; i=1000; break;
		}
	} while(k && --i);
return Temp;
}
/* Inicializa o canal 2 de I2C */
void ini_i2c(void)
{
PCONP |=0x04000080;	/* Liga energia do I2C0 e I2C2 */
PINSEL0 &= 0xffafffff;
PINSEL0 |= 0x00a00000;	/* Seleciona pinos do SDA2 e SCL2 */
I22CONCLR = 0xff;
I22CONSET = 0x40;	/* Habilita o I2C-2 um modo mestre */
I22SCLH   = 100;	/* Tempo alto do SCL	*/
I22SCLL   = 100;	/* Tempo baixo do SCL	*/
escreve_i2c(1,0x60);
}
Пример #3
0
static void
write_card(int off, char *buf)
{
	LCD_command(1);
	LCD_puts(INSCAR, sizeof(INSCAR));
	DPRINTF(INSCAR);
	while (FIO0PIN & (1 << 21));

	buf[0] = off;
	escreve_i2c(0xa0, buf, 17);
}
Пример #4
0
int main(void)
{
	unsigned char buffer[17]; // Where we are reading to
	buffer[16] = '\0'; // Terminating string
	int page = 0xa0;
	int offset = 0;

	init_timer0(); // LCD needs timer0 to function
	LCDinit(); // Initializing LCD
	ini_i2c(); // Initializing i2c

	/******************** MAIN LOOP *********************/
	while(1) {
		offset &= 0xff;
		buffer[0] = offset;
		escreve_i2c(page, buffer, 1); /* tell i2c we want to read from page + offset */
		if(le_i2c(page, buffer, 16)) { /* If we failed to read 16 bytes */
			LCDclear();
			LCDgoto(0, 0);
			LCDputs("Problema de leitura");
			LCDgoto(1, 0);
			LCDputs(buffer);
		} else {
			LCDgoto(0, 0); // Go to first line, first column
			LCDputs("Pg = ");
			LCDputchar(page + '0'); // Prints page number as char

			LCDgoto(0, 8); // Go to the second half of first line
			LCDputs("Of = ");
			LCDputchar(offset + '0'); // Prints offset as char

			LCDgoto(1, 0); // Fisrt column of the second line
			LCDputs(buffer); // Prints buffer
		}
	}

	return 0;
}
Пример #5
0
static void
read_card(int off, char *buf)
{
	LCD_command(1);
	LCD_puts(INSCAR, sizeof(INSCAR));
	DPRINTF(INSCAR);
	while (FIO0PIN & (1 << 21));

	DPRINTF("AQUI1\n");
	/* Depois de qualquer operacao efetua uma leitura */
	buf[0] = off;
	/* Escreve o offset (endereco no smcard) */
	escreve_i2c(0xa0, buf, 1);
	DPRINTF("AQUI2\n");

	/* Le 16 bytes a partir do offset */
	le_i2c(0xa0, buf, 16);
	buf[16] = '\0';
	DPRINTF("AQUI3\n");
	
	for (x = 0; x < 16; x++)
		PrByte(buf[x]);
}