智能车制作

标题: 新手写的一个简单的TRS-D05舵机驱动程序,不知道有没有问题? [打印本页]

作者: wpconan123    时间: 2015-4-17 19:26
标题: 新手写的一个简单的TRS-D05舵机驱动程序,不知道有没有问题?
void  main(void)
{
      gpio_init  (PORTD, 8, GPO, HIGH);  
      while(1);
     {                           
        gpio_set(PORTD, 8, HIGH);         
        time_delay_ms(1);  //延时1ms  
        gpio_set(PORTD, 8, LOW);         
        time_delay_ms(19); //延时19ms
        
     }                                    
}

下面是野火的延时函数,
/*************************************************************************
*                             野火嵌入式开发工作室
*
*  函数名称:time_delay_ms
*  功能说明:延时函数,使用定功耗定时器延时,准确
*  参数说明:ms   延时时间,单位为ms
*  函数返回:无
*  修改时间:2012-1-20
*  备    注:官方例程自带
*************************************************************************/
void time_delay_ms(uint32 ms)
{
    /* Make sure the clock to the LPTMR is enabled */
    SIM_SCGC5 |= SIM_SCGC5_LPTIMER_MASK;

    /* Set the compare value to the number of ms to delay */
    LPTMR0_CMR = ms;

    /* Set up LPTMR to use 1kHz LPO with no prescaler as its clock source */
    LPTMR0_PSR = LPTMR_PSR_PCS(1) | LPTMR_PSR_PBYP_MASK;

    /* Start the timer */
    LPTMR0_CSR = LPTMR_CSR_TEN_MASK;

    /* Wait for counter to reach compare value */
    while (!(LPTMR0_CSR & LPTMR_CSR_TCF_MASK));

    /* Clear Timer Compare Flag */
    LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;

    return;
}
各位大神帮忙看下有什么问题?




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2