步进电机驱动程序共31页文档.docx

上传人:b****1 文档编号:1688920 上传时间:2023-05-01 格式:DOCX 页数:18 大小:17.94KB
下载 相关 举报
步进电机驱动程序共31页文档.docx_第1页
第1页 / 共18页
步进电机驱动程序共31页文档.docx_第2页
第2页 / 共18页
步进电机驱动程序共31页文档.docx_第3页
第3页 / 共18页
步进电机驱动程序共31页文档.docx_第4页
第4页 / 共18页
步进电机驱动程序共31页文档.docx_第5页
第5页 / 共18页
步进电机驱动程序共31页文档.docx_第6页
第6页 / 共18页
步进电机驱动程序共31页文档.docx_第7页
第7页 / 共18页
步进电机驱动程序共31页文档.docx_第8页
第8页 / 共18页
步进电机驱动程序共31页文档.docx_第9页
第9页 / 共18页
步进电机驱动程序共31页文档.docx_第10页
第10页 / 共18页
步进电机驱动程序共31页文档.docx_第11页
第11页 / 共18页
步进电机驱动程序共31页文档.docx_第12页
第12页 / 共18页
步进电机驱动程序共31页文档.docx_第13页
第13页 / 共18页
步进电机驱动程序共31页文档.docx_第14页
第14页 / 共18页
步进电机驱动程序共31页文档.docx_第15页
第15页 / 共18页
步进电机驱动程序共31页文档.docx_第16页
第16页 / 共18页
步进电机驱动程序共31页文档.docx_第17页
第17页 / 共18页
步进电机驱动程序共31页文档.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

步进电机驱动程序共31页文档.docx

《步进电机驱动程序共31页文档.docx》由会员分享,可在线阅读,更多相关《步进电机驱动程序共31页文档.docx(18页珍藏版)》请在冰点文库上搜索。

步进电机驱动程序共31页文档.docx

步进电机驱动程序共31页文档

步进电机驱动程序

采用热转印制作PCB,电路采用2相推挽全桥驱动,单片机采用STC54C12C5404

学生的设计要求:

具体的模式如下:

五种模式选择

一:

停止。

二:

顺时针转2分钟,停6分钟,循环;

三:

逆时针转2分钟,停6分钟,循环;

四:

顺指针转2分钟停6分钟,逆时针转2分钟停6分钟,循环;

五:

顺指针转5分钟,逆时针转5分钟持续3小时,停9小時,循环。

请将模式四和五放在首选。

用数字码显示模式

步进电机39BYG250

品牌:

北斗型号:

39BYG技术参数

步距角:

1.8电流:

0.4A电阻:

27Ω

重量:

0.130kg驱动电压:

12V

相电流:

0.4A相数:

2环境温度:

130℃

1代表程式1,2代表程式2。

1位数码管,1个按钮

8圈/分,

每圈要分4步跳

//2010.8.26

/**************************************************

具体的模式如下:

五种模式选择

0:

停止。

1:

顺时针转2分钟,停6分钟,循环;

2:

逆时针转2分钟,停6分钟,循环;

3:

顺指针转2分钟停6分钟,逆时针转2分钟停6分钟,循环;

4:

顺指针转5分钟,逆时针转5分钟持续3小时,停9小時,循环。

模式四和五放在首选。

用数字码显示模式

1代表程式1,2代表程式2。

1位数码管,1个按钮

8圈/分,68

每圈要分4步跳

;***************************************************************/

#include"STC12C5410AD.H"//头文件

#include"intrins.h"//头文件

#defineucharunsignedchar//宏定义

#defineuintunsignedint//宏定义

#defineDPDRP2//并行数据接口定义

sbitkey=P3^2;//按键

sbitAB=P3^5;

sbitCP=P3^3;

//sbitHHH=P1^6;

sbitCLL=P3^4;

bitForward_Inversion_bit;//正转,//反转,标志

bitbit_bit;

//1:

正转

//0:

反转

bitStart_Stop_bit;//启动,停止,标志

//1:

启动

//0:

停止

//ucharcount_2;

uintcounter_3;

ucharcounter_4;

ucharForward_Tolerance_Counter;//正转容错记数器,保持步进电机不跳步

ucharInversion_Tolerance_Counter;//反转容错记数器,保持步进电机不跳步

ucharMode_Selection;//模式选择////数码管显示值

//0:

停止。

//1:

顺时针转2分钟,停6分钟,循环;

//2:

逆时针转2分钟,停6分钟,循环;

//3:

顺指针转2分钟停6分钟,逆时针转2分钟停6分钟,循环;

//4:

顺指针转5分钟,逆时针转5分钟持续3小时,停9小時,循环。

ucharTime_Counter_5;//时间计数器:

200*5=1秒

ucharTime_Counter_60;//时间计数器:

1秒*60=1分钟

ucharTime_Counter_x;//时间计数器:

1分钟*x=x分钟

ucharTime_3_by_3;//时间计数器:

3小时*3=9小时

ucharTime_30_by_30;//时间计数器:

3小时*3=9小时

#defineISP_IAP_BYTE_READ0x01//读

#defineISP_IAP_BYTE_PROGRAM0x02//编程

#defineISP_IAP_SECTOR_ERASE0x03//扇区擦除

#defineENABLE_ISP0x85//等待时间,和对ISP_CONTR设置初值

#defineEEPROM_ADDRESS_10x2800//第一扇区地址2800-29FF

#defineEEPROM_ADDRESS_20x2A00//第二扇区地址2A00-2BFF

#defineEEPROM_ADDRESS_30x2A01//第二扇区地址2A00-2BFF

//#defineEEPROM_ADDRESS_30x2C00//第三扇区地址2C00-2DFF

//#defineEEPROM_ADDRESS_40x2E00//第四扇区地址2E00-2FFF

ucharDATA_H_ADDRESS;//单片机内部EEPROM地址高字节

ucharDATA_L_ADDRESS;//单片机内部EEPROM地址低字节

uintsfr_16;//双字节缓存对单片机内部EEPROM地址字节的处理

ucharcodeDispTab_Digital[]={0xa0,0xf3,0x34,0x32,0x63,0x2a,0x28,0xb3,0x20,0x22,0xff};//数码管显示

//0;1;2;3;4;5;;

ucharcodeDispTab_Inversion[]={0x60,0x09,0x12,0x84};//反转

//d=+,c=-;

//b=+,a=-;

//c=+,d=-;

//a=+,b=-;

/*

ucharcodeDispTab_Forward[]={0xa3,0x3a,0xac,0xca};//正转

//a=-,b=+;10100011=0xa3

//c=-,d=+;00111010=0x3a

//a=+,b=-;10101100=0xac

//c=+,d=-;10001010=0xca*/

ucharcodeDispTab_Forward[]={0x84,0x12,0x09,0x60};//正转

//a=-,b=+;10100011=0xa3

//c=-,d=+;00111010=0x3a

//a=+,b=-;10101100=0xac

//c=+,d=-;10001010=0xca

voiddelay(uintz)//延时为1ms

{

ucharx,x1;

for(;z>0;z--)

{

for(x=0;x<114;x++)

{

for(x1=0;x1<1;x1++);

}

}

}

voidinit()

{

P1M1=0xff;//设为强上拉01010101

P2M1=0xff;//设为强上拉01010101

DPDR=0xaa;

TMOD=0x11;

TH1=0x16;//10ms

TL1=0xed;//10ms

TH0=0x16;//200ms

TL0=0xed;//200ms

EA=1;

ET1=1;

TR1=0;

CLL=1;

AB=1;

CP=1;

ET0=1;

TR0=1;

PT0=1;

WDT_CONTR=0x3d;//看门狗//0x3c=1.2S,,,0x3d=2.2S,,,0x3e=4.5S

counter_3=0;

counter_4=0;

bit_bit=0;

Forward_Tolerance_Counter=0;

Inversion_Tolerance_Counter=0;

Time_Counter_5=0;//时间计数器:

200*5=1秒

Time_Counter_60=0;//时间计数器:

1秒*60=1分钟

Time_Counter_x=0;//时间计数器:

1分钟*x=x分钟

Time_3_by_3=0;//时间计数器:

3小时*3=9小时

voidTimer0(void)interrupt1

{

//staticucharWDT_CONTR_Counter;

TH0=0x16;//200ms

TL0=0xed;//200ms

//WDT_CONTR_Counter++;

//if(WDT_CONTR_Counter==9)//4S喂一次狗,

//{

//WDT_CONTR_Counter=0;

//WDT_CONTR=0x3d;//看门狗

//}

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

//0:

停止。

if(Mode_Selection==0)

{

Start_Stop_bit=0;//停止。

}

//1:

顺时针转2分钟,停6分钟,循环.

elseif(Mode_Selection==1)//Forward_Inversion_bit;//正转,//反转

{

if(Start_Stop_bit==1)

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==2)

{

Time_Counter_x=0;

Start_Stop_bit=0;

Forward_Inversion_bit=1;

}

}

}

}

else

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==6)

{

Time_Counter_x=0;

Start_Stop_bit=1;

Forward_Inversion_bit=1;

}

}

}

}

}

//2:

逆时针转2分钟,停6分钟,循环;

elseif(Mode_Selection==2)//Forward_Inversion_bit;//正转,//反转

{

if(Start_Stop_bit==1)

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)//60

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==2)//2

{

Time_Counter_x=0;

Start_Stop_bit=0;

Forward_Inversion_bit=0;

}

}

}

}

else

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)//60

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==6)//6

{

Time_Counter_x=0;

Start_Stop_bit=1;

Forward_Inversion_bit=0;

}

}

}

}

}

//3:

顺指针转2分钟停6分钟,逆时针转2分钟停6分钟,循环;

elseif(Mode_Selection==3)//Forward_Inversion_bit;//正转,//反转

{

if(Start_Stop_bit==1)

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==2)

{

Time_Counter_x=0;

Start_Stop_bit=0;

Forward_Inversion_bit=~Forward_Inversion_bit;

}

}

}

}

else

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==6)

{

Time_Counter_x=0;

Start_Stop_bit=1;

}

}

}

}

}

//4:

顺指针转5分钟,逆时针转5分钟持续3小时,停9小時,循环。

elseif(Mode_Selection==4)

{

if(Start_Stop_bit==1)

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Start_Stop_bit=1;

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)//60

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==5)//5分钟

{

Time_Counter_x=0;

Forward_Inversion_bit=!

Forward_Inversion_bit;

Time_3_by_3++;

if(Time_3_by_3==36)//36//3钟

{

Start_Stop_bit=0;

Time_3_by_3=0;

TH1=0x16;//200ms

TL1=0xed;//200ms

TR0=0;

TR1=1;

}

}

}

}

}

voidTimer1(void)interrupt3

{

//staticucharcount;

TH1=0x16;//200ms

TL1=0xed;//200ms

if(Mode_Selection==4)

{

if(Start_Stop_bit==0)

{

Time_Counter_5++;//时间计数器:

200*5=1秒

if(Time_Counter_5==5)

{

Start_Stop_bit=0;

Time_Counter_5=0;

Time_Counter_60++;//时间计数器:

1秒*60=1分钟

if(Time_Counter_60==59)//60

{

Time_Counter_60=0;

Time_Counter_x++;//1分钟*x=x分钟

if(Time_Counter_x==59)//60分钟

{

Time_Counter_x=0;

Time_3_by_3++;

if(Time_3_by_3==9)//9钟

{

Start_Stop_bit=1;

Time_3_by_3=0;

Forward_Inversion_bit=1;

TH0=0x16;//200ms

TL0=0xed;//200ms

TR0=1;

TR1=0;

}

}

}

}

}

voidIAP_Disable()//关闭IAP

{

ISP_CONTR=0;

ISP_CMD=0;

ISP_TRIG=0;

}

voidByte_read()//读

{

uintsfr_sfr;

sfr_sfr=sfr_16;

DATA_L_ADDRESS=sfr_sfr;//低地址字节

sfr_sfr>>=8;

DATA_H_ADDRESS=sfr_sfr;//高地址字节

ISP_CONTR=ENABLE_ISP;

ISP_CMD=ISP_IAP_BYTE_READ;

ISP_ADDRH=DATA_H_ADDRESS;

ISP_ADDRL=DATA_L_ADDRESS;

//EA=0;

ISP_TRIG=0x46;

ISP_TRIG=0xb9;

_nop_();

//EA=1;

//ISP_DATA//读出的数据在ISP_DATA

IAP_Disable();

}

voidByte_program(ucharByte_data)////编程//Byte_data为要保存的数据

{

uintsfr_sfr;

sfr_sfr=sfr_16;

DATA_L_ADDRESS=sfr_sfr;//低地址字节

sfr_sfr>>=8;

DATA_H_ADDRESS=sfr_sfr;//高地址字节

ISP_CONTR=ENABLE_ISP;

ISP_CMD=ISP_IAP_BYTE_PROGRAM;

ISP_ADDRH=DATA_H_ADDRESS;

ISP_ADDRL=DATA_L_ADDRESS;

ISP_DATA=Byte_data;

//EA=0;

ISP_TRIG=0x46;

ISP_TRIG=0xb9;

_nop_();

//EA=1;

//IAP_Disable();

}

voidSector_Erase()//扇区擦除

{

uintsfr_sfr;

sfr_sfr=sfr_16;

DATA_L_ADDRESS=sfr_sfr;//低地址字节

sfr_sfr>>=8;

DATA_H_ADDRESS=sfr_sfr;//高地址字节

ISP_CONTR=ENABLE_ISP;

ISP_CMD=ISP_IAP_SECTOR_ERASE;

ISP_ADDRH=DATA_H_ADDRESS;

ISP_ADDRL=DATA_L_ADDRESS;

//EA=0;

ISP_TRIG=0x46;

ISP_TRIG=0xb9;

_nop_();

//EA=1;

//IAP_Disable();//关闭IAP

}

voidDigital_Tube()//数码管显示

{

//ucharii,temp,a;

//P1=DispTab_Digital[2];

P1=DispTab_Digital[Mode_Selection];

//HHH=0;

}

voidKey_Detection()//按键检测

{

if(Mode_Selection>4)

{

Mode_Selection=0;

}

if(key==0)

{

delay(20);

if(key==0)

{

Digital_Tube();//数码管显示

while(key==0);

delay(20);

if(Mode_Selection==0)

{

Mode_Selection=1;

Start_Stop_bit=1;

Forward_Inversion_bit=1;

}

elseif(Mode_Selection==1)

{

Mode_Selection=2;

Start_Stop_bit=1;

Forward_Inversion_bit=0;

}

elseif(Mode_Selection==2)

{

Mode_Selection=3;

Start_Stop_bit=1;

Forward_Inversion_bit=1;

}

elseif(Mode_Selection==3)

{

Mode_Selection=4;

Start_Stop_bit=1;

Forward_Inversion_bit=1;

}

elseif(Mode_Selection==4)

{

Mode_Selection=0;

Start_Stop_bit=0;

Forward_Inversion_bit=1;

}

elseif(Mode_Selection==0)

{

Mode_Selection=1;

//Start_Stop_bit=0;

//Forward_Inversion_bit=1;

}

Time_Counter_5=0;//时间计数器:

200*5=1秒

Time_Counter_60=0;//时间计数器:

1秒*60=1分钟

Time_Counter_x=0;//时间计数器:

1分钟*x=x分钟

Time_3_by_3=0;//时间计数器:

3小时*3=9小时

counter_3=0;

counter_4=0;

bit_bit=0;

sfr_16=EEPROM_ADDRESS_1;

Sector_Erase();//扇区擦除

Byte_program(Mode_Selection);////编程

IAP_Disable();

Digital_Tube();//数码管显示

}

}

}

voidDatabase_Refresh()//刷新数据库

{

sfr_16=EEPROM_ADDRESS_1;

Byte_read();//读

Mode_Selection=ISP_DATA;

if(Mode_Selection>4)

{

Mode_Sel

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2