Exemplo n.º 1
0
/**
 * @brief LED Double Flash!
 */
void DoubleFlash()
{
	LED_White();
	delay_ms(50);
	LED_Off();
	delay_ms(50);
	LED_White();
	delay_ms(50);
	LED_Off();	
}
Exemplo n.º 2
0
int main (void)
{
    /* Initialize TWI master. */
    TWI_MasterInit(&twiMaster,&TWIF,TWI_MASTER_INTLVL_LO_gc,TWI_BAUDSETTING);
    TWIF.SLAVE.CTRLA=0;  //slave disabled
    //board_init();

    En_RC32M();

    //Enable LowLevel & HighLevel Interrupts
    PMIC_CTRL |= PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm |PMIC_MEDLVLEN_bm;

    PORT_init();
    TimerD0_init();
    TimerC0_init();
    //USARTE0_init();
    //ADCB_init();
    LCDInit();
    //wdt_enable();


    // Globally enable interrupts
    sei();

    LED_Green_Time	= 3000;
    LED_Green_Speed = 500;
    LED_Red_Time	= 3000;
    LED_Red_Speed	= 100;
    LED_White_Time	= 1000;
    LED_White_Speed = 200;
    Buzzer_Time		= 2000;
    Buzzer_Speed	= 150;




    ///////////////////////////////////////////////////////////////////////////////////////////////Begin NRF Initialize
    NRF24L01_L_CE_LOW;       //disable transceiver modes

    SPI_Init();

    _delay_us(10);
    _delay_ms(100);      //power on reset delay needs 100ms
    NRF24L01_L_Clear_Interrupts();
    NRF24L01_L_Flush_TX();
    NRF24L01_L_Flush_RX();
    NRF24L01_L_CE_LOW;
    NRF24L01_L_Init_milad(_TX_MODE, _CH, _2Mbps, Address, _Address_Width, _Buffer_Size, RF_PWR_MAX);
    NRF24L01_L_WriteReg(W_REGISTER | DYNPD,0x01);
    NRF24L01_L_WriteReg(W_REGISTER | FEATURE,0x06);

    NRF24L01_L_CE_HIGH;
    _delay_us(130);
    ///////////////////////////////////////////////////////////////////////////////////////////////END   NRF Initialize

    // Insert application code here, after the board has been initialized.
    while(1)
    {

        LCDGotoXY(0,0);
        sprintf("salam");
        //LCDStringRam(str);
        ////////TWI
        //tx1[0]=Robot_D[RobotID].M1;
        //tx2[0]=Robot_D[RobotID].M2;
        //tx3[0]=Robot_D[RobotID].M3;
        //tx4[0]=Robot_D[RobotID].M4;

        tx1[0]=0x0F;
        tx2[0]=0x12;
        tx3[0]=0x01;
        tx4[0]=0x02;


        //	TWI_MasterWriteRead(&twiMaster,SLAVE1_ADDRESS,&tx1[0],1,3);
        //	TWI_MasterWriteRead(&twiMaster,SLAVE2_ADDRESS,&tx2[0],1,3);
        TWI_MasterWriteRead(&twiMaster,SLAVE3_ADDRESS,&tx3[0],1,3);
        rx3[0]=twiMaster.readData[0];
        if (rx3[0]==1)
        {
            LED_White(ON);
        }

        //	TWI_MasterWriteRead(&twiMaster,SLAVE4_ADDRESS,&tx4[0],1,3);
        /////////////////////


        NRF24L01_L_Write_TX_Buf(Buf_Tx_L, _Buffer_Size);
        NRF24L01_L_RF_TX();
        if (Buf_Rx_L[0]=='f')
        {
            LED_Green_PORT.OUTTGL = LED_Green_PIN_bm;
        }
        _delay_ms(10);
    }
}