?? test_logic.c
字號:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define step_motor_frequence 65536-625
#define timer_10ms 65536-10000
#define up 1
#define down 0
uchar up_list[5];
uchar down_list[5];
uint counter_5s;
extern uchar up_list_flag;
extern uchar down_list_flag;
bit current_direction;
sbit L297_clock=P1^0;
sbit L297_reset=P1^1;
sbit L297_mode=P1^2;
sbit L297_direction=P1^3;
sbit L297_on=P1^4;
/************************初始化程序******************/
void init_port(void)
{
P0=0x00;
P2=P2&0x07;
}
void init_stepper_motor(void)
{
L297_on=1;
L297_reset=1;
L297_mode=1;
L297_direction=up;
}
void init_timer0(void)
{
TMOD=0x11;
TH0=step_motor_frequence/256;
TL0=step_motor_frequence%256;
ET0=1;
TH1=timer_10ms/256;
TL1=timer_10ms%256;
ET1=0;
// TR0=1;
}
/*****************************主程序************************/
void lift_run(void)
{
uchar i;
if((0==down_list_flag)&&(0==up_list_flag))
{
TR0=0;
}
if((up==current_direction)&&(0!=up_list_flag))
{
L297_direction=up;
while(storey<=up_list[0]);
for(i=0;i<4;i++)
up_list[i]=up_list[i+1];
up_list[4]=0;
TR1=1;
counter_5s=500;
while(counter_5s);
TR1=0;
}
else if((up==current_direction)&&(0==up_list_flag))
{
current_direction=down;
}
if((down==current_direction)&&(0!=down_list_flag))
{
L297_direction=down;
while(storey>=down_list[0]);
for(i=0;i<4;i++)
down_list[i]=down_list[i+1];
down_list[4]=0;
TR1=1;
counter_5s=500;
while(counter_5s);
TR1=0;
}
else if((down==current_direction)&&(0==down_list_flag))
{
current_direction=up;
}
}
void main(void)
{
init_port();
init_exint0();
init_stepper_motor();
while(1);
{
lift_run();
}
}
/*****************************中斷程序及其判斷*************/
void exint0(void) interrupt 0 using 1
{
read_flag=1;
}
void timer0_interrupt(void) interrupt 1 using 2
{
L297_clock=!L297_clock;
TH0=step_motor_frequence/256;
TL0=step_motor_frequence%256;
}
void timer1_interrupt(void) interrupt 3 using 3
{
TH1=timer_10ms/256;
TL1=timer_10ms%256;
counter_5s--;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -