资源简介
程序名称: 飞思卡尔智能车舵机调试工具 v1.1
程序作者: LinX
时 间: 2009-03-07
联系方式: Q Q : 408111919
Email: linhaiwz@163.com" & vbCrLf & vbCrLf & _
〖 本程序为方便舵机调试而编写,错误在所难免,如有建议欢迎和我联系! 〗
角度转换为高电平时间
角度 -45 0 45 (anger/度)
高电平时间 1000 1500 2000 (t/us)
计算公式为:T = 1000 + (anger + 45) * (1000 / 90)
该程序可以通过串口与单片机进行通讯,实时改变舵机的角度。
通讯协议为:0xfe 0xMM 0xNN (其中0xfe为包头,0xMM为PWMDTYx高8位,0xN为PWMDTYx低8位)
在串口中断中分三次接收,在第二次接收时保存数据到temp0中,在第三次接收到数据时将PWMDTY01= ((unsigned int)temp0 <<8) | RxData 就可以完成PWM改变输出了。
下位机程序如下:
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
unsigned char RX=0,temp0;
void uart_putchar(unsigned char ch)
{
if (ch == '\n')
{
while(!(SCI0SR1&0x80)) ;
SCI0DRL= 0x0d;
return;
}
while(!(SCI0SR1&0x80)) ;
SCI0DRL=ch;
}
static void PWM_Init(void)
{
//SB,B for ch2367
//SA,A for ch0145
PWMCTL_CON01=1; //0和1联合成16位PWM;
PWMCAE_CAE1=0; //选择输出模式为左对齐输出模式
PWMCNT01 = 0; //计数器清零;
PWMPOL_PPOL1=1; //先输出高电平,计数到DTY时,反转电平
PWMPRCLK = 0X40; //clockA不分频,clockA=busclock=16MHz;CLK B 16分频:1Mhz
PWMSCLA = 8; //对clock SA 进行2*8=16分频;pwm clock=clockA/16=1MHz;
PWMCLK_PCLK1 = 1; //选择clock SA做时钟源
PWMPER01 = 20000; //周期20ms; 50Hz;(可以使用的范围:50-200hz)
PWMDTY01 = 1500; //高电平时间为1.5ms;
PWME_PWME1 = 1;
}
void setbusclock(void) //PLL setting
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=1;
REFDV=1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
_asm(nop); //BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
static void SCI_Init(void) //SCI
{
SCI0CR1=0x00;
SCI0CR2=0x2c; //enable Receive Full Interrupt,RX enab
代码片段和文件信息
/******************************************************************************
FILE : datapage.c
PURPOSE : paged data access runtime routines
MACHINE : Freescale 68HC12 (Target)
LANGUAGE : ANSI-C
HISTORY : 21.7.96 first version created
******************************************************************************/
#include “hidef.h“
#include “non_bank.sgm“
#include “runtime.sgm“
#ifndef __HCS12X__ /* it‘s different for the HCS12X. See the text below at the #else // __HCS12X__ */
/*
According to the -Cp option of the compiler the
__DPAGE__ __PPAGE__ and __EPAGE__ macros are defined.
If none of them is given as argument then no page accesses should occur and
this runtime routine should not be used !
To be on the save side the runtime routines are created anyway.
If some of the -Cp options are given an adapted versions which only covers the
needed cases is produced.
*/
/* if no compiler option -Cp is given it is assumed that all possible are given : */
/* Compile with option -DHCS12 to activate this code */
#if defined(HCS12) || defined(_HCS12) || defined(__HCS12__) /* HCS12 family has PPAGE register only at 0x30 */
#define PPAGE_ADDR (0x30+REGISTER_base)
#ifndef __PPAGE__ /* may be set already by option -CPPPAGE */
#define __PPAGE__
#endif
/* Compile with option -DDG128 to activate this code */
#elif defined DG128 /* HC912DG128 derivative has PPAGE register only at 0xFF */
#define PPAGE_ADDR (0xFF+REGISTER_base)
#ifndef __PPAGE__ /* may be set already by option -CPPPAGE */
#define __PPAGE__
#endif
#elif defined(HC812A4)
/* all setting default to A4 already */
#endif
#if !defined(__EPAGE__) && !defined(__PPAGE__) && !defined(__DPAGE__)
/* as default use all page registers */
#define __DPAGE__
#define __EPAGE__
#define __PPAGE__
#endif
/* modify the following defines to your memory configuration */
#define EPAGE_LOW_BOUND 0x400u
#define EPAGE_HIGH_BOUND 0x7ffu
#define DPAGE_LOW_BOUND 0x7000u
#define DPAGE_HIGH_BOUND 0x7fffu
#define PPAGE_LOW_BOUND (DPAGE_HIGH_BOUND+1)
#define PPAGE_HIGH_BOUND 0xBFFFu
#define REGISTER_base 0x0u
#ifndef DPAGE_ADDR
#define DPAGE_ADDR (0x34u+REGISTER_base)
#endif
#ifndef EPAGE_ADDR
#define EPAGE_ADDR (0x36u+REGISTER_base)
#endif
#ifndef PPAGE_ADDR
#define PPAGE_ADDR (0x35u+REGISTER_base)
#endif
/*
The following parts about the defines are assumed in the code of _GET_PAGE_REG :
- the memory region controlled by DPAGE is above the area controlled by the EPAGE and
below the area controlled by the PPAGE.
- the lower bound of the PPAGE area is equal to be the higher bound of the DPAGE area + 1
*/
#if EPAGE_LOW_BOUND >= EPAGE_HIGH_BOUND || EPAGE_HIGH_BOUND >= DPAGE_LOW_BOUND || DPAGE_LOW_BOUND >= DPAGE_HIGH_BOUND || DPAGE_HIGH_BOUND >= PPAGE_LOW_BOUND || PPAGE_LOW_BOUND >= PPAGE_HIGH_BOUND
#error /* please adapt _GET_PAGE_REG for
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 105 2010-03-05 16:56 舵机调试工具\测试程序\bin\Full_Chip_Simulation.map
文件 147259 2010-03-05 16:56 舵机调试工具\测试程序\bin\TBDML.abs
文件 1130 2010-03-05 16:56 舵机调试工具\测试程序\bin\TBDML.abs.glo
文件 1100 2010-03-05 16:56 舵机调试工具\测试程序\bin\TBDML.abs.s19
文件 100713 2010-03-05 16:56 舵机调试工具\测试程序\bin\TBDML.map
文件 59 2010-03-05 16:56 舵机调试工具\测试程序\cmd\Full_Chip_Simulation_Postload.cmd
文件 60 2010-03-05 16:56 舵机调试工具\测试程序\cmd\Full_Chip_Simulation_Preload.cmd
文件 60 2010-03-05 16:56 舵机调试工具\测试程序\cmd\Full_Chip_Simulation_Reset.cmd
文件 59 2010-03-05 16:56 舵机调试工具\测试程序\cmd\Full_Chip_Simulation_SetCPU.cmd
文件 59 2010-03-05 16:56 舵机调试工具\测试程序\cmd\Full_Chip_Simulation_Startup.cmd
文件 1514 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Erase_unsecure_hcs12xe.cmd
文件 59 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Postload.cmd
文件 60 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Preload.cmd
文件 60 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Reset.cmd
文件 59 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Startup.cmd
文件 77 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Vppoff.cmd
文件 78 2010-03-05 16:56 舵机调试工具\测试程序\cmd\TBDML_Vppon.cmd
文件 855 2010-03-05 16:56 舵机调试工具\测试程序\C_Layout.hwl
文件 161 2010-03-05 16:56 舵机调试工具\测试程序\Default.mem
文件 874 2010-03-05 16:56 舵机调试工具\测试程序\Full_Chip_Simulation.ini
文件 10141 2010-03-05 16:56 舵机调试工具\测试程序\prm\burner.bbl
文件 4975 2010-03-05 16:56 舵机调试工具\测试程序\prm\Full_Chip_Simulation_li
文件 4975 2010-03-05 16:56 舵机调试工具\测试程序\prm\TBDML_li
文件 3113 2010-03-05 16:56 舵机调试工具\测试程序\readme.txt
文件 68446 2010-03-05 16:56 舵机调试工具\测试程序\Sources\datapage.c
文件 4283 2010-03-05 16:56 舵机调试工具\测试程序\Sources\main.c
文件 22599 2010-03-05 16:56 舵机调试工具\测试程序\Sources\Start12.c
文件 3008 2010-03-05 16:56 舵机调试工具\测试程序\TBDML.ini
文件 110297 2010-03-05 16:56 舵机调试工具\测试程序\test1.mcp
文件 4434 2010-03-05 16:56 舵机调试工具\测试程序\test1_Data\CWSettingsWindows.stg
............此处省略24个文件信息
评论
共有 条评论