void BlueToothHandler()
{
	////////////////串口//////////////////////////////////////////////////////////
	char ch;

	if (uart_query(UART0) == 1)   //接收数据寄存器满
	{
		//用户需要处理接收数据
		uart_getchar(UART0, &ch);                    //无限等待接受1个字节
		uart_putchar(UART0, ch);                    //发送字符串
	}
}
Example #2
0
int
char_present (void)
{
	return uart_query(FIRE_PORT);
}
Example #3
0
/***********************************主函数**************************************/
void  main(void)
{
    for(i = 0; i < 110; i++)   //装载摄像头边线初值
    {
        slope.left_initial_value[i] = left_initial[i];
        slope.right_initial_value[i] = right_initial[i];
    }
    camera_init(imgbuff);						//初始化摄像头
    //配置中断服务函数
    set_vector_handler(PORTA_VECTORn , PORTA_IRQHandler);   //设置LPTMR的中断服务函数为 PORTA_IRQHandler
    set_vector_handler(DMA0_VECTORn , DMA0_IRQHandler);     //设置LPTMR的中断服务函数为 PORTA_IRQHandler

    set_vector_handler(PORTE_VECTORn ,PORTE_IRQHandler);    //设置PORTE的中断服务函数为 PORTE_IRQHandler
    enable_irq (PORTE_IRQn);                                //使能PORTE中断

    port_init(PTE2, ALT1 | PULLUP );     //5  蓝牙同时发车
    if(!gpio_get (PTE2))   //蓝牙通讯同时发车
    {
        key_init(KEY_A);
        OLED_Init();
        while(1)
        {
            #if ( CAR_NUMBER == 2 )
                OLED_P6x8Str(0, 6, "Press K6 to start!");
                if(key_check(KEY_A) == KEY_DOWN)   //按K3发车
                {
                    uart_putchar(VCAN_PORT, ch);
                    OLED_P6x8Str(0, 6, "                  ");
                    bluetooth = 1;
                    break;
                }
            #endif
            #if ( CAR_NUMBER == 1 )
                OLED_P6x8Str(0, 6, "Start 2B to start!");
                while(uart_query (VCAN_PORT) == 0);
                OLED_P6x8Str(0, 6, "                  ");
                bluetooth = 1;
                break;
            #endif
        }
    }
    else
    {
        bluetooth = 2;
    }

    mk60int();
	init_PID();

    while(1)
    {
        oled_display();
        camera_get_img();						//摄像头获取图像
        img_extract(img, imgbuff, CAMERA_SIZE);	//解压图像
        get_slope(img, &slope); //获取斜率
        boundary_detection();//扫描图像获取边界
        picture_analysis();//获取中线
        //SetMotorVoltage(0.2,0.2);
        if(!gpio_get (PTE1))
        {
           vcan_sendimg(imgbuff,CAMERA_SIZE);//摄像头看图像
        }

        if(!gpio_get (PTE2))   //蓝牙同时发车
        {
            #if ( CAR_NUMBER == 1 )
                if(uart_querychar (VCAN_PORT, &ch) != 0)
                {
                    if(ch == 's')
                    {
                        stop_done = 1;
                    }
                }
            #endif
            #if ( CAR_NUMBER == 2 )
                if(stop_done)
                {
                    lptmr_delay_ms(500);    //延时确保后车过线
                    while(1)
                    {
                        uart_putchar(VCAN_PORT, ch_stop);
                    }
                }
            #endif
        }

        if(!gpio_get (PTE3))   //速度40
        {
            vPID.Setpoint = 40;
        }
        if(!gpio_get (PTE4))  //速度45
        {
            vPID.Setpoint = 45;
        }
        if(!gpio_get (PTE5))   //速度50
        {
            vPID.Setpoint = 50;
        }
        if(!gpio_get (PTE6))   //速度47
        {
            vPID.Setpoint = 46;
        }
        if(!gpio_get (PTE7))   //速度48
        {
            vPID.Setpoint = 47;
        }
        if(!gpio_get (PTE8))   //速度49
        {
            vPID.Setpoint = 48;
        }
        //ware1[0]=xielv;
        //vcan_sendware(ware1, sizeof(xielv));
        /*
        Display_number(36, 6, ttt);
        Display_number(0, 6, sss);
        printf("%d,", left_diuxian1);
        printf("%d\n",tt-t);
        */
        //printf("%d\n",speed1);

        //printf("%d,",left_diuxian1);

        //printf("%d\n",slope3);

        //printf("%d,",left_chazi);
        //printf("%d\n",right_chazi);
        //printf("%d,",m);
        //printf("%d\n",a);
        // if(!gpio_get (PTE8))
        // {
        //     for(l=0;l<120;l++)
        //     {
        //         printf("%d,",left_bianjie[l]);
        //     }
        //     printf("\n");
        // }
   }
}