如题,最近用到trct5000红外追迹模块,到处找不到代码,最后,在xxdn上下载下来用了,优化了些代码
现在共享出来,希望有用的着的朋友们支持一下
单片机源程序如下:
- //硬件驱动
- #include "usart.h"
- #include "common_.h"
- #include "TCRT5000.h"
- int last_on_status;
- void Tcrt_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // pa
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // pa01->d0
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//上拉输入
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;// 下拉输入
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
-
- last_on_status = 0;// 默认下拉
- }
- void Tcrt_test(){
-
- int on_status = 0;
- if(TCRT1 == 0) //循迹到黑线
- {
- // print_str("感应到物体接近...");
- on_status = 1;
- }else if(TCRT1 == 1) //未循迹到黑线
- {
- // print_str("物体离开...");
- on_status = 0;
- }
-
- process_trct(on_status, on_status != last_on_status);
-
- last_on_status = on_status;
- }
复制代码
|