-
Adobe Reader X 10.0.0
-
protel99se
-
//数码管位 高位-----低位
//四个按键控制步进电机:正转,反转,加1,减1,停止
//上电时电机启动,数码管上显示速度最小档1,加减档位均能通过数码管显示出来,电机采用单双八拍方式
//电机转速一共10档,通过按键调节转速
//电机正转时最高位数码管显示0,反转时显示1
#include
#define uchar unsigned char
#define uint unsigned int
#define LED_data P0 //数码管数据口
#define haha P2
sbit key_zz = P1^0;
sbit key_fz = P1^1;
sbit key_add = P3^0;
sbit key_sub = P3^1;
sbit key_ove=p1^7;//按键定义,s1正转,s2反转,s3加1,s4减1 ,停止
sbit wei3 = P2^3;
sbit wei2 = P2^2;
sbit wei1 = P2^1;
sbit wei0 = P2^0;//数码管位选定义
sbit a = P2^7;
sbit a1 = P2^6;
sbit b = P2^5;
sbit b1 = P2^4;//脉冲信号输入端定义
uchar code seg_code[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//共阳数码管驱动信号0---9,不显示
uchar code T_count[10][2]={{0xda,0x1c},{0xde,0xe4},{0xe1,0xec},{0xe5,0xd4},{0xe9,0xbc}, //9.7 ----1ms
{0xed,0xa4},{0xf1,0x8c},{0xf5,0x74},{0xf9,0x5c},{0xfc,0x18}};
uchar code Motor_driver[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90};
uchar num1 = 0;//控制取励磁信号变量
uchar num2 = 8;
uchar k=1;//加减档位控制,1为最小档
bit Run_dir_flag = 0;//初始正转,正反转标志
uchar Display_num[4]={0,10,0,1};//数码管显示缓存,正转,不显示,显示0,显示1档位,高----低
//================================定时器0/1初始化函数================================
void T0_T1_init()
{
TMOD = 0x11;//定时器0/1均工作于方式1,16位计时方式
TH0 = (65536 - 4000)/256;
TL0 = (65536 - 4000)%256;//定时器0,定时4ms用于数码管扫描显示
TH1 = T_count[k-1][0];
TL1 = T_count[k-1][1];//定时器1,定时10ms用于步进电机转速控制
TR0 = 1;
TR1 = 1;
ET0 = 1;
ET1= 1;//开定时器中断
EA = 1;//开总中断
}
//================================ms级延时函数=======================================
void delay1m(uint x)
{
uint i,j;
for(i=0;i
-
//数码管位 高位-----低位
//四个按键控制步进电机:正转,反转,加1,减1,停止
//上电时电机启动,数码管上显示速度最小档1,加减档位均能通过数码管显示出来,电机采用单双八拍方式
//电机转速一共10档,通过按键调节转速
//电机正转时最高位数码管显示0,反转时显示1
#include
#define uchar unsigned char
#define uint unsigned int
#define LED_data P0 //数码管数据口
#define haha P2
sbit key_zz = P1^0;
sbit key_fz = P1^1;
sbit key_add = P3^0;
sbit key_sub = P3^1;
sbit key_ove=p1^7;//按键定义,s1正转,s2反转,s3加1,s4减1 ,停止
sbit wei3 = P2^3;
sbit wei2 = P2^2;
sbit wei1 = P2^1;
sbit wei0 = P2^0;//数码管位选定义
sbit a = P2^7;
sbit a1 = P2^6;
sbit b = P2^5;
sbit b1 = P2^4;//脉冲信号输入端定义
uchar code seg_code[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//共阳数码管驱动信号0---9,不显示
uchar code T_count[10][2]={{0xda,0x1c},{0xde,0xe4},{0xe1,0xec},{0xe5,0xd4},{0xe9,0xbc}, //9.7 ----1ms
{0xed,0xa4},{0xf1,0x8c},{0xf5,0x74},{0xf9,0x5c},{0xfc,0x18}};
uchar code Motor_driver[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90};
uchar num1 = 0;//控制取励磁信号变量
uchar num2 = 8;
uchar k=1;//加减档位控制,1为最小档
bit Run_dir_flag = 0;//初始正转,正反转标志
uchar Display_num[4]={0,10,0,1};//数码管显示缓存,正转,不显示,显示0,显示1档位,高----低
//================================定时器0/1初始化函数================================
void T0_T1_init()
{
TMOD = 0x11;//定时器0/1均工作于方式1,16位计时方式
TH0 = (65536 - 4000)/256;
TL0 = (65536 - 4000)%256;//定时器0,定时4ms用于数码管扫描显示
TH1 = T_count[k-1][0];
TL1 = T_count[k-1][1];//定时器1,定时10ms用于步进电机转速控制
TR0 = 1;
TR1 = 1;
ET0 = 1;
ET1= 1;//开定时器中断
EA = 1;//开总中断
}
//================================ms级延时函数=======================================
void delay1m(uint x)
{
uint i,j;
for(i=0;i
-
希望版主提出好的改进方法,大家一同进步?有讨论有问题才有进步,呵呵!!