コード例 #1
0
ファイル: main.c プロジェクト: gjoosen/Microcontrollers
void write_data(int row, int column){
	twi_start();
	twi_tx(0xE0);		// Display I2C address + R/W bit
	twi_tx(row);	// Address
	twi_tx(column);  //column
	twi_stop();
}
コード例 #2
0
void write_data(unsigned char adress,unsigned char data)
{
	twi_start();
	twi_tx(0xE0);	// Display I2C addres + R/W bit
	twi_tx(adress);	// Address
	twi_tx(data);	// data
	twi_stop();
}
コード例 #3
0
ファイル: main.c プロジェクト: gjoosen/Microcontrollers
void twi_clear(void){
	int i = 0x00;
	for(; i <=0x0E; i += 0x02){
		twi_start();
		twi_tx(0xE0);
		twi_tx(i);
		twi_tx(0x00);
		twi_stop();
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: RD125632/Microcontrollers
void twi_data_inverse(PATTERN_STRUCT pattern[]) //geeft pattern weer (inverted) nog niet getest!
{
	twi_start();
	twi_tx(0xE0);
	for (int i = 0; i < 8; i++)
	{
		twi_tx(pattern[i].address);
		twi_tx(pattern[i].data |~(0xFF));
	}
	twi_stop();
}
コード例 #5
0
ファイル: main.c プロジェクト: RD125632/Microcontrollers
void twi_data(PATTERN_STRUCT pattern[]) //geeft een simpele pattern weer
{
	twi_start();
	twi_tx(0xE0);
	for (int i = 0; i < 8; i++)
	{
		twi_tx(pattern[i].address);
		twi_tx(pattern[i].data);
	}
	twi_stop();
}
コード例 #6
0
ファイル: main.c プロジェクト: gjoosen/Microcontrollers
int main( void )
 
{
	
	twi_init();		// Init TWI interface

	// Init HT16K22. Page 32 datasheet
	twi_start();
	twi_tx(0xE0);	// Display I2C addres + R/W bit
	twi_tx(0x21);	// Internal osc on (page 10 HT16K33)
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xA0);	// HT16K33 pins all output
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xE3);	// Display Dimming 4/16 duty cycle
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0x81);	// Display OFF - Blink On
	twi_stop();

	twi_clear();

		play_fill_animation();
		clear_rows();
	
	return 1;
	}
コード例 #7
0
void twi_init(void)
/* 
short:			Init AVR TWI interface and set bitrate
inputs:			
outputs:	
notes:			TWI clock is set to 100 kHz
Version :    	DMK, Initial code
*******************************************************************/
{
	TWSR = 0;
	TWBR = 32;	 // TWI clock set to 100kHz, prescaler = 0
	// Init HT16K22. Page 32 datasheet
	twi_start();
	twi_tx(0xE0);	// Display I2C addres + R/W bit
	twi_tx(0x21);	// Internal osc on (page 10 HT16K33)
	twi_stop();
	
	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xA0);	// HT16K33 pins all output
	twi_stop();
	
	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xE3);	// Display Dimming 4/16 duty cycle
	twi_stop();
	
	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0x81);	// Display OFF - Blink On
	twi_stop();
	
}
コード例 #8
0
ファイル: twi.c プロジェクト: nishantP-10/WSNS15IRFence
static int8_t twi_point(uint8_t addr, uint8_t reg)
{
    uint8_t len = 0;
    msg_buf[len++] = addr << TWI_ADR_BITS;
    msg_buf[len++] = reg;
    return twi_tx(msg_buf, len);
}
コード例 #9
0
ファイル: main.c プロジェクト: RD125632/Microcontrollers
int main( void )
/* 
short:			main() loop, entry point of executable
inputs:			
outputs:	
notes:			Looping forever, trashing the HT16K33
Version :    	DMK, Initial code
*******************************************************************/
{
	twi_init();		// Init TWI interface

	twi_start();
	twi_tx(0xE0);
	twi_tx(0x00);
	for(int i = 0; i < 16; i++)
	{
		twi_tx(0x00);
	}
	twi_stop();
	DDRA = 0x00; //input open on port A
	index = 0;

	while (1)
	{
		wait(750);
		if(PINA & 0x01)
		{
			twi_data(downey);
		}
		else if(PINA & 0x02)
		{
			twi_data3();
		}
		else if(PINA & 0x04)
		{
			twi_data_inverse(smiley);
		}
		else
		{
			twi_data(smiley);
			index = 0;
		}
	}

	return 1;
}
コード例 #10
0
ファイル: main.c プロジェクト: RD125632/Microcontrollers
void twi_data3() //geeft animatie weer (brainfart pattern)
{
	twi_start();
	twi_tx(0xE0);

	for (int i = 0; i < 8; i++)
	{
		twi_tx(brainfart[i + index * 8].address);
		twi_tx(brainfart[i + index * 8].data);
	}
	index++;
	if(index > 4)
	{
		index = 3;
	}
	twi_stop();
}
コード例 #11
0
ファイル: twi.c プロジェクト: obulpathi/avr
int twi_tx_slave_address(unsigned char address, unsigned char mode) 
{
	// transmit slave address and mode.
	twi_tx(address | mode);
	if ((TWSR & 0xF8) != TWI_TX_SL_ADD_SUCESS)
	      return 1;
	      
	return 0;
}
コード例 #12
0
ファイル: twi.c プロジェクト: nishantP-10/WSNS15IRFence
int8_t twi_write(uint8_t addr, uint8_t reg, uint8_t val)
{
    uint8_t len = 0;

    msg_buf[len++] = addr << TWI_ADR_BITS;
    msg_buf[len++] = reg;
    msg_buf[len++] = val;

    return twi_tx(msg_buf, len);
}
コード例 #13
0
ファイル: twi.c プロジェクト: nishantP-10/WSNS15IRFence
/* NOTE: multi-byte reads (using hw auto-incrementing of
 * register address) is not supported by this function
 * deliberately: it does not work -- only one byte is
 * returned. An additional issue is that an extra '0x3d'
 * (read command) byte is returned ('echoed') before
 * the actual reply byte -- we work around this here. */
int8_t twi_read(uint8_t addr, uint8_t reg, uint8_t *val)
{
    int8_t rc;
    uint8_t len = 0;
    uint8_t val_buf[2] = {0}; /* workaround for garbage byte */

    ASSERT(val);

    rc = twi_point(addr, reg);
    if (rc != NRK_OK) {
        LOG("ERROR: failed to set read ptr\r\n");
        return rc;
    }

    msg_buf[len++] = (addr << TWI_ADR_BITS) | (1 << TWI_READ_BIT);

    /* The example in the datasheet (and in sparkfun) sends the
     * count after the read req, but this seems non-standard. It
     * does not seem to make any difference. The auto-incremented
     * reads do not work in either case. */
    /* msg_buf[len++] = count; */

    rc = twi_tx(msg_buf, len);
    if (rc != NRK_OK) {
        LOG("ERROR: read req failed\r\n");
        return rc;
    }

    /* We want only one byte, but an extra byte is returned, hence len = 2 */
    rc = TWI_Get_Data_From_Transceiver( val_buf , 2 );
    if (!rc) {
        LOG("ERROR: failed to read data\r\n");
        return NRK_ERROR;
    }

    *val = val_buf[1];
    LOG("read: "); LOGP("0x%x \r\n", *val);

    return NRK_OK;
}