已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
步进电机角度控制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,0x6d,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);outp(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-)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,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);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 pai=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,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_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);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;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,主要是让电机反转回到原来的位置。static uint temp;change_flag=1;if(zhuan_flag=1) /加个标志,如果没有按下START,则按CLR不反转。zhuan_flag=0;temp=jiao0+jiao1;temp=temp+jiao2;/temp=temp%360;disp=temp;fan_zhuan(temp);disp=0;set_flag=0;jiao0=0; /清楚角度值jiao1=0;jiao2=0;void key_qian() /键百,每按一次加一千,要进位时,自减一万。static uint temp,temp1;change_flag=1;temp=jiao_max/10000;jiao_max=jiao_max+1000;temp1=jiao_max/10000;if(temp1-temp)=1)jiao_max=jiao_max-10000;disp=jiao_max;void key_ge() /键百,每按一次加一,要进位时,自减一十static uint temp,temp1;change_flag=1;temp=jiao_max/10;jiao_max=jiao_max+1;temp1=jiao_max/10;if(temp1-temp)=1)jiao_max=jiao_max-10;disp=jiao_max;void key_kong() /有一个按键没用到。change_flag=1;void key_shi() /键百,每按一次加十,要进位时,自减一百。static uint temp,temp1;change_flag=1;temp=jiao_max/100;jiao_max=jiao_max+10;temp1=jiao_max/100;if(temp1-temp)=1)jiao_max=jiao_max-100;disp=jiao_max;void key_start() /开始旋转,转了三个角度后停止。static uint i;change_flag=1;zhuan_flag=1;set_flag=0;disp=jiao0; zhuan(jiao0);for(i=75;i0;i-)display();disp=jiao1;zhuan(jiao1);for(i=75;i0;i-)display();disp=jiao2;zhuan(jiao2);for(i=75;i0;i-)display();disp=0;void keyscan() /键盘扫描。static uint temp,temp1;outp(PB,0xfe); /set baitemp=inp(PC);temp=temp&0xc0;if(temp!=0xc0) /有按键按下。switch(temp)case 0x80:key_set();break;case 0x40:key_bai();break;while(temp!=0xc0) /等待按键放松display();outp(PB,0xfe);temp=inp(PC);temp=temp&0xc0;outp(PB,0x0d); temp=inp(PC);temp=temp&0xc0;if(temp!=0xc0)switch(temp)case 0x80:key_qian();break;case 0x40:key_clr();break;while(temp!=0xc0)display();outp(PB,0x0d);temp=inp(PC);temp=temp&0xc0;outp(PB,0x0b);temp=inp(PC);temp=temp&0xc0;if(temp!=0xc0)switch(temp)case 0x80:key_kong();break;case 0x40:key_ge();break;while(temp!=0xc0)display();outp(PB,0x0b);temp=inp(PC);temp=temp&0xc0;outp(PB,0x07);temp=inp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江西省2025年第一季度特种作业安全技术(一类)考核金属非金属矿山爆破作业练习题及答案
- 2025年甘肃干部遴选真题及答案
- 2025年学业水平试卷及答案化学
- 2025吊车的租赁合同模板
- 康复医学科脊柱裂康复护理规范
- 2026年南昌健康职业技术学院单招职业适应性测试题库附答案
- 2026年太湖创意职业技术学院单招职业倾向性测试题库及答案1套
- 2026年吉林省四平市单招职业倾向性考试题库及答案1套
- 2025年铸造工程师考试试题及答案
- 2025年教师职称考试(化学)(高中)综合练习题及答案
- 2025届中国兵器装备集团有限公司校园招聘全面启动笔试参考题库附带答案详解(10套)
- 2025年山东省春季高考语文试卷试题真题(含答案详解)
- 【课件】第13章++综合与实践++确定匀质薄板的重心位置+课件++2025-2026学年人教版八年级数学上册
- 美的微波炉TG7XCG7-NSH使用说明书
- 2025西藏开发投资集团有限公司招聘86人笔试历年参考题库附带答案详解
- 教师招聘之幼儿教师招聘题库
- 粤教花城版(2024)一年级上册音乐全册教案(教学设计)
- DB42∕T 1902-2022 中小学生营养配餐指南
- 输血法规培训课件
- 静脉血管通路护理
- 网点保险营销技巧
评论
0/150
提交评论