⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weld_all.c

📁 电焊机点焊程序
💻 C
📖 第 1 页 / 共 4 页
字号:
#include<AT89X52.H>
#include<string.h>
#include<intrins.h>
/////  for ZLG7289
sbit CS=P2^6;
sbit CLK=P2^5;
sbit DIO=P2^4;
sbit KEY=P3^3;
//// for 93C46
sbit CS1=P2^3;
sbit SK=P2^2;
sbit DI=P2^1;
sbit DD=P2^0;
//// for Start-A/B
sbit start_a = P1^2;
sbit a_state = P0^0;
sbit start_b = P1^3;
sbit b_state = P0^1;
//// 为去抖动而设
sbit T2_EX = P1^1;
//// for weld and adiust
sbit weld_adjust = P1^4;
//// 可控硅控制脚
sbit con = P2^7;
//// for the licence
sbit licence = P0^3;
//// for feedback check
sbit feedback_check = P0^4;
//// for the two relays:relay_A---- Start-A   relay_B----Start_B
sbit relay_A = P3^7;  
sbit relay_B = P3^6;
//// stand for whether the welding is started
sbit start = P1^0;
//// stand for whether it is the first time of turning on the SCR
//// first_time=0-------weld_current is smaller than 100 or the first turning on is already done
//// first_time=1-------weld_current is bigger than 100 
sbit first_time = P0^2;
//定义一个可位寻址的字节
bdata unsigned char BCC;
sbit B0=BCC^0;	sbit B1=BCC^1;	sbit B2=BCC^2;	sbit B3=BCC^3;
sbit B4=BCC^4;	sbit B5=BCC^5;	sbit B6=BCC^6;	sbit B7=BCC^7;
//定义一个可委寻址字节
bdata unsigned char DCC;
sbit D0=DCC^0;	sbit D1=DCC^1;	sbit D2=DCC^2;	sbit D3=DCC^3;
sbit D4=DCC^4;	sbit D5=DCC^5;	sbit D6=DCC^6;	sbit D7=DCC^7;
////  criterion:0--A ,  12--B 
unsigned  char criterion = 0;
////  parameter is for 12 weld parameters
//   0--prepare time  1--press time   2--weld-1 time   3--weld-1 current   4--cool-1 time  5--weld-2 time
//   6--weld-2 current   7--cool-2 time   8--weld-3 time   9--weld-3 current  10--hold time   11--stop time
unsigned char parameter = 6;
//// for storiing 12 weld parameters in 93C46
//// 0--11 are for A criterion group    12--23 are for B criterion
unsigned char parameter_value[36];  
//// story the current mode in 93C46
unsigned char mode = 2;
////  for storying the value of very read from the 93C46
unsigned char rom_value = 0;
//// for the current weld state
unsigned char current_n = 0;
//// for counting in welding
unsigned int counter = 0;
//// stand for weld current
unsigned char weld_current = 0;
//// for timer
unsigned char high_byte_0 = 0,low_byte_0 = 0,high_byte_1 = 0,low_byte_1 = 0;
unsigned int timer = 0;
//// safe stands for whether the feedback signal is OK 
unsigned char safe = 1;
unsigned char error = 0; 
//// usefull at sometimes
unsigned char temp = 0;
//// for password
unsigned char password_1 = 72;
unsigned char password_2 = 89;

//// function delaying about 9+6(t+1)us  
delay(unsigned long t)  
{    
     while(t--){}
}
//// read the byte at addr in the EEPROM 93C46
read_eerom(unsigned char addr)
{
   BCC=addr; CS1=1; 
////   address is firstly been sent. 
   DI=1; SK=0; SK=1;
   DI=1; SK=0; SK=1;
   DI=0; SK=0; SK=1;
   DI=B6; SK=0; SK=1;
   DI=B5; SK=0; SK=1;
   DI=B4; SK=0; SK=1;
   DI=B3; SK=0; SK=1;
   DI=B2; SK=0; SK=1;
   DI=B1; SK=0; SK=1;
   DI=B0; SK=0; SK=1;
//// data is then at the DD and taken by 70--B0
   SK=0; SK=1; B7=DD;
   SK=0; SK=1; B6=DD; 
   SK=0; SK=1; B5=DD;
   SK=0; SK=1; B4=DD; 
   SK=0; SK=1; B3=DD;
   SK=0; SK=1; B2=DD;
   SK=0; SK=1; B1=DD;
   SK=0; SK=1; B0=DD;   
   CS1=0;
//// story the byte in RAM in AT89S52
   parameter_value[parameter+criterion] = BCC;
}
//// eeprom to ram
eeprom_one_byte_ram(unsigned char addr)
{
   BCC=addr; CS1=1; 
////   address is firstly been sent. 
   DI=1; SK=0; SK=1;
   DI=1; SK=0; SK=1;
   DI=0; SK=0; SK=1;
   DI=B6; SK=0; SK=1;
   DI=B5; SK=0; SK=1;
   DI=B4; SK=0; SK=1;
   DI=B3; SK=0; SK=1;
   DI=B2; SK=0; SK=1;
   DI=B1; SK=0; SK=1;
   DI=B0; SK=0; SK=1;
//// data is then at the DD and taken by 70--B0
   SK=0; SK=1; B7=DD;
   SK=0; SK=1; B6=DD; 
   SK=0; SK=1; B5=DD;
   SK=0; SK=1; B4=DD; 
   SK=0; SK=1; B3=DD;
   SK=0; SK=1; B2=DD;
   SK=0; SK=1; B1=DD;
   SK=0; SK=1; B0=DD;   
   CS1=0;   
   parameter_value[addr] = BCC;
}
//// eeprom to ram
eeprom_36_byte_ram(void)
{  unsigned char i; 
   for(i=0;i<36;i++)
   {
      eeprom_one_byte_ram(i);
   }
}
//// read the mode(at the address of 36 in the EEPROM) which was the last mode 
read_mode(void)
{
   BCC=36; CS1=1; 
////   address  firstly
   DI=1; SK=0; SK=1;
   DI=1; SK=0; SK=1;
   DI=0; SK=0; SK=1;
   DI=B6; SK=0; SK=1;
   DI=B5; SK=0; SK=1;
   DI=B4; SK=0; SK=1;
   DI=B3; SK=0; SK=1;
   DI=B2; SK=0; SK=1;
   DI=B1; SK=0; SK=1;
   DI=B0; SK=0; SK=1;
//// data secondly
   SK=0; SK=1; B7=DD;
   SK=0; SK=1; B6=DD; 
   SK=0; SK=1; B5=DD;
   SK=0; SK=1; B4=DD; 
   SK=0; SK=1; B3=DD;
   SK=0; SK=1; B2=DD;
   SK=0; SK=1; B1=DD;
   SK=0; SK=1; B0=DD;   
   CS1=0;
//// story the mode in RAM in AT89S51
   mode = BCC;
}
//// enable\diable the 93C46    enable:1--can be writen  0--cann't be writen
write_enable(unsigned char enable)
{
//// enable insruction
   if(enable)
   {
      CS1 = 1;
      DI = 1; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      DI = 1; SK = 0; SK = 1;
      DI = 1; SK = 0; SK = 1;
      SK = 0; SK = 1;
	  SK = 0; SK = 1;
	  SK = 0; SK = 1;
      SK = 0; SK = 1;
	  SK = 0; SK = 1;
      CS1 = 0;
   }
//// disable instruction 
   else
   {
      CS1 = 1;
      DI = 1; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      DI = 0; SK = 0; SK = 1;
      SK = 0; SK = 1;
	  SK = 0; SK = 1;
	  SK = 0; SK = 1;
      SK = 0; SK = 1;
	  SK = 0; SK = 1;
      CS1 = 0;      
   }
}
//// story _data at address in 93C46
write_eerom(unsigned char address,unsigned char _data)
{ 
////  Address firstly
   BCC = address; 
   CS1 = 1;       
   DI = 1; SK = 0; SK = 1;
   DI = 0; SK = 0; SK = 1;
   DI = 1; SK = 0; SK = 1;
   DI = B6; SK = 0; SK = 1;
   DI = B5; SK = 0; SK = 1;
   DI = B4; SK = 0; SK = 1;
   DI = B3; SK = 0; SK = 1;
   DI = B2; SK = 0; SK = 1;
   DI = B1; SK = 0; SK = 1;
   DI = B0; SK = 0; SK = 1;
////  Data secondly
   BCC = _data;   
   DI = B7; SK = 0; SK = 1;
   DI = B6; SK = 0; SK = 1;
   DI = B5; SK = 0; SK = 1;
   DI = B4; SK = 0; SK = 1;
   DI = B3; SK = 0; SK = 1;
   DI = B2; SK = 0; SK = 1;
   DI = B1; SK = 0; SK = 1;
   DI = B0; SK = 0; SK = 1;
   CS1 = 0;
}
////  send a byte to zlg7289
comd_out(char a)   
{
    BCC=a;CS=0;CLK=0;delay(7);
	DIO=B7;CLK=1;delay(0); CLK=0;delay(0); 
	DIO=B6;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B5;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B4;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B3;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B2;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B1;CLK=1;delay(0); CLK=0;delay(0);
    DIO=B0;CLK=1;delay(0); CLK=0;delay(0);
    CS=1;   
}
//// display commond of ZLG7289:a is the display instruction,b is the data to be displayed    
display(char a,char b)   
{
    BCC=a;CS=0;CLK=0;delay(7);
	DIO=B7;CLK=1;delay(0); CLK=0;delay(0); 
	DIO=B6;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B5;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B4;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B3;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B2;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B1;CLK=1;delay(0); CLK=0;delay(0);
    DIO=B0;CLK=1;delay(0); CLK=0;delay(0);
    BCC=b;CS=0;CLK=0;delay(7);
	DIO=B7;CLK=1;delay(0); CLK=0;delay(0); 
	DIO=B6;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B5;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B4;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B3;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B2;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B1;CLK=1;delay(0); CLK=0;delay(0);
    DIO=B0;CLK=1;delay(0); CLK=0;delay(0);
    CS=1;   
}
//// get the value standing for which key is pressed down 
unsigned char value_key(unsigned char a)   
{
    BCC=a;CS=0;CLK=0;delay(7);
	DIO=B7;CLK=1;delay(0); CLK=0;delay(0); 
	DIO=B6;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B5;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B4;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B3;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B2;CLK=1;delay(0); CLK=0;delay(0);
	DIO=B1;CLK=1;delay(0); CLK=0;delay(0);
    DIO=B0;CLK=1;delay(0); CLK=0;delay(0);
    CS=0;CLK=0;delay(7);
    CLK=1;delay(0);B7=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B6=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B5=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B4=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B3=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B2=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B1=DIO;CLK=0;delay(0); 
	CLK=1;delay(0);B0=DIO;CLK=0;delay(0);
    CS=1;  
    return(BCC);
}
//// diaplay a weld parameter's value by the three BCD LED
display_parameter_value(unsigned char value)
{
   unsigned char d2,d1,d0;
   d2 = value/100; d1 = (value - 100*d2)/10; d0 = value%10;  
   display(0xcb,d2); 
   display(0xcc,d1);
   display(0xcd,d0);
}
//// begin displaying\stop displaying a percific segment
//// segment_n is the adrress      
//// on_off:1--begin displaying   0--stop displaying
segment(unsigned char segment_n,unsigned char on_off)
{
   if(on_off) 
        display(0xe0,segment_n);
   else 
        display(0xc0,segment_n);
}
//// switch the parameter to be set
//// The switch is a loop.When switch to a new parameter,the two neighbour parameter's LED is turned off
parameter_switch(void)
{
    switch(parameter)
	{
          case 0: segment(11,0); segment(17,0); segment(12,1); break;
		  case 1: segment(12,0); segment(10,0); segment(11,1); break;
		  case 2: segment(11,0); segment(9,0); segment(10,1); break;
		  case 3: segment(10,0); segment(8,0); segment(9,1); break;
		  case 4: segment(9,0); segment(15,0); segment(8,1); break;
		  case 5: segment(8,0); segment(22,0); segment(15,1); break;
		  case 6: segment(15,0); segment(21,0); segment(22,1); break;
		  case 7: segment(22,0); segment(20,0); segment(21,1); break;
		  case 8: segment(21,0); segment(19,0); segment(20,1); break;
		  case 9: segment(20,0); segment(18,0); segment(19,1); break;
		  case 10: segment(19,0); segment(17,0); segment(18,1); break;
		  case 11: segment(18,0); segment(12,0); segment(17,1); break;
	}
}
//// turn off all of the 12 parameter LEDs
parameter_all_off(void)
{
      segment(12,0); 
	  segment(11,0); 
	  segment(10,0); 
	  segment(9,0); 
      segment(8,0); 
      segment(15,0); 
      segment(22,0); 
      segment(21,0); 
      segment(20,0); 
      segment(19,0); 
      segment(18,0); 
      segment(17,0); 	
}
//// switch the criterion between A and B  
criterion_switch(void)
{ 
   if(criterion==0)
       {   segment(0,0); segment(1,1);  }
   else if(criterion==12)
       {   segment(0,1); segment(1,0);  }
   else    
	   {  segment(0,0); segment(1,0);  }
          
}
//// switch the mode between prorgam、reduced and normal 
mode_switch(void)
{
   switch(mode)
   {
          case 0: segment(7,1);segment(14,0);segment(13,0);break;
		  case 1: segment(7,0);segment(14,1);segment(13,0);break;
		  case 2: segment(7,0);segment(14,0);segment(13,1);break;
//// if where is something wrong,such as mode's value is bigger than 2,then mode is set to 0
		  default: mode = 0;
   }
}
//// display the current weld state:pressing->welding->cooling->holding->stoped 
state_switch(unsigned char weld_state)
{
    switch(weld_state)
	{
         case 0: segment(2,0); break;  //// no led is turned on
		 case 1: segment(6,1); segment(2,0); break;  //// press
		 case 2: segment(5,1); segment(6,0); segment(4,0); break;  //// weld

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -