sys.c
来自「这是Mc9sdg128的舵机调试程序,适合进行智能小汽车的调试.」· C语言 代码 · 共 43 行
C
43 行
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include "SYS.h"
/***************variables define ************************/
unsigned char AD[9]; //AD结果值
unsigned char rudder, speed,stop,i,buf;
//rudder 为送舵机控制量值,speed为送速度控制量值,
//stop为送刹车控制量值,
//i为循环变量,buf 为 PB的缓冲值,count为计时器溢出次数。
char lastposition,position,positionbuf,pola;
//lastposition 为上个循环的位置值,
//position为位置值,positionbuf为位置的暂存值,pola为位置的极性
unsigned int time,count,lasttime,thistime;
//time为小轮一圈的时间1表示0.0013653s 一圈4cm
//timeset为time的设定值,timebuf为time的暂存值
/************************subroutine define****************/
#pragma CODE_SEG DEFAULT
void SYS_Init()
{
rudder=RUDDERDEFAULT;
speed=SPEEDDEFAULT;
stop=STOPDEFAULT;
pola=1;
position=0;
positionbuf=0;
count=0;
lasttime=0;
thistime=0;
DDRA=0x0;
DDRB=0xff;
DDRH=0x00;
CLK_Init();
ECT_Init();
PWM_Init();
AD_Init();
}
void CLK_Init()
{
CLKSEL_PLLSEL = 0x0;
REFDV = REFDV_VALUE; // 选择分频以及倍频系数
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?