Ejemplo n.º 1
0
int main(void)
{
	//DDRC |= 0x30;				//
	TWI_init_slave(SLAVEADD);		//Initialize slave mode
		
	//Initialize Start Conditions
	DDRC |= 0x0F;
	char temp = 0x0A;
	
    /* Replace with your application code */
    while (1) 
    {
		if((TWSR & 0xF8) == 0x60) //Check if new data is available
		{
			TWI_match_read_slave();
			TWI_read_slave(&temp);
		}
		PINC = (temp & 0x0F);
    }
}
Ejemplo n.º 2
0
int main()
{
    int16_t length=0,adc_value1,adc_value2;
    uint8_t i;
    DELAY_ms(100);
    ADC_Init();
    TIMSK = 0x00;
    DDRB= 0xff;
    DDRC = 0xff;
    DDRD = 0xff;
    PORTC = 0xff;



    while(1)
    {

        switch(state)
        {
        case E_Init:
            DELAY_ms(200);
            ADC_Init();
            adc_value1 = ADC_GetAdcValue(6);
            adc_value2 = ADC_GetAdcValue(7);

           // UART_Init(BAUD_RATE);
          //  sw_uart_init();
            StartDisplayTimer();

            sei();
          //  GetFont('1',pattern);

            while(1);
            MsgLength = strlen(inputBuffer);


            if( (adc_value1 >= 600) && (adc_value2 >= 600) )
            {
                deviceType = MASTER;
            }
            else
            {
                deviceType = SLAVE;
            }

            state = E_StartArbitration;
            break;

        case E_StartArbitration:

            GetFont(((MyDeviceId-0x30)/2)+0x30,pattern);
            if(deviceType == MASTER)
            {
                DELAY_ms(500);

                TCCR2 = 0x00;
                TIMSK = 0x01;
                TWI_init_master();
                state = E_MasterDisp;
            }
            else
            {
                if(IdConfirmed == 1)
                {
                    DELAY_ms(250);

                    TCCR2 = 0x00;
                    TIMSK = 0x01;
                    DisableHwUartComm();
                    TWI_init_slave(MyDeviceId);
                    state = E_SlaveDisp;
                }
            }
            break;


        case E_MasterDisp:

            if(NewMsgReceived!=0)
            {

                MsgLength = NewMsgLength;
                NewMsgReceived = 0;
                NewMsgLength = 0;
            }

            strcpy(msgBuffer,inputBuffer);

            if(MsgLength > NumberOfSegments)
            {
                ScrollString(msgBuffer);
            }
            else
            {

                DisplayString(msgBuffer);
            }

            break;

        case E_SlaveDisp:

            TWI_Receive_Frame(FrameBuffer);
            for(i=0;i<8;i++)
                pattern[i] = FrameBuffer[i];

            break;
        }
    }
}