这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » Renesas » anananjjj的试用进程贴(调试10:uCOS-II移植实现距)

共57条 6/6 |‹ 1 2 3 4 5 6 跳转至
工程师
2012-09-17 20:30:31     打赏
51楼

调试9:定时器应用——超声波模块测距

1、超声波模块原理介绍:




2、设置定时器:
利用Applilet3来设置定时器:


得到代码:
void TAU0_Init(void)
{
 TAU0EN = 1U;  /* supplies input clock */
 
        TPS0 = _0000_TAU_CKM0_FCLK_0 | _0000_TAU_CKM1_FCLK_0 | _0000_TAU_CKM2_FCLK_1 | _0000_TAU_CKM3_FCLK_8;
 /* Stop all channels */
 
        TT0 = _0001_TAU_CH0_STOP_TRG_ON | _0002_TAU_CH1_STOP_TRG_ON | _0004_TAU_CH2_STOP_TRG_ON | _0008_TAU_CH3_STOP_TRG_ON | _0010_TAU_CH4_STOP_TRG_ON | _0020_TAU_CH5_STOP_TRG_ON | _0040_TAU_CH6_STOP_TRG_ON | _0080_TAU_CH7_STOP_TRG_ON | _0200_TAU_CH1_H8_STOP_TRG_ON | _0800_TAU_CH3_H8_STOP_TRG_ON;
 /* Mask channel 0 interrupt */
 
        TMMK00 = 1U; /* disable INTTM00 interrupt */
 
        TMIF00 = 0U; /* clear INTTM00 interrupt flag */
 
        /* Mask channel 1 interrupt */
 
        TMMK01 = 1U; /* disable INTTM01 interrupt */
 
        TMIF01 = 0U; /* clear INTTM01 interrupt flag */
 
        /* Mask channel 1 higher 8 bits interrupt */
 
        TMMK01H = 1U; /* disable INTTM01H interrupt */
 
        TMIF01H = 0U; /* clear INTTM01H interrupt flag */
 
        /* Mask channel 2 interrupt */
 
        TMMK02 = 1U; 
        /* disable INTTM02 interrupt */
 
        TMIF02 = 0U; /* clear INTTM02 interrupt flag */
 
        /* Mask channel 3 interrupt */
 
        TMMK03 = 1U; /* disable INTTM03 interrupt */
 
        TMIF03 = 0U; /* clear INTTM03 interrupt flag */
 
        /* Mask channel 3 higher 8 bits interrupt */
 
        TMMK03H = 1U; /* disable INTTM03H interrupt */
 
        TMIF03H = 0U; /* clear INTTM03H interrupt flag */
 
        /* Mask channel 4 interrupt */
 
        TMMK04 = 1U; 
        /* disable INTTM04 interrupt */
 
        TMIF04 = 0U; /* clear INTTM04 interrupt flag */
 
        /* Mask channel 5 interrupt */
 
        TMMK05 = 1U; /* disable INTTM05 interrupt */
 
        TMIF05 = 0U; /* clear INTTM05 interrupt flag */
 
        /* Mask channel 6 interrupt */
 
        TMMK06 = 1U; /* disable INTTM06 interrupt */
 
        TMIF06 = 0U; /* clear INTTM06 interrupt flag */
 
        /* Mask channel 7 interrupt */
 
        TMMK07 = 1U; /* disable INTTM07 interrupt */
 
        TMIF07 = 0U; /* clear INTTM07 interrupt flag */

       
 /* Set INTTM00 high priority */
 TMPR100 = 0U;
 TMPR000 = 0U; 
        /* Channel 0 used as interval timer */
 
        TMR00 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE | _0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0001_TAU_START_INT_USED;
 TDR00 = _001F_TAU_TDR00_VALUE;
 
        TO0 &= ~_0001_TAU_CH0_OUTPUT_VALUE_1;
 
        TOE0 &= ~_0001_TAU_CH0_OUTPUT_ENABLE;
 
}
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function starts TAU0 channel 0 counter.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TAU0_Channel0_Start(void)
{
 TMIF00 = 0U; /* clear INTTM00 interrupt flag */
 TMMK00 = 0U; /* enable INTTM00 interrupt */
 TS0 |= _0001_TAU_CH0_START_TRG_ON;
}
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function stops TAU0 channel 0 counter.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TAU0_Channel0_Stop(void)
{
 TT0 |= _0001_TAU_CH0_STOP_TRG_ON;
 /* Mask channel 0 interrupt */
 TMMK00 = 1U; /* disable INTTM00 interrupt */
 TMIF00 = 0U; /* clear INTTM00 interrupt flag */
}

3、关键程序:

主程序中只需启动定时器:TAU0_Channel0_Start();

主循环中:
   S=change_distence();
   LCD_Accel_Value2(4,0,S);

其中:
void delay1(void)   

 uchar i;
 for(i=11;i>0;i--);
}

void Get_distance(void)
{
  unsigned long int i=162400;       //3.5m测距所需的时间
  Trig_1;           //触发
  delay1();
  Trig_0; //停止触发
 //检测输入信号
 while(!(EchoIN==1)&&i>0)
 {
   i--;
 }
 if (i>0)
  {
  tick_1us=0;
  while(EchoIN==1);
  temp1=tick_1us;
  }
 
}
unsigned int change_distence()

  unsigned long int i;
   Get_distance();
   k=temp1/58.00;
   i=(uint)(k*100);
  return i;
 }

而关键的 tick_1us
是在定时中断:
#pragma vector = INTTM00_vect
__interrupt void MD_INTTM00(void)
{
 
 /* Start user code. Do not edit comment generated here */
       TM00_flag = TRUE;
       tick_1us++;
 /* End user code. Do not edit comment generated here */
}
得到的!

4、图片:




5、视频:


工程师
2012-09-23 16:08:46     打赏
52楼

调试10:uCOS-II移植实现

1、在操作系统中建立了三个任务:

static  OS_STK  App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];

#define TASK_LED1_STACK_SIZE (128)
static OS_STK Task_LED1_Stack[TASK_LED1_STACK_SIZE];
void Task_LED1( void *Id ) ;
#define Task_LED1_PRIO       6

#define TASK_Beep_STACK_SIZE (128)
static OS_STK  Task_Beep_Stack[TASK_Beep_STACK_SIZE];
void Task_Beep( void *Id ) ;
#define Task_Beep_PRIO       5

#define TASK_LED_STACK_SIZE (128)
static OS_STK Task_LED2_Stack[TASK_LED_STACK_SIZE];
void Task_LED2( void *Id ) ;
#define  Task_LED2_PRIO       10
//以下为任务的具体内容
static  void  App_TaskCreate (void)
{
 
  OSTaskCreate( Task_LED1, (void *)0, (OS_STK *)&Task_LED1_Stack[TASK_LED1_STACK_SIZE-1], Task_LED1_PRIO ) ;
  OSTaskCreate( Task_LED2, (void *)0, (OS_STK *)&Task_LED2_Stack[TASK_LED_STACK_SIZE-1], Task_LED2_PRIO ) ;
  OSTaskCreate( Task_Beep, (void *)0, (OS_STK *)&Task_Beep_Stack[TASK_Beep_STACK_SIZE-1], Task_Beep_PRIO ) ;
}

void Task_LED1( void *Id )
{
 for( ; ; ) 
 { 
                BSP_LED_Toggle(1);
                LCD_clear();
                LCD_write_english_string(0,0,"LED1 Change!");
  OSTimeDly(500);
 }
}

void Task_Beep( void *Id )
{
 for( ; ; ) 
 {
                BSP_Beep_Toggle();
                LCD_clear();
                LCD_write_english_string(0,2,"Beep ring!");
  OSTimeDly(100); 
 }
}

void Task_LED2( void *Id )
{

 for(;;)
 {
          BSP_LED_Toggle(2);
          LCD_clear();
          LCD_write_english_string(0,4,"LED1 Change!");
   OSTimeDly(1000);//1s
 }
}

2、由于移植自Micrium,所以改动不大只是移植,然后编写了几个任务!

3、图片视频:


测试视频:


院士
2012-09-23 20:36:08     打赏
53楼
真 棒 真棒……

继续期待楼主更多作品出来

工程师
2012-09-23 21:31:58     打赏
54楼
这几天正在纠结到底买不买那个FPGA呢!一是我这个月钱紧(学生当伤不起),二是怕没时间!不知道过段时间买不行啊!

院士
2012-09-24 13:47:53     打赏
55楼
有取有舍才是王道。

估计之后购买会有,但是能否参加活动获得奖励,这可难说了。

高工
2012-09-26 12:39:09     打赏
56楼

移植的没看明白。。有原代码下载没。


菜鸟
2012-10-01 10:40:58     打赏
57楼

编程的全是C语言吗?


共57条 6/6 |‹ 1 2 3 4 5 6 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]