Exemple #1
0
int main(void)
{
uint16_t cnt=0;
uint8_t c,div;
	DDRA = 0;
	PORTA = 0xff;
	DDRB = (1 << 4);	//TXD
	DDRC = 0xff;
	PORTC = 0;
	DDRD = 0xfe;

	USART_Init(8);		// 115.2K
	ADCSRA = 0x87;		// init ADC

//	TCCR0 = 1;
//	TIMSK = 1;
//	sei();

	for( ; ; ) {
		_WDR();

		if(USART_Ready()) {
			c = USART_Receive(STD_TIMEOUT);
			switch(c) {
				case 'g':
					div = rhex();
					if(USART_Timeout()) break;
					ADCSRA = 0x80 | div;
					div = rhex();
					if(USART_Timeout()) break;
					PORTC = div;	// gain
					get_wave();
					send_wave();
					break;

				case 'q':
					div = rhex();
					if(USART_Timeout()) break;
					ADCSRA = 0x80 | div;
					div = rhex();
					if(USART_Timeout()) break;
					PORTC = div;	// gain
					div = rhex();	// ch
					if(USART_Timeout()) break;
					get_sync_wave(div);
					send_wave();
					break;

				default:;
			}
		}

		if(++cnt > 1000) {
			PORTB = PINB ^ (1<<4); // blink
			cnt = 0;
		}
	}

	return 0;
}
Exemple #2
0
int main(void)
{
    int dianya_fly = 0;
    SysTick_Init();
    Tim3_Init(500);
    Nvic_Init();
    LED_Init();
    ADC1_Init();
    USART1_Config(115200);
    KEY_Init();
    NRF24L01_Init();
    while (NRF24L01_Check())	//检查NRF24L01是否在位.要放在设置TX_MODE之前,否则设置的发送地址会变成check中的0XA5 ,将与原接收地址对不上
    {
        LED2_ON;
        LED1_OFF;
        printf("no");
    }
    LED1_ON;
    LED2_OFF;
    //TX mode
    //NRF24L01_TX_Mode();
    //NRF24L01_Mode_Config(2);

    //RX mode
    NRF24L01_Mode_Config(3);
    while (1)
    {
        key = KEY_scan();


        if (NRF24L01_RxPacket(tmp_buf) == 0)
        {
            NRF24L01_TxPacket_AP(rc_buf);
            LED1_ON;
            if(tmp_buf[0]==0x88 && tmp_buf[1]==0xAE && tmp_buf[2]==0x1C)
            {
                dianya_fly = tmp_buf[17]<<8|tmp_buf[18];
                if(dianya_fly<36 && dianya_fly>20)
                {
                    LED2_ON;
                }
            }
            send_wave(32,tmp_buf);
        }
        else
        {
            LED1_OFF;
        }
    }
}
Exemple #3
0
int main(void)
{
    float q[4];
    u8 tmp_buf[32] = {0};
    float test = 0;
    static u8 led_on = 0;

    RCC_HSE_Configuration();
    SysTick_Init();
    NVIC_Configuration();
    USART1_Config(115200);
    LED_Init();
    LED3_Flash(2,100);
    ANO_TC_I2C2_INIT(0xA6, 400000, 1, 1, 3, 3);
    //硬实时
    Tim3_Init(500);//0.005s
    TIM2_Init(999, 0);

    Mpu6050init();
    MOT_GPIO_init();
    MOT_PWM_init();
    Set_PWM(0, 0, 0, 0);
    NRF24L01_Init();
    while (NRF24L01_Check())
    {
        LED2_Flash(2,500000);
    }

    //TX mode
    NRF24L01_Mode_Config(4);
    PID_Init();
    ADC1_Init();
    while (1)
    {
        if (getMpu6050Data == 1)
        {
            //0.01ms?
            Read_Mpu6050();
            Mpu6050_Analyze();
            getMpu6050Data = 0;
        }
        if (calculateAngle == 1)//2ms period
        {
            //0.2ms T
            //LED2_ON;

            //100us
            IMU_Quateration_Update((float)fGYRO_X , (float)fGYRO_Y , (float)fGYRO_Z , (float)fACCEL_X, (float)fACCEL_Y, (float)fACCEL_Z,ypr);
            //LED2_OFF;
            calculateAngle = 0;
        }
        if (sendData == 1)//2ms period
        {
            if(led_on)
            {
                LED2_OFF;
                led_on = 0;
            }
            else
            {
                LED2_ON;
                led_on = 1;
            }

            if (NRF24L01_RxPacket(tmp_buf) == 0)
            {
                //10us
                Rc_Data_Analyze(tmp_buf,&Rc_Data);
            }
            //if wait for the IRQ it need 9ms
            //if not wait for IRQ it runtime need 100us*1.2=0.12ms

            sendSenser((int16_t)fACCEL_X, (int16_t)fACCEL_Y, (int16_t)fACCEL_Z, (int16_t)fGYRO_X, (int16_t) fGYRO_Y, (int16_t)fGYRO_Z, (int16_t)(ypr[0] * 100), (signed short int)(ypr[1] * 100));
            send_wave(32);

            //0.14ms run time
            sendPwmVoltage(&Rc_Data,(uint16_t)(motor0 / 1000.0 * 100), (uint16_t)(motor1 / 1000.0 * 100), (uint16_t)(motor2 / 1000.0 * 100), (uint16_t)(motor3 / 1000.0 * 100));//0.00003974s
            send_wave(32);

            sendData = 0;
        }
        //moveFilterAccData(fACCEL_X, fACCEL_Y, fACCEL_Z, AngleOut);

        if (!strcmp(Rc_Data.status, "stop"))
        {
            Set_PWM(0, 0, 0, 0);
        }
        else if (!strcmp(Rc_Data.status, "start"))
        {
            //LED2_ON;
            expRoll = Rc_Data.roll;
            expPitch = Rc_Data.pitch;
            expThro = Rc_Data.throttle;
            surRoll = ypr[2];
            surPitch = ypr[1];
            PID_Set();
            Set_PWM(motor0, motor1, motor2, motor3);
            //LED2_OFF;
        }
        ////Uart1_Send_PID(320,PID_ROLL.KI,PID_ROLL.KD,1,0,0);
        ////send_wave(32);
        // if (STA == 1)
        // {
        // 	receive_Data();
        // 	STA = 0;
        // 	p = 0;
        // }
    }
}
Exemple #4
0
void main( void )
{
	unsigned int ucState=0xffff;
	unsigned char test[10];
	memset(test,'\0',10);
	int i=0;
	halBoardInit();
	hal430SetSystemClock();
	halButtonsInit();
	Init_Uart(115200);
	Init_Lcd();
	Msp430_ADC12_Init();
	Write_NByte((unsigned char *)eeprom,10,0);
	Read_NByte_Randomaddress(test,10,0);
	printf("main %s\r\n",test);
	 while(1)
	{
		if(flag==1)
		{
			//WDTCTL = WDTPW + WDTNMI + WDTTMSEL + WDTSSEL + WDTCNTCL;             // Start watchdog timer
			//IE1 |= WDTIE;                         // Enable WDT interrupt
			printf("we are in active state\r\n");
			//这里写自己的程序,把程序做在一个有限的循环里,这样做完之后就可以自动结束并关机。
			for(i=0;i<1000;i++){
			ucState = halButtonsPressed();
			
			if(ucState!=0xffff)
			{
			    i=0;
			    send_wave();
			    hal_buzzer(2);
			    Get_Power();
				//printf("%x is pressed\r\n",ucState);
				switch(ucState)
					{
					case BUTTON_MATL:
						printf("matl is pressed\r\n");
						break;
					case BUTTON_HARD:
						printf("hard is pressed\r\n");
						break;
					case BUTTON_DIREC:
						printf("direc is pressed\r\n");
						break;
					case BUTTON_TIMES:
						printf("times is pressed\r\n");
						break;						
					case BUTTON_SAVE:
						printf("save is pressed\r\n");
						break;
					case BUTTON_UP:
						printf("up is pressed\r\n");
						break;
					case BUTTON_DEL:
						printf("del is pressed\r\n");
						break;
					case BUTTON_AVE:
						printf("ave is pressed\r\n");
						break;
					case BUTTON_LEFT:
						printf("left is pressed\r\n");
						break;
					case BUTTON_MENU:
						printf("menu is pressed\r\n");
						break;
					case BUTTON_RIGHT:
						printf("right is pressed\r\n");
						break;
					case BUTTON_BACKLIGHT:
						printf("backlight is pressed\r\n");
						break;
					case BUTTON_ESC:
						printf("esc is pressed\r\n");
						break;
					case BUTTON_DOWN:
						printf("down is pressed\r\n");
						break;
					case BUTTON_ENTER:
						printf("enter is pressed\r\n");
						break;
					default:
						break;
					}
			}			
			//LPM3;
			Delay(100);
			}
			//如需定时,上边这个LPM3要被包括在那个有循环的循环体中,这样才能实现类似便携式仪表5分钟自动关机的效果。如果不使用定时也可以不要LPM3这句话。
			//WDTCTL = WDTPW + WDTHOLD + WDTNMI;             // Stop watchdog timer
			flag=0;
		}
		else
		{
			//如果周边设备在关机时有需要复位的或是关闭的在这里处理
			printf("we are in power off state\r\n");
		}
		hal_buzzer(0);
		printf("we going to LPM4\r\n");
		LPM4;
	}
}