📄 main_0.c
字号:
//============================
//绕线机程序
//============================
#ifndef __main_0_c__
#define __main_0_c__
#include "included.h"
void main(void)
{
uchar key_value;
init_port();
TMOD = 0X11;
TH1 = 0X55;
TL1 = 0X00;
TR1 = 0;
ET1 =1;
EA =1;
clr_dis_sram();
int_lcd();
dis_0();
speak();
out_add = 0xff;
while(1)
{
key_value = key();
switch(key_value)
{
case 10:speak();tiaojie();break;
case 11:speak();setup_key();break;
case 12:speak();setup_key(); break;
case 15:speak();run(); break;
}
}
}
//=========================================
void tiaojie(void)
{
uchar temp=20;
uint t=0;
out_add = 0xff;
while(1)
{
temp = key_123();
switch(temp)
{
case 11:
dir_h();
for_m(2);
break;
case 12:
dir_l();
for_m(2);
break;
}
}
}
//=========================================
void run(void)
{
uint i=0;
unsigned int avr_[7];
unsigned int count;
unsigned int h=0;
unsigned int gh=0;
unsigned int speed;
uint temp[3],tem[3];
avr_[0] = fact_date(XIANJING);//线径
temp[2] = avr_[0]/100;
tem[2] = avr_[0]%100;
temp[1] = tem[2]/10;
tem[1] = tem[2]%10;
temp[0] = tem[1];
avr_[0] = temp[2]*2200+temp[1]*220+temp[0]*22;
avr_[1] = fact_date(QUANSHU); //圈数
avr_[2] = fact_date(ZASHU); //匝数===1层需要多少
avr_[3] = fact_date(CHOUTOU_1); //抽头1
avr_[4] = fact_date(CHOUTOU_2); //抽头2
avr_[5] = fact_date(CHOUTOU_3); //抽头3
avr_[6] = fact_date(CHOUTOU_4); //抽头4
speed=fact_sudu();
count=0;
out_add = 0x00;
for(i=0;i<400;i++) ;
TR1 =1;
do{
while(P3_3==0);
count++;
display(count);
gh=count/avr_[2]; //匝数===1层需要多少
if(gh%2)
{
dir_h();
for(h=0;h<=avr_[0];h++)
for_m(speed); //正转
}
else
{
dir_l();
for(h=0;h<=avr_[0];h++)
back_m(speed); //反转
}
if((count== avr_[3])&&(avr_[3]!=0)) //抽头1
{
out_add = 0xff;
start_key();
out_add = 0x00;
}
else if((count== (avr_[4]+avr_[3]))&&(avr_[4]!=0)) //抽头2
{
out_add = 0xff;
start_key();
out_add = 0x00;
}
else if((count== (avr_[5]+avr_[4]+avr_[3]))&&(avr_[5]!=0)) //抽头3
{
out_add = 0xff;
start_key();
out_add = 0x00;
}
else if((count== (avr_[6]+avr_[5]+avr_[4]+avr_[3]))&&(avr_[6]!=0)) //抽头4
{
out_add = 0xff;
start_key();
out_add = 0x00;
}
else if(count >= avr_[1]) //圈数
{
out_add = 0xff;
start_key();
out_add = 0x00;
count=0;
P3_5=0;
delay_1ms(500);
P3_5=1;
}
}while(1);
}
//===============================
void start_key(void)
{
uchar temp;
do{
temp= key();
}while(temp!=15);
}
//============================
void timer_1(void)interrupt 3 using 2
{
TR1 =0;
TH1 = 0X55;
TL1 = 0X55;
P1_0 =0;
_nop_();
_nop_();
if(P3_2==0)
{
out_add = 0xff;
while(stop()!=15);
out_add = 0x00;
}
TR1 =1;
}
//=============================
uchar stop(void)
{
uchar scan_code=0xfe;
uchar key_val=00;
uchar time_0 =0x00;
jxkey_1:
do{ //检测按键是否被按下
while(ks1()==0);
delay_1ms(20);//消抖动
}while(ks1()==0);
scan_code=0xfe;
for(time_0=0;time_0<8;time_0++)
{
P1 = scan_code;
P3 |= 0X07;
_nop_();
_nop_();
_nop_();
if( P3_0 == 0)
{
key_val=time_0; //0-7key
break;
}
if( P3_1 == 0)
{
key_val=time_0+0x08; //8-15key
break;
}
if( P3_2 == 0)
{ //16 key=stop key
key_val=0x10;
break;
}
scan_code = scan_code<<1;
}
if(key_val>0x10)
goto jxkey_1;
else
do{
while(ks0()==1);
delay_1ms(20);//消抖动
//等待按键弹起
}while(ks0()==1);
return (key_val);
}
//=============================
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -