基于磁场导航智能车控制器的设计(7)

2018-12-25 22:40

//-------------电机驱动初始化-----------------// void TheMotor_Init() {

PWME=0x00;

PWMDTY0=0x00; //(5/50)*100 PWMPER0=0x64; PWMDTY1=0x00; PWMPER1=0x64;

PWMDTY23=0; //1.5ms PWMPER23=0x2710; PWME=0x0f; }

//-----------ATD模块-----------// void ATD_Init() {

ATD0CTL1=0x00;

ATD0CTL2=0X40; //使能AD,清除标志 */

ATD0CTL3=0Xb0; //队列长度为6,依次存入结果寄存器,继续转换 */ ATD0CTL4=0X05; //8位精度,总线频率32分频 */ ATD0CTL5=0X30; //多通道转换 0开始转换*/ ATD0DIEN=0x0f; //禁止数字输入 }

//----------定时器初始化程序-------//

/* void ECT_Init(void) //ECT初始化,使用输入捕捉功能 {

TIOS =0x00; //设为输入捕捉 TSCR1=0x80; //定时器使能 TSCR2=0x07;

TIE=0b00000001; //开中断

TCTL4=0b00000010; //0 ,1触发电平: TC0=888; } */

//*********J口外部中断检测起跑线********************* void PJ7_Init(void)

{

DDRJ = 0X00; // PJ0判断行同步脉冲到达 PPSJ = 0x80; // 上升沿

//PPSJ = 0x00; // 下降沿 PIEJ = 0X80; PERJ = 0xff; }

//----------PIT初始化------------//

void Pit0_Init(void) {

PITCFLMT_PITE=0; //disable PIT

PITCE_PCE0=1; //enable timer channel 0

PITMUX_PMUX0=0; //ch0 connected to micro timer 0

PITMTLD0=0X0a; //micro PITLD0=0Xff00; //time-out + 1) /

// //For maximum time

//1 * 6400 * /64000000 = 0.0001s. PITINTE_PINTE0=1; //enable interupt channel 0 PITCFLMT_PITE=1; //enable PIT } /*

void Pit1_Init(void) {

PITCFLMT_PITE=0; //disable PIT

PITCE_PCE1=1; //enable timer channel 1 PITMUX_PMUX1=0; //ch1 connected to micro timer 1

PITMTLD1=0X0f ; //micro PITLD1=0Xffff; //time-out + 1) /fbus

// //For example, for a 16 MHz bus clock, the

maximum time

//15 * 65536 * /64000000 = 0.01536s..

PITINTE_PINTE1=1; //enable interupt channel 1

time base 0 equals 255 clock cycles period = (PITMTLD + 1) * (PITLD 时间计算

example, for a 16 MHz bus clock, the time base 1 equals 255 clock cycles period = (PITMTLD + 1) * (PITLD 时间计算

PITCFLMT_PITE=1; //enable PIT } */

/////////////////////////////////////

//------------PACNT初始化------------// void PACN_Init(void) {

PACTL=0x10; //启动脉冲累加器A PACNT =0x0000;

PAFLG=0x01; //脉冲数入1=IOC7-PT7,最大65536个脉冲 PACTL=0x10|0x40; //16b计数允许 }

//----------IO口初始化-------------// void IO_Init(void) {

DDRA=0xFF; PORTA=0x00; DDRB=0xFF; PORTB=0x00;

DDRE_DDRE5=1; /* PTE5 as output */ DDRE_DDRE6=1; /* PTE6 as output */ DDRB_DDRB3=0; /* PTE6 as output */ DDRB_DDRB5=1; /* PTE6 as output */ DDRB_DDRB7=1; /* PTE6 as output */ PORTE_PE5=1; /* LEDs off */ PORTE_PE6=1; /* LEDs off */ PORTB_PB3=1; /* LEDs off */ }

//-------------主程序------------// void main(void) {

DisableInterrupts; SetBusCLK_64M(); ATD_Init(); PACN_Init(); Pit0_Init(); PJ7_Init(); IO_Init();

jianche(30000); delay(2000); PWM_Init();

TheMotor_Init(); Led_left=1; Led_right=1; //Sudu(100);

EnableInterrupts; asm { nop }

for(;;) {

Speed_con();

//KEY_SCAN(); //PWMDTY23=1570;

_FEED_COP(); /* feeds the dog */ } }

//-----------------------中断函数处理-------------------// /*

#pragma CODE_SEG __NEAR_SEG NON_BANKED

void interrupt 8 Timer0_ISR(void) //8 为定时器通道 0 输出比较的中断标号 {

TFLG1_C0F=1; //清中断标志位 m=TCNT;

TC0=m+3700; //37500*2.67us=10ms 定时时间 waittime++;

if(waittime==20) {

waittime=0; //Led5=~Led5; //Led6=~Led6; //Led7=~Led7; }

}

#pragma CODE_SEG DEFAULT */

//------------------------------------------------//

int jianche(int xms) {

int d,e;

for(d=0;d

for(e=0;e<=50;e++) {

KEY_SCAN(); } } }

//-------------PIT中断-------------//

#pragma CODE_SEG __NEAR_SEG NON_BANKED //指示该程序在不分页区 void interrupt 66 PIT0(void) {

PITTF_PTF0=1; //CLER FLAG FeedBack=PACNT; PACNT=0x0000; }

#pragma CODE_SEG DEFAULT

/* ////////////////////////////////// #pragma CODE_SEG __NEAR_SEG NON_BANKED

void interrupt 67 PIT1_ISR(void) {

PITTF_PTF1=1; //CLER FLAG r++;

if(r==20) {

r=0;

Led5=~Led5; Led6=~Led6; //PWMDTY0=0; //PWME=0x0f;

//PITCE_PCE1=0;

//PITINTE_PINTE1=0; //DISable interupt channel 0 } }

#pragma CODE_SEG DEFAULT */

#pragma CODE_SEG __NEAR_SEG NON_BANKED void interrupt 24 PORTJ_ISR(void) {

PIFJ_PIFJ7=1; //清除中断标志位 n++;

if(n==2) {

PIFJ_PIFJ7=0;

Led_right=0; Led_left=0; PWMDTY23=1570; PWME_PWME0=1; PWME_PWME1=0; PWMDTY0=30; delay(500); PWME_PWME0=0; PWME_PWME1=0; } }

#pragma CODE_SEG DEFAULT


基于磁场导航智能车控制器的设计(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:生化期末复习答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: