-
大小: 1001KB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-10-23
- 语言: 其他
- 标签: STM32F103C8; 12舵机
资源简介
STM32F103C8舵机控制程序,原创支持12舵机;\
调用 void PWM_Test(void),即可。基于原子程序调试成功。
代码片段和文件信息
#include “sys.h“
#include “usart.h“
#include “delay.h“
#include “led.h“
#include “key.h“
#include “string.h“
#include “timer.h“
#include “oled.h“
#include “adc.h“
#include “remote.h“
void Adc_Test(void)
{
u16 ad = 0;
ad = Get_Adc_Average(02);
OLED_ShowString(214“CH0:“);
OLED_ShowNumber(3214ad512);
ad = Get_Adc_Average(12);
OLED_ShowString(228“CH1:“);
OLED_ShowNumber(3228ad512);
OLED_Refresh_Gram();
}
int main(void)
{
u8 t=0; u16 len = 0;
u16 led0pwmval=1770;
u8 red_key = 0;
u8 mode = 1;
u16 time = 20;
Stm32_Clock_Init(9);
delay_init(72);
JTAG_Set(JTAG_SWD_DISABLE); //=====关闭JTAG接口
JTAG_Set(SWD_ENABLE); //=====打开SWD接口 可以利用主板的SWD接口调试
uart_init(72115200);
LED_Init();
KEY_Init();
OLED_Init();
//TIM2_Int_Init(49997199);
//PWM_Test();
//PA7
TIM3_PWM_Init2(1999719); //不分频。PWM频率=72000/(899+1)=80Khz
TIM3->CCR2 =1770;
//PA1
Adc_Init();
Remote_Init();
OLED_ShowString(242“key:“);
while(1)
{
red_key = Remote_Scan();
if(red_key)
{
OLED_ShowNumber(3242red_key512);
OLED_ShowNumber(6442RmtCnt512);
}
switch(red_key)
{
case 104: LED0_PWM_VAL+=5; break; // 1
case 152: LED0_PWM_VAL-=5; break; //2
case 176: mode = 1; break; //3
case 48: mode = 0; break; //4
case 24: if(time<1000) time += 10; break; //5
case 122: if(time>20) time -= 10; break; //6
case 16: break;// 7
case 56: break; //8
case 90: break; //9
case 66: break; //0
case 82: break; // delete
}
if(1)
{
OLED_ShowNumber(22t512);
OLED_Refresh_Gram();
OLED_ShowNumber(402LED0_PWM_VAL512);
OLED_Refresh_Gram();
Adc_Test();
if(USART_RX_STA&0x8000)
{
len = USART_RX_STA & 0x3fff;
printf(“RX len = %d\r\n“len);
printf(“TEXT: %s\r\n“USART_RX_BUF);
OLED_Clear();
OLED_ShowString(55USART_RX_BUF);
OLED_Refresh_Gram();
USART_RX_STA = 0;
memset((u8 *)(USART_RX_BUF)0USART_REC_LEN);
}
printf(“t:%d\r\n“t);
}
delay_ms(5);
//delay_us(100);
if(KEY == 0)
{
//key_press = 0;
printf(“key pressed\r\n“);
led0pwmval++;
LED0_PWM_VAL=led0pwmval;
}
if(mode) //遥控正传反转模式
{
if( (LED0_PWM_VAL >= 1951) )
{
delay_ms(100);
led0pwmval = 1771;
LED0_PWM_VAL=led0pwmval;
delay_ms(100);
}
if( (LED0_PWM_VAL <= 1770) )
{
delay_ms(100);
led0pwmval = 1950;
LED0_PWM_VAL=led0pwmval;
delay_ms(100);
}
}
else //抖动模式
{
if( (LED0_PWM_VAL >= 1850) )
{
delay_ms(time);
led0pwmval = 1800;
LED0_PWM_VAL=led0pwmval;
delay_ms(time);
}
if( (LED0_PWM_VAL <= 1800) )
{
delay_ms(time);
led0pwmval = 1850;
LED0_PWM_VAL=led0pwmval;
delay_ms(time);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 223892 2016-04-20 16:05 TEST_12PWM\USER\adc.crf
文件 286 2016-04-20 16:05 TEST_12PWM\USER\adc.d
文件 238176 2016-04-20 16:05 TEST_12PWM\USER\adc.o
文件 223233 2016-04-20 16:05 TEST_12PWM\USER\delay.crf
文件 271 2016-04-20 16:05 TEST_12PWM\USER\delay.d
文件 237468 2016-04-20 16:05 TEST_12PWM\USER\delay.o
文件 19 2016-04-11 11:02 TEST_12PWM\USER\ExtDll.iex
文件 2119 2016-04-12 15:11 TEST_12PWM\USER\Hardware\ADC\adc.c
文件 805 2015-01-30 18:17 TEST_12PWM\USER\Hardware\ADC\adc.h
文件 3008 2016-04-12 15:02 TEST_12PWM\USER\Hardware\KEY\key.c
文件 480 2016-03-25 11:27 TEST_12PWM\USER\Hardware\KEY\key.h
文件 518 2016-04-11 11:45 TEST_12PWM\USER\Hardware\LED\led.c
文件 152 2016-04-11 11:27 TEST_12PWM\USER\Hardware\LED\LED.H
文件 5222 2016-04-12 08:19 TEST_12PWM\USER\Hardware\OLED\oled.c
文件 957 2016-03-11 09:03 TEST_12PWM\USER\Hardware\OLED\oled.h
文件 16174 2013-09-13 11:45 TEST_12PWM\USER\Hardware\OLED\oledfont.h
文件 3609 2016-04-20 16:02 TEST_12PWM\USER\Hardware\REMOTE\remote.c
文件 881 2015-01-30 20:59 TEST_12PWM\USER\Hardware\REMOTE\remote.h
文件 9606 2016-04-12 11:42 TEST_12PWM\USER\Hardware\TIMER\timer.c
文件 744 2016-04-12 11:43 TEST_12PWM\USER\Hardware\TIMER\timer.h
文件 225440 2016-04-20 16:05 TEST_12PWM\USER\key.crf
文件 321 2016-04-20 16:05 TEST_12PWM\USER\key.d
文件 243088 2016-04-20 16:05 TEST_12PWM\USER\key.o
文件 222821 2016-04-20 16:05 TEST_12PWM\USER\led.crf
文件 253 2016-04-20 16:05 TEST_12PWM\USER\led.d
文件 235548 2016-04-20 16:05 TEST_12PWM\USER\led.o
文件 40272 2016-04-12 15:12 TEST_12PWM\USER\OBJ\Listings\startup_stm32f10x_md.lst
文件 95447 2016-04-20 16:39 TEST_12PWM\USER\OBJ\Listings\test.map
文件 58 2016-04-11 08:15 TEST_12PWM\USER\OBJ\ob
文件 5916 2016-04-11 08:15 TEST_12PWM\USER\OBJ\ob
............此处省略67个文件信息
- 上一篇:状态机控制LED-vhdl代码
- 下一篇:NetAssist 3.6
评论
共有 条评论