2011年11月18日
摘要: #include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit wela=P2^0;sbit dula=P2^1;uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};uchar Data[8]; //存储显示值的全局变量sbit dc1=P1^1; //定义电机信号输出端口uchar 阅读全文
posted @ 2011-11-18 21:54 舒 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 程序一与程序二的区别在于程序一的两个延时函数是先声明后定义,而程序二的两个延时函数是直接在主函数之前定义的并未声明。这两个平时看似可以互换的两种函数定义的方法,在此显出了其中的差异,单往单片机中烧录程序一的时候步进电机会一直转动,不停止,(其原因是此种情况下,主函数在反复执行,所以会不停的重复正转)而按程序来分析步进电机在转过几圈之后会自动停止,这显然与结果冲突。而当往单片机中烧录程序二的时后步进电机却再转了几圈后停止。以后要注意直接将函数定义在主函数之前。二程序一:#include<reg52.h>#define uchar unsigned char#define uint u 阅读全文
posted @ 2011-11-18 19:57 舒 阅读(256) 评论(0) 推荐(2) 编辑
摘要: /*占空比,方波,直流电机高电平有效*/#include<reg52.h>#define uchar unsigned char#define uint unsigned int sbit wela=P2^0;sbit dula=P2^1;uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};uchar Data[8];sbit dc1=P1^1; //定义电机信号输 阅读全文
posted @ 2011-11-18 19:57 舒 阅读(310) 评论(0) 推荐(0) 编辑
摘要: #include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit d1=P1^0; //定义步进电机连接端口sbit d2=P1^1;sbit d3=P1^2;sbit d4=P1^3;//分四步转动步进电机#define A {d1=1,d2=0,d3=0,d4=0;}//A相通电,其他相断电 #define B {d1=0,d2=1,d3=0,d4=0;}//B相通电,其他相断电#define C {d1=0,d2=0,d3=1,d4=0;}//C相通电,其他相断电#define D {d1=0, 阅读全文
posted @ 2011-11-18 19:56 舒 阅读(312) 评论(0) 推荐(1) 编辑
摘要: /*原理基本与步进电机的调速原理相同,不同之处在于新增加了两个功能,即控制步进电机的停止与运行两个功能。这两个功能通过另外设置一个停止标志位来控制。*/#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit wela=P2^0;sbit dula=P2^1;uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d 阅读全文
posted @ 2011-11-18 19:56 舒 阅读(409) 评论(0) 推荐(0) 编辑
摘要: 程序一:(二相励磁法)#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit d1=P1^0;sbit d2=P1^1;sbit d3=P1^2;sbit d4=P1^3;#define A {d1=1,d2=0,d3=0,d4=0;}#define B {d1=0,d2=1,d3=0,d4=0;}#define C {d1=0,d2=0,d3=1,d4=0;}#define D {d1=0,d2=0,d3=0,d4=1;}#define E {d1=0,d2=0,d3=0,d4=0;}#d 阅读全文
posted @ 2011-11-18 19:55 舒 阅读(458) 评论(0) 推荐(0) 编辑
摘要: #include<reg52.h>#define uchar unsigned char#define uint unsigned int sbit dula=P2^1; //段选sbit wela=P2^0; //位选uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //位码uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //段码uchar Data[8]; //存数位的段码sbit... 阅读全文
posted @ 2011-11-18 19:54 舒 阅读(639) 评论(0) 推荐(0) 编辑
摘要: 原理为:通过按键(键盘扫描)控制速度增减,从而改变延时长短(定时器控制),从而达到调速的目的,数码管显示。#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit wela=P2^0;sbit dula=P2^1;uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};uchar 阅读全文
posted @ 2011-11-18 19:54 舒 阅读(794) 评论(0) 推荐(0) 编辑
摘要: /*此程序实现的功能为,按键反转,即每按一次键,步进电机在原来的方向上反转一次,要注意将P3^2口接到任意按键上。*/#include<reg52.h>#define uchar unsigned char#define uint unsigned int sbit d1=P1^0; //定义步进电机的四个端口sbit d2=P1^1;sbit d3=P1^2;sbit d4=P1^3;#define A {d1=1,d2=0,d3=0,d4=0;}//使用1-2相励磁法一相与二相交替导通#define B {d1=0,d2=1,d3=0,d4=0;}#define C {d1=0 阅读全文
posted @ 2011-11-18 19:53 舒 阅读(803) 评论(0) 推荐(0) 编辑
摘要: #include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit LED=P1^2;sbit KEY=P3^3;sbit dula=P2^1;sbit wela=P2^0;uchar num;uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x7b,0x71};void delay(uchar z){ uchar x,y; for(x=z;x>0;x--) { fo 阅读全文
posted @ 2011-11-18 19:52 舒 阅读(342) 评论(0) 推荐(0) 编辑