|
本帖最后由 sdwfmt 于 2018-4-26 13:29 编辑
目前已经有了利用单片机控制步进电机的延时(按秒)、转动角度、等,需要在这个基础上加上 一天三次启动的定时系统。有没有码农知道怎么搞定的?
源程序如下:
#include<reg52.h>
#include<stdio.h>
#include "lcd1602.h"
#include "eeprom.h"
#define N_ADDRESS 3
#define DIR_ADDRESS 7
#define SPEED_ADDRESS 12
#define SET_ANGLE_ADDRESS 5
#define SET_TIME_ADDRESS 12
#define MAX_PAGE 10 // 最大节点数
#define T0_INIT_DATA_10 100
#define T0_INIT_DATA_50ms 50000
#define Two_XiFen_Clk 400
unsigned char T0_NUM;
unsigned char T0_NUM_2;
unsigned char END_FLAG = 0;
unsigned char END_FLAG_2 = 0;
unsigned char S_FLAG = 0;
sbit SW1=P3^0; //四个独立按键定义
sbit SW2=P3^1;
sbit SW5=P3^2;
sbit SW4=P3^3; // 暂调试
sbit SW3=P3^4;
/*
sbit SW1=P1^3; //四个独立按键定义
sbit SW2=P1^4;
sbit SW4=P1^2;
sbit SW5=P1^5;
sbit SW3=P1^6;
*/
sbit MotorEn = P2^1; // 使能
sbit FX = P2^0; // 方向
sbit CLK = P2^2; // 脉冲
unsigned char g_MotorSt = 0; // 启停
unsigned char g_MotorDir = 0; // 正反
unsigned int CLK_OUT_NUM = 0; // 脉冲计数
signed int MotorSpedNum = 0; // 速度档
//float CUR_MotorAngle = 0.0; // 当前角度
unsigned int CUR_MotorSpedQuan = 0; // 当前圈数
//unsigned int SET_MotorQuan = 0; //
//unsigned int SET_MotorPulse = 0;
unsigned int CUR_Miao = 0;
unsigned int T0_INIT_DATA = 10;
unsigned char cMode = 0;
unsigned char s1_num;
unsigned int iSetData;
//signed char RL = 0; // 方向
//signed char iSet[3];
unsigned int SYS_NUM = 0;
unsigned char MotorTab[10] = {63, 42, 27, 18, 12, 8, 5, 3, 2};
//unsigned char MotorTab[10] = {25, 20, 16, 13, 9, 6, 4, 2, 1};
//unsigned int MotorSpedTab[6] = {400, 800, 1600, 3200, 6400, 12800};
//unsigned char MotorTab[10] = {63, 42, 27, 18, 12, 8, 5, 3, 2};
//unsigned int MotorSeparateTab[5] = {1, 2, 8, 16, 64}; // 细分
signed char EEPROM_Tab[8] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned char cur_page;
signed char page_num;
signed char set_page_num[2];
signed char set_jd_bai, set_jd_shi, set_jd_ge;
signed char set_sj_bai, set_sj_shi, set_sj_ge;
/********数据定义***********************************************************/
struct DataNum
{
signed char set_fx; // 方向
signed char set_sd; // 速度
signed int set_jd; // 角度
signed int set_time; // 间隔
};
struct DataNum StepData[7]; // 注意: 因为STC89C52芯片容量有限,这里采用最大7组连贯动作
//--------------
void delayms(xms);
void mDelay(unsigned int DelayTime); //延时函数
void EEPROM_Init();
void SYS_Init();
void T0_Init();
void LCD_Init();
void PageProcess(unsigned char ac_page);
void EEPROM_DATA(unsigned char ac_page);
void EEPROM_READ(unsigned char ac_page);
void KeyScan(void);
void Stop_Key();
void KeyProcess();
void SecondPro();
void SecondPro_2();
// 主程序 main()
void main(void)
{
SYS_Init(); // 参数初始化
EEPROM_Init(); // 读取数据
T0_Init(); // 定时器0 初始化
LCD_Init(); // 显示初始化
while(1)
{
if (!cMode) // 空闲模式下
{
KeyScan(); // 按键
}
KeyProcess(); // 处理进程
}
}
// 参数初始化
void SYS_Init()
{
MotorEn = 0; // 使能
page_num = 0; // 节点数
cur_page = 0; //当前页面数
set_page_num[0] = set_page_num[1] = 0; // 节点2位小数
}
/********定时器初始化***********************************************************/
void T0_Init()
{
TMOD = 0x01;
TH0 = (65535-100)/256; // 0.1ms
TL0 = (65535-100)%256;
EA = 1;
ET0 = 1;
}
// 液晶显示初始化
void LCD_Init()
{
init_1602(); //lcd1602初始化
write_string(1, 1, "Enter Step Num");
write_string(2,3,"Step:");
write_sf(2,9,page_num);
}
/************存储初始化*****************/
void EEPROM_Init()
{
EEPROM_READ(cur_page);
}
/********定时器中断*****************/
void T0_time() interrupt 1
{
TR0 = 0;
// TH0 = (65535-T0_INIT_DATA)/256; // 0.1ms
// TL0 = (65535-T0_INIT_DATA)%256;
/* TH0 = (65535-100)/256; // 0.1ms
TL0 = (65535-100)%256;
T0_NUM++;
*/
// SYS_NUM++;
if (cMode == 6) // 间隔模式
{
TH0 = (65535-50000)/256; // 50ms
TL0 = (65535-50000)%256;
if (StepData[cur_page-1].set_time > 0)
{
T0_NUM_2++;
if (T0_NUM_2 >= 20)
{
T0_NUM_2 = 0;
CUR_Miao++;
if (CUR_Miao >= StepData[cur_page-1].set_time) // 达到目标
{
CUR_Miao = 0;
TR0 = 0; // 关闭定时器
END_FLAG_2 = 1; // 时间目标达到标志
}
}
}
else
{
CUR_Miao = 0;
TR0 = 0; // 关闭定时器
END_FLAG_2 = 1; // 时间目标达到标志
}
}
else if (cMode == 4) // 电机运行模式
{
TH0 = (65535-100)/256; // 0.1ms
TL0 = (65535-100)%256;
T0_NUM++;
if (StepData[cur_page-1].set_jd > 0)
{
// if(T0_NUM >= MotorTab[StepData[cur_page-1].set_sd]) MotorSpedTab
if(T0_NUM >= MotorTab[StepData[cur_page-1].set_sd])
// if(T0_NUM >= MotorTab[9])
{
T0_NUM = 0;
CLK=CLK^0x01; // 输出脉冲
CLK_OUT_NUM++;
if (S_FLAG)
{
if(CLK_OUT_NUM > 30) // 高速时给个加速过程
{
StepData[cur_page-1].set_sd = StepData[cur_page-1].set_sd + 1;
S_FLAG = 0;
}
}
if(CLK_OUT_NUM >= Two_XiFen_Clk) // 一圈 2细分
{
CLK_OUT_NUM = 0;
CUR_MotorSpedQuan++;
if(CUR_MotorSpedQuan >= StepData[cur_page-1].set_jd) // 达到圈数
{
CLK_OUT_NUM = 0; // 脉冲清空
TR0 = 0; // 关闭定时器
END_FLAG = 1; // 目标达到标志
SYS_NUM = 0; // 清空
}
}
else
{
;
}
// if(CLK_OUT_NUM >= SET_MotorPulse) // 达到角度目标
}
}
else
{
CLK_OUT_NUM = 0; // 脉冲清空
TR0 = 0; // 关闭定时器
END_FLAG = 1; // 目标达到标志
SYS_NUM = 0; // 清空
}
}
else
{
;
}
TR0 = 1;
}
/********保持当前页数据*****************/
void EEPROM_DATA(unsigned char ac_page)
{
if (ac_page == 0)
{
set_page_num[0] = page_num / 10;
set_page_num[1] = page_num % 10;
write_eeprom(SECTION_ADDRESS1,set_page_num,2); // 保存总节点数
}
else if (ac_page > 0)
{
EEPROM_Tab[0] = StepData[ac_page-1].set_fx;
EEPROM_Tab[1] = StepData[ac_page-1].set_sd;
EEPROM_Tab[2] = StepData[ac_page-1].set_jd / 100;
EEPROM_Tab[3] = StepData[ac_page-1].set_jd % 100 / 10;
EEPROM_Tab[4] = StepData[ac_page-1].set_jd % 10;
EEPROM_Tab[5] = StepData[ac_page-1].set_time / 100;
EEPROM_Tab[6] = StepData[ac_page-1].set_time % 100 / 10;
EEPROM_Tab[7] = StepData[ac_page-1].set_time % 10;
switch (ac_page-1)
{
case 0:
write_eeprom(SECTION_ADDRESS2,EEPROM_Tab,8);
break;
case 1:
write_eeprom(SECTION_ADDRESS3,EEPROM_Tab,8);
break;
case 2:
write_eeprom(SECTION_ADDRESS4,EEPROM_Tab,8);
break;
case 3:
write_eeprom(SECTION_ADDRESS5,EEPROM_Tab,8);
break;
case 4:
write_eeprom(SECTION_ADDRESS6,EEPROM_Tab,8);
break;
case 5:
write_eeprom(SECTION_ADDRESS7,EEPROM_Tab,8);
break;
case 6:
write_eeprom(SECTION_ADDRESS8,EEPROM_Tab,8);
break;
default:
break;
}
}
else
{
;
}
}
/********读取数据*****************/
void EEPROM_READ(unsigned char ac_page)
{
if (ac_page == 0)
{
read_eeprom(SECTION_ADDRESS1,set_page_num,2); // 保存总节点数
if ((set_page_num[0] > 0) || (set_page_num[0] < 0))
set_page_num[0] = 0;
if ((set_page_num[1] > 9) || (set_page_num[1] < 0))
set_page_num[1] = 0;
page_num = set_page_num[0]*10 + set_page_num[1];
// read_eeprom(SECTION_ADDRESS1,page_num,2); // 保存总节点数
}
else if (ac_page > 0)
{
switch (ac_page-1)
{
case 0:
read_eeprom(SECTION_ADDRESS2,EEPROM_Tab,8);
break;
case 1:
read_eeprom(SECTION_ADDRESS3,EEPROM_Tab,8);
break;
case 2:
read_eeprom(SECTION_ADDRESS4,EEPROM_Tab,8);
break;
case 3:
read_eeprom(SECTION_ADDRESS5,EEPROM_Tab,8);
break;
case 4:
read_eeprom(SECTION_ADDRESS6,EEPROM_Tab,8);
break;
case 5:
read_eeprom(SECTION_ADDRESS7,EEPROM_Tab,8);
break;
case 6:
read_eeprom(SECTION_ADDRESS8,EEPROM_Tab,8);
break;
default:
break;
}
if ((EEPROM_Tab[0] > 1) || (EEPROM_Tab[0] < 0))
EEPROM_Tab[0] = 0;
if ((EEPROM_Tab[1] > 9) || (EEPROM_Tab[1] < 0))
EEPROM_Tab[1] = 0;
if ((EEPROM_Tab[2] > 9) || (EEPROM_Tab[2] < 0))
EEPROM_Tab[2] = 0;
if ((EEPROM_Tab[3] > 9) || (EEPROM_Tab[3] < 0))
EEPROM_Tab[3] = 0;
if ((EEPROM_Tab[4] > 9) || (EEPROM_Tab[4] < 0))
EEPROM_Tab[4] = 0;
if ((EEPROM_Tab[5] > 9) || (EEPROM_Tab[5] < 0))
EEPROM_Tab[5] = 0;
if ((EEPROM_Tab[6] > 9) || (EEPROM_Tab[6] < 0))
EEPROM_Tab[6] = 0;
if ((EEPROM_Tab[7] > 9) || (EEPROM_Tab[7] < 0))
EEPROM_Tab[7] = 0;
StepData[ac_page-1].set_fx = EEPROM_Tab[0];
StepData[ac_page-1].set_sd = EEPROM_Tab[1];
StepData[ac_page-1].set_jd = EEPROM_Tab[2]*100 + EEPROM_Tab[3]*10 + EEPROM_Tab[4];
StepData[ac_page-1].set_time = EEPROM_Tab[5]*100 + EEPROM_Tab[6]*10 + EEPROM_Tab[7];
}
else
{
;
}
}
/********翻页界面***********************************************************/
void PageProcess(unsigned char ac_page)
{
write_string(1,0," ");
write_string(2,0," ");
write_string(1,1,"N:"); // 显示节点
write_sf(1,3, (unsigned int)ac_page);
if(StepData[ac_page-1].set_fx == 0) //显示方向
write_string(1,DIR_ADDRESS,"R");
else
write_string(1,DIR_ADDRESS,"L");
write_string(1,10,"S:"); // 显示速度
write_one_data(1,SPEED_ADDRESS, StepData[ac_page-1].set_sd);
write_string(2,1,"set:"); // 显示圈数
write_sfm(2, SET_ANGLE_ADDRESS, StepData[ac_page-1].set_jd);
write_string(2,10,"t:"); // 显示间隔
write_sfm(2, SET_TIME_ADDRESS, StepData[ac_page-1].set_time);
}
/********按键扫描函数***********************************************************/
void KeyScan()
{
if(SW1 == 0)
{
delayms(10);
if(SW1 == 0) // 功能键
{
while(!SW1); // 等待松开
cMode = 1; // 功能模式
}
}
if(SW2 == 0)
{
delayms(10);
if(SW2 == 0) // 增加
{
while(!SW2); // 等待松开
cMode = 2;
}
}
/* if(SW3 == 0)
{
delayms(10);
if(SW3 == 0) // 减小
{
while(!SW3); // 等待松开
cMode = 3;
}
} */
if(SW4 == 0)
{
delayms(10);
if(SW4 == 0) // 启停
{
while(!SW4); // 等待松开
cMode = 4;
if (StepData[cur_page-1].set_sd >= 9)
{
StepData[cur_page-1].set_sd = StepData[cur_page-1].set_sd - 1;
S_FLAG = 1;
}
g_MotorSt = 1;
MotorEn = 1;
cur_page = 1; // 电机从第1个节点运行
EEPROM_READ(cur_page); // 读取数据
PageProcess(cur_page); // 页面更新
// CUR_MotorAngle = 0;
CUR_MotorSpedQuan = 0;
if(StepData[cur_page-1].set_fx == 0)
{
FX = 0;
}
else
{
FX = 1;
}
TR0 = 1; // 定时器开启
}
}
if(SW5 == 0)
{
delayms(10);
if(SW5 == 0) // 翻页
{
while(!SW5); // 等待松开
cMode = 5;
}
}
}
void Stop_Key()
{
if(SW4 == 0)
{
delayms(10);
if(SW4 == 0) // 启停
{
while(!SW4); // 等待松开
cMode = 0;
g_MotorSt = 0;
MotorEn = 1; // 继续保持扭矩
// CUR_MotorAngle = 0;
CUR_MotorSpedQuan = 0;
TR0 = 0;
}
}
}
/********按键处理函数***********************************************************/
void KeyProcess()
{
switch(cMode)
{
case 0: // 空闲模式
break;
case 1: // 功能模式
{
s1_num++;
cMode = 0; // 功能模式
if(cur_page > 0) // 各自界面中
{
if(s1_num ==1) // 第1次被按下
{
write_com(0x80+DIR_ADDRESS); // 方向
write_com(0x0f); // 光标闪烁
}
if(s1_num ==2)
{
write_com(0x80+SPEED_ADDRESS);
}
if(s1_num ==3)
{
write_com(0x80+0x40+SET_ANGLE_ADDRESS);
}
if(s1_num ==4)
{
write_com(0x80+0x40+SET_ANGLE_ADDRESS+1);
}
if(s1_num ==5)
{
write_com(0x80+0x40+SET_ANGLE_ADDRESS+2);
}
if(s1_num ==6) // 间隔
{
write_com(0x80+0x40+SET_TIME_ADDRESS);
}
if(s1_num ==7)
{
write_com(0x80+0x40+SET_TIME_ADDRESS+1);
}
if(s1_num ==8)
{
write_com(0x80+0x40+SET_TIME_ADDRESS+2);
}
if(s1_num == 9) //第9次退出
{
s1_num = 0; // 记录按键清零
cMode = 0; // 退出模式
write_com(0x0c); // 取消光标闪烁
// SET_MotorPulse = (unsigned int)((StepData[cur_page-1].set_jd/0.9)*8.0); // 脉冲
EEPROM_DATA(cur_page); // 保存数据
}
}
else // 设定总节点界面
{
if(s1_num ==1) // 第1次被按下
{
write_com(0x80+0x40+9); // 节点数目
write_com(0x0f); // 光标闪烁
}
if(s1_num ==2)
{
write_com(0x80+0x40+10);
}
if(s1_num == 3) //第3次退出
{
s1_num = 0; // 记录按键清零
cMode = 0; // 退出模式
write_com(0x0c); // 取消光标闪烁
EEPROM_DATA(cur_page); // 保存数据
}
}
}
break;
case 2: // 增加
{
cMode = 0; // 功能模式
if(cur_page > 0) // 各自界面中
{
set_jd_bai = StepData[cur_page-1].set_jd / 100;
set_jd_shi = StepData[cur_page-1].set_jd % 100 / 10;
set_jd_ge = StepData[cur_page-1].set_jd % 10;
set_sj_bai = StepData[cur_page-1].set_time / 100;
set_sj_shi = StepData[cur_page-1].set_time % 100 / 10;
set_sj_ge = StepData[cur_page-1].set_time % 10;
if(s1_num == 1) // 方向
{
StepData[cur_page-1].set_fx++;
if(StepData[cur_page-1].set_fx > 1)
StepData[cur_page-1].set_fx = 0;
if(StepData[cur_page-1].set_fx == 0)
{
// FX = 0;
write_string(1, DIR_ADDRESS, "R");
}
else
{
// FX = 1;
write_string(1, DIR_ADDRESS, "L");
}
write_com(0x80+DIR_ADDRESS);
}
if(s1_num == 2) // 速度
{
StepData[cur_page-1].set_sd++;
if(StepData[cur_page-1].set_sd >= 10)
{
StepData[cur_page-1].set_sd = 0;
}
write_one_data(1, SPEED_ADDRESS, StepData[cur_page-1].set_sd);
write_com(0x80+SPEED_ADDRESS);
}
if(s1_num == 3) // 角度 百
{
set_jd_bai++;
if(set_jd_bai >= 10)
set_jd_bai = 0;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SET_ANGLE_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SET_ANGLE_ADDRESS);
}
if(s1_num == 4)
{
set_jd_shi++;
if(set_jd_shi >= 10)
set_jd_shi = 0;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SET_ANGLE_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SET_ANGLE_ADDRESS+1);
}
if(s1_num == 5)
{
set_jd_ge++;
if(set_jd_ge >= 10)
set_jd_ge = 0;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SET_ANGLE_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SET_ANGLE_ADDRESS+2);
}
if(s1_num == 6) // 时间间隔 百
{
set_sj_bai++;
if(set_sj_bai >= 10)
set_sj_bai = 0;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS);
}
if(s1_num == 7)
{
set_sj_shi++;
if(set_sj_shi >= 10)
set_sj_shi = 0;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS+1);
}
if(s1_num == 8)
{
set_sj_ge++;
if(set_sj_ge >= 10)
set_sj_ge = 0;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS+2);
}
}
else // 设定总节点界面
{
if(s1_num == 1) // 十
{
set_page_num[0]++;
if(set_page_num[0] >= 1)
set_page_num[0] = 0;
page_num = set_page_num[0]*10 + set_page_num[1];
write_sf(2, 9, page_num);
write_com(0x80+0x40+9);
}
if(s1_num == 2) // 个
{
set_page_num[1]++;
if(set_page_num[1] >= 6)
set_page_num[1] = 0;
page_num = set_page_num[0]*10 + set_page_num[1];
write_sf(2, 9, page_num);
write_com(0x80+0x40+10);
}
}
}
break;
case 3: // 减小
{
cMode = 0; // 功能模式
if(cur_page > 0)
{
set_jd_bai = StepData[cur_page-1].set_jd / 100;
set_jd_shi = StepData[cur_page-1].set_jd % 100 / 10;
set_jd_ge = StepData[cur_page-1].set_jd % 10;
set_sj_bai = StepData[cur_page-1].set_time / 100;
set_sj_shi = StepData[cur_page-1].set_time % 100 / 10;
set_sj_ge = StepData[cur_page-1].set_time % 10;
if(s1_num == 1) // 方向
{
StepData[cur_page-1].set_fx--;
if(StepData[cur_page-1].set_fx < 0)
StepData[cur_page-1].set_fx = 0;
if(StepData[cur_page-1].set_fx == 0)
{
// FX = 0;
write_string(1, DIR_ADDRESS, "R");
}
else
{
// FX = 1;
write_string(1, DIR_ADDRESS, "L");
}
write_com(0x80+DIR_ADDRESS);
}
if(s1_num == 2) // 速度
{
StepData[cur_page-1].set_sd--;
if(StepData[cur_page-1].set_sd < 0)
{
StepData[cur_page-1].set_sd = 0;
}
write_one_data(1, SPEED_ADDRESS, StepData[cur_page-1].set_sd);
write_com(0x80+SPEED_ADDRESS);
}
if(s1_num == 3) // 百
{
set_jd_bai--;
if(set_jd_bai < 0)
set_jd_bai = 9;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SET_ANGLE_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SET_ANGLE_ADDRESS);
}
if(s1_num == 4)
{
set_jd_shi--;
if(set_jd_shi < 0)
set_jd_shi = 9;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SET_ANGLE_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SET_ANGLE_ADDRESS+1);
}
if(s1_num == 5)
{
set_jd_ge--;
if(set_jd_ge < 0)
set_jd_ge = 9;
StepData[cur_page-1].set_jd = set_jd_bai*100 + set_jd_shi*10 + set_jd_ge;
write_sfm(2, SPEED_ADDRESS, StepData[cur_page-1].set_jd);
write_com(0x80+0x40+SPEED_ADDRESS+2);
}
if(s1_num == 6) // 时间间隔
{
set_sj_bai--;
if(set_sj_bai < 0)
set_sj_bai = 9;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS);
}
if(s1_num == 7)
{
set_sj_shi--;
if(set_sj_shi < 0)
set_sj_shi = 9;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS+1);
}
if(s1_num == 8)
{
set_sj_ge--;
if(set_sj_ge < 0)
set_sj_ge = 9;
StepData[cur_page-1].set_time = set_sj_bai*100 + set_sj_shi*10 + set_sj_ge;
write_sfm(2, SET_TIME_ADDRESS, StepData[cur_page-1].set_time);
write_com(0x80+0x40+SET_TIME_ADDRESS+2);
}
}
else
{
if(s1_num == 1) // -
{
set_page_num[0]--;
if(set_page_num[0] < 0)
set_page_num[0] = 0;
page_num = set_page_num[0]*10 + set_page_num[1];
write_sf(2, 9, page_num);
write_com(0x80+0x40+9);
}
if(s1_num == 2) // 个
{
set_page_num[1]--;
if(set_page_num[1] < 0)
set_page_num[1] = 0;
page_num = set_page_num[0]*10 + set_page_num[1];
write_sf(2, 9, page_num);
write_com(0x80+0x40+10);
}
}
}
break;
case 4: // 运行
{
if (SYS_NUM >= 100) // 10ms
{
SYS_NUM = 0;
// CUR_MotorAngle = CLK_OUT_NUM *0.9/8.0; // 计算当前角度
}
SecondPro(); //
// Stop_Key();
}
break;
case 5: // 翻页
{
cMode = 0; // 功能模式
cur_page++; //翻页增加
if((cur_page > page_num) || (cur_page > MAX_PAGE))
cur_page = 1;
init_1602();
EEPROM_READ(cur_page); // 读取数据
PageProcess(cur_page); // 显示节点数
}
break;
case 6: //时间
{
// cMode = 0; // 功能模式
SecondPro_2();
}
break;
default:
break;
}
}
void SecondPro()
{
if (END_FLAG) // 角度目标达到
{
END_FLAG = 0; // 清
g_MotorSt = 0; // 电机关闭关闭标志
MotorEn = 1;
// CUR_MotorAngle = 0;
CUR_MotorSpedQuan = 0;
cMode = 6; // 进入时间模式
// T0_INIT_DATA = 50000; // 定时器初始值
T0_INIT_DATA = T0_INIT_DATA_50ms; // 定时器初始值
TR0 = 1; //启动定时器
}
else
{
g_MotorSt = 1;
}
}
void SecondPro_2()
{
if (END_FLAG_2) // 时间目标达到
{
END_FLAG_2 = 0; // 清
if (cur_page >= page_num) // 达到总节点数
{
cur_page = 0;
TR0 = 0; //关闭定时器
write_string(1,0," ");
write_string(2,0," ");
LCD_Init(); // 页面更新
cMode = 0; // 待机模式
g_MotorSt = 0; // 电机
MotorEn = 1;
// CUR_MotorAngle = 0;
CUR_MotorSpedQuan = 0;
// T0_INIT_DATA = 10; // 定时器赋值
T0_INIT_DATA = T0_INIT_DATA_10; // 定时器赋值
}
else
{
cur_page = cur_page + 1; // 进入下一个节点
EEPROM_READ(cur_page); // 读取数据
PageProcess(cur_page); // 页面更新
cMode = 4; // 电机运行模式
if(StepData[cur_page-1].set_fx == 0)
{
FX = 0;
}
else
{
FX = 1;
}
g_MotorSt = 1; // 电机
MotorEn = 1;
// CUR_MotorAngle = 0;
CUR_MotorSpedQuan = 0;
// 下一个动作的角度冒充计算
// SET_MotorPulse = (unsigned int)((StepData[cur_page-1].set_jd/0.9)*8.0); // 脉冲
// T0_INIT_DATA = 10; // 定时器赋值
T0_INIT_DATA = T0_INIT_DATA_10; // 定时器赋值
TR0 = 1; // 启动定时器
}
}
}
/********延时函数***********************************************************/
void delayms(xms)
{
unsigned int x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--)
;
}
|
|