资源描述:
《单片机控制步进电机转动程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、xxxxxxxxxxxxxxxxxxx#include"reg52.h"#include"INTRINS.H"#include#include#defineuintunsignedint#defineucharunsignedchar#defineACC_LEVEL42#defineDEC_LEVEL42#defineSTOP_LEVEL42#defineUP_LEVEL(ACC_LEVEL-2)#defineDOWN_LEVEL1ucharcodeslave_a
2、ddr[4]={00,01,02,255};ucharcodec1[10]={0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xA0,0xA2};ucharcodec2[10]={0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0xB0,0xB2};/*加速过程各档速度定时器初值,用16位的T2实现*/uintcodeacc_pulse_T2_const[ACC_LEVEL]={64170,64170,64841,65065,6517
3、6,65243,65288,65320,65344,65362,65377,65389,65399,65407,65415,65421,65426,65431,65435,65439,65443,65446,65448,65451,65453,65455,65457,65459,65461,65462,65464,65465,65466,65467,65468,65469,65470,65471,65472,65473,65474,65474};/*加速过程各档速度加速持续时间(用脉冲数表示),用1
4、6位的T0计数,计数器初值*/uintcodeacc_time_T0_const[ACC_LEVEL]={65463,65463,65460,65458,65455,65452,65449,65446,65443,65440,65436,65433,65429,65425,65421,65417,65413,65409,65404,65399,65395,65389,65384,65379,65373,65368,65362,65355,65349,65342,65335,65328,65321,6
5、5313,65305,65297,65289,65280,65271,65261,65251,65251};/*减速过程各档速度定时器初值,用16位的T2实现*/uintcodedec_pulse_T2_const[DEC_LEVEL]={64170,64170,64841,65065,65176,65243,65288,65320,65344,65362,65377,65389,65399,65407,65415,65421,65426,65431,65435,65439,65443,65446,
6、65448,65451,65453,65455,65457,65459,65461,65462,65464,65465,65466,65467,65468,65469,65470,65471,65472,65473,65474,65474};/*减速过程各档速度减速持续时间(用脉冲数表示),用16位的T0计数,计数器初值*/uintcodedec_time_T0_const[DEC_LEVEL]={65463,65463,65460,65458,65455,65452,65449,65446,654
7、43,65440,65436,65433,65429,65425,65421,65417,65413,65409,65404,65399,65395,65389,65384,65379,65373,65368,65362,65355,65349,65342,65335,65328,65321,65313,65305,65297,65289,65280,65271,65261,65251,65251};/*停机过程各档速度定时器初值,用16位的T2实现*/uintcodestop_pulse_T2_c
8、onst[STOP_LEVEL]={64170,64170,64841,65065,65176,65243,65288,65320,65344,65362,65377,65389,65399,65407,65415,65421,65426,65431,65435,65439,65443,65446,65448,65451,65453,65455,65457,65459,65461,65462,65464,65465,65466,65467,65468,65469,65