コード例 #1
0
ファイル: main.c プロジェクト: pedrovanzella/arm-smartcard
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;
}
コード例 #2
0
ファイル: main.c プロジェクト: williamlagos/serial
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]);
}