⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hardwareopration.c

📁 飞思卡尔智能车用的决策程序,这是由参加过的研究生提供的例子
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

#define uch unsigned char

extern uch pic[40][40];
extern uch gpline,gppoint,gpflag,tline,tpoint,mdelay;

/*  These are used for other programs
extern void set_motor(uch,uch);
extern void set_DJ(unsigned short);
extern void get_pic(uch *);
*/

// set motor speed
void set_motor(uch fward,uch bward) {
  PWMDTY0=fward;
  PWMDTY1=bward;
}

// set the direction
void set_DJ(unsigned short DJ) {
  PWMDTY45=DJ;
}

// get a picture
void get_pic(void) {
  gpline=0;
  gpflag=0;
  while((PTIH&0x02)!=0);
  EnableInterrupts;
  TC0=TCNT+0x0C00;
  TFLG1=0xFF;
  TIE=0x01;
  while(gpflag==0);
  DisableInterrupts;
}


// Vector 6 Interrupt:start get a line
interrupt 6 void line_start(void) {
  INTCR=0;
  if(gpline==40)
    gpflag=1;
  else {
    gppoint=0;
    TC1=TCNT+mdelay;
    TFLG1=0x0F;
    TIE=2;
  }
}

// Vector 8 Interrupt:Timer0
interrupt 8 void timer0(void) {
  TIE=0;
  INTCR=0x40;
}

// Vector 9 Interrupt:Timer1
interrupt 9 void timer1(void) {
  uch *p;
  TIE=0;
  p=&(pic[gpline][0]);
  ATD0CTL2=0xC0;
  ATD0CTL5=0x80;
  asm{
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
  }
  ATD1CTL2=0xC0;
  ATD1CTL5=0x80;
  while(gppoint!=38) {
    while((ATD0STAT1&0x01)==0);
    *p=ATD0DR0L;
    ATD0CTL5=0x80;
    p++;
    gppoint++;
    while((ATD1STAT1&0x01)==0);
    *p=ATD1DR0L;
    ATD1CTL5=0x80;
    p++;
    gppoint++;
  }
  while((ATD0STAT1&0x01)==0);
  *p=ATD0DR0L;
  p++;
  while((ATD1STAT1&0x01)==0);
  *p=ATD1DR0L;
  TC2=TCNT+1056;   //1056=5.5*64*3
  TFLG1=0xFF;
  TIE=0x04;
  gpline++;
}

// Vector 10 Interrupt:Timer2
interrupt 10 void timer2(void) {
  TIE=0;
  INTCR=0x40;
}

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -