之前找的一个程序,不知道可行不可行
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "tracking.h"
- #include "usart.h"
- #include "pwm.h"
- #include "encoder.h"
- #include "timer.h"
- #include "adc.h"
- #include "schedule.h"
- #include "DataScope_DP.h"
- #include "key.h"
- extern struct Encoder Encoder_2;
- extern struct Encoder Encoder_4;
- extern int Encoder_TIM;
- extern int Angel_evalue;
- extern int now_ang ;
- extern float out_c;
- extern int Encoder_first;
- extern int Encoder_end;
- int main(void)
- {
- delay_init(); //延时函数初始化
- LED_Init(); //初始化与LED连接的硬件接口
- KEY_Init();
- Inf_Init(); //初始化与按键连接的硬件接口
- LED0=0; //点亮LED
- LED1=0;
- LED2=0;
- Buzzer=0;
- Bluetooth_Init(9600);
- MiniBalance_PWM_Init(7199,0);//不分频。PWM频率=72000/(899+1)=80Khz
- EXTIX_Init();
- Encoder_Init_TIM2();
- Encoder_Init_TIM4();
- Angle_Adc_Init();
- PWMLF = 0;
- PWMLB = 0;
- PWMRF = 0;
- PWMRB = 0;
- // delay_ms(100);
- Timer1_Init(49,7199); //=====定时中断初始化
- while(1)
- {
- //printf("%d\n",Encoder_TIM);
- //
- // key=KEY_Scan();
- // if(key==1)
- // LED0=!LED0;
- // else if(key==2)
- // LED1=!LED1;
- // else if(key==3)
- // LED2=!LED2;
- printf(" %d\t",Angel_evalue);
- printf(" %d\n",now_ang);
- printf("%f\n",out_c);
- printf(" %d\n",Encoder_first);
- printf(" %d\n",Encoder_end);
- // printf("R: %d\n",Read_Encoder(4));
- // printf("%d\n",Read_Velocity(4));
- if(Encoder_end>(Encoder_first+100))
- {
- Encoder_end-=1;
- Encoder_first+=1;
- }
- delay_ms(100);
- }
- }
复制代码
所有资料51hei提供下载:
2017-7-25-16-50 跷跷板.rar
(319.35 KB, 下载次数: 8)
|