步进电机角度控制

上传人:新** 文档编号:432598501 上传时间:2024-01-04 格式:DOC 页数:12 大小:33.50KB
返回 下载 相关 举报
步进电机角度控制_第1页
第1页 / 共12页
步进电机角度控制_第2页
第2页 / 共12页
步进电机角度控制_第3页
第3页 / 共12页
步进电机角度控制_第4页
第4页 / 共12页
步进电机角度控制_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《步进电机角度控制》由会员分享,可在线阅读,更多相关《步进电机角度控制(12页珍藏版)》请在金锄头文库上搜索。

1、步进电机角度控制1. 编程控制步进电机顺时针行走,180度(角度显示在七段LED上),3秒后行走45度(显示角度),3秒后行走90度(显示角度),3秒后行走180度,依次循环。#include #define uchar unsigned char#define uint unsigned int#define PA 0x60#define PB 0x61#define PC 0x62#define CTRL 0x63uchar pai=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09;uchar teble=0x3f,0x06,0x5b,0x4f,0x66,0x

2、6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;uint m=0;uchar a3,a2,a1,a0=0;void delay(uint xms)uint i,j;for(i=xms;i0;i-)for(j=110;j0;j-);void display()outp(PA,teblea0);outp(PB,0x07);delay(10);outp(PA,teblea1);outp(PB,0x0b);delay(10);outp(PA,teblea2);outp(PB,0x0d);delay(10);outp(PA,teblea3);o

3、utp(PB,0x0e);delay(10);void zhuan(uint zz)uint temp,i,j;a3=zz/1000a2=(zz%1000)/100;a1=(zz%100)/10;a0=(zz%10);temp=(uint)(zz/15*4);for(i=temp;i0;i-) for(j=3;j0;j-)display();outp(PC,paim);m+;if(m7)m=0;void main()int i;outp(CTRL,0x88);while(1)zhuan(180);for(i=75;i0;i-)display();zhuan(45);for(i=75;i0;i-

4、)display();zhuan(90);for(i=75;i0;i-)display();2. 完成A/D转换实验并把转换结果在七段LED上显示出来。#include #define uchar unsigned char#define uint unsigned int#define PA 0x60#define PB 0x61#define PC 0x62#define CTRL 0x63#define AD 0x00uchar pai=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09;uchar teble=0x3f,0x06,0x5b,0x4f,0x66

5、,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;uint m=0;uchar a3,a2,a1,a0;void delay(uint xms)uint i,j;for(i=xms;i0;i-)for(j=110;j0;j-);void display()outp(PA,teblea0);outp(PB,0x07);delay(10);outp(PA,teblea1);outp(PB,0x0b);delay(10);outp(PA,teblea2);outp(PB,0x0d);delay(10);outp(PA,teblea3);

6、outp(PB,0x0e);delay(10);void main()int temp=0;outp(CTRL,0x88);while(1)outp(AD,0x0d);temp=inp(AD);a3=0;a2=0;a1=temp/16;a0=(temp%16);display();3. 如实验指导书(3)。#include #define uchar unsigned char#define uint unsigned int#define PA 0x60#define PB 0x61#define PC 0x62#define CTRL 0x63#define AD 0x00uchar pa

7、i=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09; /正转电机时序uchar pai_fan=0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01; /反转电机时序uchar teble=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, /数码管段选 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;uint jiao=0,0,0; /贮存三次设置的电机角度uint m=0; /记录电机相序uint disp; /数码管显示的数值uint set_flag,jiao_max

8、,jiao_now,change_flag=1,zhuan_flag;uint qian,bai,shi,ge; void delay(uint xms) /延时函数,约一毫秒uint i,j;for(i=xms;i0;i-)for(j=110;j0;j-);void display() /显示子程序uchar a3,a2,a1,a0;uint temp1,temp;if(change_flag=0) /如果change_flag=0;显示实时AD转换后对应的角度 /否则显示dispoutp(AD,0x0d);temp=inp(AD);if(temp=0)temp=1;temp1=(jiao_

9、max*50)/256;temp1=temp*temp1;temp1=temp1/50;disp=temp1;a3=disp/1000; /分别取所显示数字的千,百,十,个位a2=(disp%1000)/100;a1=(disp%100)/10;a0=disp%10;outp(PA,teblea0); /送段选outp(PB,0x07); /送位选delay(10); /延时outp(PA,teblea1);outp(PB,0x0b);delay(10);outp(PA,teblea2);outp(PB,0x0d);delay(10);outp(PA,teblea3);outp(PB,0x0e

10、);delay(10);void fan_zhuan(uint xx) /电机反转程序static uint temp,i,j;temp=(xx*10)/15*4); temp=temp/10; /计算要转的拍for(i=temp;i0;i-) for(j=1;j0;j-)display();outp(PC,pai_fanm); /反转m+;if(m7) /8拍,如果等于8拍,从新m=0;void zhuan(uint zz) /正转static uint temp,i,j;temp=(zz*10)/15*4);temp=temp/10;for(i=temp;i0;i-) for(j=1;j0

11、;j-)display();outp(PC,paim);m+;if(m7)m=0;void key_bai() /键百,每按一次加一百,要进位时,自减一千static uint temp,temp1;change_flag=1;temp=jiao_max/1000;jiao_max=jiao_max+100;temp1=jiao_max/1000;if(temp1-temp)=1)jiao_max=jiao_max-1000;disp=jiao_max;void key_set() /键SET,static uint temp,temp1;change_flag=0;outp(AD,0x0d); /读取当前AD值temp=inp(AD);if(temp=0)temp=1;temp1=(jiao_max*50)/256; /转换成要旋转的角度。temp1=temp*temp1;temp1=temp1/50;if(set_flag=0)disp=temp1;elsejiaoset_flag-1=temp1; /存储到JIAO数组中。disp=temp1;set_flag+;if(set_flag=4) /存储3个角度set_flag=0;change_flag=1;void key_clr() /键CLR,主要

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 建筑资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号