cmd_cnt.c

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <stdio.h>

void main(int argc, char *argv[])
 {
   printf ("The number of command line entries is %d/n", argc);
 }

 

#include "stm32f10x.h" #include "main.h" #include "HC_SR04.h" #include "SysTick.h" void delay(uint16_t time) { uint16_t i = 0; while(time--) { i = 12000; while(i--); } } int main() { float Length = 0; HC_SR04Config(); while(1) { Length = Getlength(); printf("%.3f\r\n",Length);//????????,?????????? ms_delay(500); } }*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\webdownload\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_md.s... compiling system_stm32f10x.c... compiling stm32f10x_bkp.c... compiling stm32f10x_dac.c... compiling stm32f10x_cec.c... compiling stm32f10x_can.c... compiling stm32f10x_dma.c... compiling core_cm3.c... compiling stm32f10x_adc.c... compiling misc.c... compiling stm32f10x_flash.c... compiling stm32f10x_fsmc.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_crc.c... compiling stm32f10x_exti.c... compiling stm32f10x_gpio.c... compiling stm32f10x_i2c.c... compiling stm32f10x_pwr.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_rtc.c... compiling stm32f10x_rcc.c... compiling stm32f10x_sdio.c... compiling stm32f10x_wwdg.c... compiling stm32f10x_usart.c... compiling stm32f10x_spi.c... compiling Delay.c... compiling LED.c... compiling stm32f10x_tim.c... compiling HC_SR04.c... HC_SR04.h(15): warning: #1-D: last line of file ends without a newline SysTick.h(4): warning: #1-D: last line of file ends without a newline HC_SR04.c(103): warning: #1-D: last line of file ends without a newline } HC_SR04.c: 3 warnings, 0 errors compiling Key.c... compiling OLED.c... compiling SysTick.c... SysTick.h(4): warning: #1-D: last line of file ends without a newline SysTick.c(26): warning: #1-D: last line of file ends without a newline } SysTick.c: 2 warnings, 0 errors compiling main.c... User\main.c(2): error: #5: cannot open source input file "main.h": No such file or directory #include "main.h" User\main.c: 0 warnings, 1 error compiling stm32f10x_it.c... ".\Objects\Project.axf" - 1 Error(s), 5 Warning(s). Target not created.分析问题并修改,给我完整代码
07-10
void CLOCK_INST_IRQHandler(void)//主计时器中断 { switch (DL_TimerA_getPendingInterrupt(CLOCK_INST)) { case DL_TIMERA_IIDX_ZERO: COUNT_TIME++; controlFlag_1000HZ = 1; // 速度 = (count差 * 6000 / 编码器PPR) motor_l.encoder.speed=(float)(motor_l.encoder.countnum-motor_l.encoder.lastcount)*6000/PULSE_PER_CYCLE;//rpm motor_r.encoder.speed=(float)(motor_r.encoder.countnum-motor_r.encoder.lastcount)*6000/PULSE_PER_CYCLE;//rpm motor_l.encoder.speed=Speed_Low_Filter(motor_l.encoder.speed,&motor_l.encoder); motor_r.encoder.speed=Speed_Low_Filter(motor_r.encoder.speed,&motor_r.encoder); motor_l.encoder.lastcount=motor_l.encoder.countnum; motor_r.encoder.lastcount=motor_r.encoder.countnum; if(COUNT_TIME % 10 == 0)controlFlag_100HZ = 1; if(COUNT_TIME % 50 == 0)controlFlag_20HZ = 1; if(COUNT_TIME % 100 == 0)controlFlag_5HZ = 1; if(COUNT_TIME % 1000 == 0)controlFlag_5HZ = 1; sensor_get_gray_byte(); break; default: break; } DL_TimerA_clearInterruptStatus(CLOCK_INST,DL_TIMERA_IIDX_ZERO); } //编码器 void ENCODER1A_INST_IRQHandler (void) { // 左轮 switch (DL_TimerG_getPendingInterrupt(ENCODER1A_INST)) { case DL_TIMERA_IIDX_CC0_DN: motor_l.encoder.dierct = DL_GPIO_readPins(GPIO_ENCODER_PORT, GPIO_ENCODER_ENCODER1B_PIN);//读取IO电平获取电机旋转方向 motor_l.encoder.countnum= motor_l.encoder.dierct? (motor_l.encoder.countnum - 1) : (motor_l.encoder.countnum + 1);//通过判断旋转方向来决定encoder_cnt增加还是减少 break; default: break; } } void ENCODER2A_INST_IRQHandler(void) { // 右轮 switch (DL_TimerG_getPendingInterrupt(ENCODER2A_INST)) { case DL_TIMERG_IIDX_CC0_DN: motor_r.encoder.dierct= DL_GPIO_readPins(GPIO_ENCODER_PORT, GPIO_ENCODER_ENCODER2B_PIN);//读取IO电平获取电机旋转方向 motor_r.encoder.countnum = motor_r.encoder.dierct ? ( motor_r.encoder.countnum - 1) : ( motor_r.encoder.countnum +1);//通过判断旋转方向来决定encoder_cnt增加还是减少 break; default: break; } } GMR编码器的MG310电机的减速比是20,500线。右上面的代码计算编码器的转速,为什么无论轮子正传还是反转都计数器都只会减?
07-25
#include "TIM.h" void IC_TIM2(void) { // 使能TIM2和GPIOA时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); // 配置GPIOA引脚0为输入 GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // 浮空输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // 配置TIM2的基本定时器参数 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 0xFFFF; // 最大计数值 TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; // 1MHz时钟 (1us分辨率) TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // 配置TIM2的输入捕获参数 TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge; // 双边沿触发 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0F; // 最大滤波 TIM_ICInit(TIM2, &TIM_ICInitStructure); // 配置TIM2的中断 NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 最高优先级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 使能输入捕获中断 TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE); // 初始禁用定时器 TIM_Cmd(TIM2, DISABLE); } void IC_TIM3(void) { // 使能TIM3和GPIOA时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); // 配置GPIOA引脚6为输入 GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // 浮空输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // 配置TIM3的基本定时器参数 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 0xFFFF; // 最大计数值 TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; // 1MHz时钟 (1us分辨率) TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); // 配置TIM3的输入捕获参数 TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge; // 双边沿触发 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0F; // 最大滤波 TIM_ICInit(TIM3, &TIM_ICInitStructure); // 配置TIM3的中断 NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 最高优先级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // 使能输入捕获中断 TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); // 初始禁用定时器 TIM_Cmd(TIM3, DISABLE); }
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值