📄 eeprom.c
字号:
/** ###################################################################
** Filename : eeprom.C
** Project : eeprom
** Processor : MC9S12HZ64CFU
** Version : Driver 01.12
** Compiler : CodeWarrior HC12 C Compiler
** Date/Time : 2008-12-15, 上午 10:41
** Abstract :
** Main module.
** Here is to be placed user's code.
** Settings :
** Contents :
** No public methods
**
** (c) Copyright UNIS, spol. s r.o. 1997-2007
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE eeprom */
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Events.h"
#include "IEE1.h"
#include "EInt1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
//#include <hidef.h> /* common defines and macros */
//#include <MC9S12HZ64.h> /* derivative information */
word keptDataA,keptDataB,keptDataC,eResultA,eResultB,eResultC,eResultP;//保存在EEPROM中的数据 keptDataA,keptDataB,keptDataC代表三个步进电机
word keptPole;//正反转
extern char sFlag;//进样器动作前的标志位
void delay1s(void); //延迟函数
int i;
int j;
int xd,yd,zd;//x/y/z方向脉冲个数
const int iX1=30; //进样器共5行10列,这里定义平面上每一个的坐标,用以计算每个点到零点的距离
const int iX2=40;//X方向
const int iX3=50;
const int iX4=60;
const int iX5=70;
const int iX6=80;
const int iX7=90;
const int iX8=100;
const int iX9=110;
const int iX10=120;
const int iY1=20;//Y方向
const int iY2=30;
const int iY3=40;
const int iY4=50;
const int iY5=60;
const int iZ=50;//Z方向为一固定值
void main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
//从EEPROM中读数据
IEE1_GetWord(0x808,&eResultA);
keptDataA=eResultA;//读出步进电机A的数据
IEE1_GetWord(0x810,&eResultB);
keptDataB=eResultB;//读出步进电机B的数据
IEE1_GetWord(0x812,&eResultC);
keptDataC=eResultC;//读出步进电机C的数据
IEE1_GetWord(0x814,&eResultP);
keptPole=eResultP;//读出步进电机正反转标志
DDRP=0xff;//把port P端口设置为输出,用以输出方波
DDRA=0xff;//把port A端口设置为输出,用以输出高低点评,控制电机的转动方向
//步进电机M1的四个管教分别对应Vcc/PP5/PA0/PA1
//步进电机M2的四个管教分别对应Vcc/PP4/PA2/PA3
//步进电机M3的四个管教分别对应Vcc/PP3/PA4/PA5
//步进电机M4的四个管教分别对应Vcc/PP1/PA6/PA7
for(;sFlag='T';){
}
//利用循环,判断当前是对第几个样品进行操作
//if (sFlag='T')
for(i=1;(i<=50 );i++) {
switch (i){
case 1: //运行到X1 Y1 Z的点
xd=iX1;
yd=iY1;
zd=iZ;
break;
case 2: //运行到X1 Y2 Z的点
xd=iX1;
yd=iY2;
zd=iZ;
break;
case 3: //运行到X1 Y3 Z的点
xd=iX1;
yd=iY3;
zd=iZ;
break;
case 4: //运行到X1 Y4 Z的点
xd=iX1;
yd=iY4;
zd=iZ;
break;
case 5: //运行到X1 Y5 Z的点
xd=iX1;
yd=iY5;
zd=iZ;
break;
case 6: //运行到X2 Y1 Z的点
xd=iX2;
yd=iY1;
zd=iZ;
break;
case 7: //运行到X2 Y2 Z的点
xd=iX2;
yd=iY2;
zd=iZ;
break;
case 8: //运行到X2 Y3 Z的点
xd=iX2;
yd=iY3;
zd=iZ;
break;
case 9: //运行到X2 Y4 Z的点
xd=iX2;
yd=iY4;
zd=iZ;
break;
case 10: //运行到X2 Y5 Z的点
xd=iX2;
yd=iY5;
zd=iZ;
break;
case 11: //运行到X3 Y1 Z的点
xd=iX3;
yd=iY1;
zd=iZ;
break;
default:
i++;
}
}
sFlag='F';//标志位恢复到'F'
//M1电机运动到xd
PORTA_BIT0=0xFF;//PA0输出高电平(正转),即用PA0控制电机方向
for (j=0;j<=xd;j++){
PTP_PTP5=0xff;// PP5输出高电平
delay1s();
PTP_PTP5=0x00;//PP5输出低电平
delay1s();
}
PTP_PTP5=0x00;//M1停止后,PP5输出低电平
//M2电机运动到iY1
PORTA_BIT2=0xff;//PA2输出高电平(正转),即用PA2控制电机方向
for (j=0;j<=yd;j++){
PTP_PTP4=0xff;// PP4输出高电平
delay1s();
PTP_PTP4=0x00;//PP4输出低电平
delay1s();
}
PTP_PTP4=0x00;//M2停止后,PP4输出低电平
//M3电机运动到iZ
PORTA_BIT4=0xff;//PA4输出高电平(正转),即用PA4控制电机方向
for (j=0;j<=zd;j++){
PTP_PTP3=0xff;// PP3输出高电平
delay1s();
PTP_PTP3=0x00;//PP3输出低电平
delay1s();
}
PTP_PTP3=0x00;//M3停止后,PP3输出低电平
//延迟等待一段时间后,返回零点
//M1电机返回到X0
PORTA_BIT0=0x00;//PA0输出低电平(反转)
for (j=0;j<=xd;j++){
PTP_PTP5=0xff;// PP5输出高电平
delay1s();
PTP_PTP5=0x00;//PP5输出低电平
delay1s();
}
PTP_PTP5=0x00;//M1停止后,PP5输出低电平
//M2电机返回到Y0
PORTA_BIT2=0x00;//PA2输出高电平(反转)
for (j=0;j<=yd;j++){
PTP_PTP4=0xff;// PP4输出高电平
delay1s();
PTP_PTP4=0x00;//PP4输出低电平
delay1s();
}
PTP_PTP4=0x00;//M2停止后,PP4输出低电平
//M3电机返回到Z0
PORTA_BIT4=0x00;//PA4输出高电平(反转)
for (j=0;j<=zd;j++){
PTP_PTP3=0xff;// PP3输出高电平
delay1s();
PTP_PTP3=0x00;//PP3输出低电平
delay1s();
}
PTP_PTP3=0x00;//M3停止后,PP3输出低电平
i++;
//通过调用延迟函数,实现波形输出
//DDRP=0xff;/* as output */
//DDRA=0xff;
//for (j=0;j<=10000;j++){
// PTP=0xff;
// PORTA=0xff;
// delay1s();
// i=0;
// PTP=0x00;
// delay1s();
// i=0;
//}
//PTP=0x00;
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
for(;;){
}
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
void delay1s(void)//延迟
{
for(i=0;i<1000;i++){}
}
/* END eeprom */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 2.98 [03.98]
** for the Freescale HCS12 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -