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

📄 printfunction.c

📁 9针的打印机驱动程序,单片机采用ST uPSD3254A
💻 C
📖 第 1 页 / 共 3 页
字号:
								 break;}
				case 2:{	 
								 CarriagePhase1;
								 break;}
				case 3:{	 
								 CarriagePhase0;
								 break;}
		}
		CarriageION3;
		if(PhaseIn==3)
		phase=0;
		else
		phase=PhaseIn+1;
		CRLP=phase;
		return	phase;
}
/*******************************************************************************
*	Function Name	 :CarriageSpeedUpRightToLeft
*	Description		 :字车电机左加速
*	Input			 		 :u8	PhaseIn
*	Return			   :none
*******************************************************************************/
void	CarriageSpeedUpRightToLeft(u8 PhaseIn)
{
		u8	i,phase;
		for(i=0;i<12;i++)
		{
				phase=(i+PhaseIn)%4;
				CarriageRightToLeft(phase);
				delay(ACCTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :CarriageSpeedDownRightToLeft
*	Description		 :字车电机左减速
*	Input			 		 :u8	PhaseIn
*	Return			   :none
*******************************************************************************/
void	CarriageSpeedDownRightToLeft(u8 PhaseIn)
{
		u8	i,phase;
		for(i=0;i<12;i++)
		{
				phase=(i+PhaseIn)%4;
				CarriageRightToLeft(phase);
				delay(DECTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :CarriageConstantSpeedRightToLeft
*	Description		 :字车电机左常速
*	Input			 		 :u8	PhaseIn,u8	stepcount
*	Return			   :none
*******************************************************************************/
void	CarriageConstantSpeedRightToLeft(u8 PhaseIn,u8	stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				CarriageRightToLeft(phase);
				delay(105);
		}		
}
/*******************************************************************************
*	Function Name	 :CarriageSlowSpeedRightToLeft
*	Description		 :字车电机左慢速
*	Input			 		 :u8	PhaseIn,u8	stepcount
*	Return			   :none
*******************************************************************************/
void	CarriageSlowSpeedRightToLeft(u8 PhaseIn,u8	stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				CarriageRightToLeft(phase);
				delay(500);
		}		
}
/*******************************************************************************
*	Function Name	 :CarriageHold
*	Description		 :字车电机保持
*	Input					 :PhaseCycle 								 
*	Return				 :none
*******************************************************************************/
void  CarriageHold(u16	PhaseCycle) 
{
		//CarriageIOFF;
        CarriageION1;
		delay(PhaseCycle);
}	

/*******************************************************************************
*	Function Name	 :PaperForward
*	Description		 :走纸电机进纸
*	Input					 :u8	PhaseIn
*	Return				 :CurrentPhase---0~3
*******************************************************************************/
u8	PaperForward(u8	PhaseIn)
{
		static	u8	phase;
		switch(PhaseIn)
		{
				case 0:{	 PaperPhase3;
									 break;}
				case 1:{	 PaperPhase2;
									 break;}
				case 2:{	 PaperPhase1;
									 break;}
				case 3:{	 PaperPhase0;
									 break;}
		}
		PaperION3;
		if(PhaseIn==3)
		phase=0;
		else
		phase=PhaseIn+1;
		PFP=phase;
		return	phase;
}
/*******************************************************************************
*	Function Name	 :PhaseDirectionSwitch
*	Description		 :电机相位换向切换
*	Input					 :u8	PhaseIn
*	Return				 :phase
*******************************************************************************/
u8	PhaseDirectionSwitch(u8	PhaseIn)
{
		u8	phase;
		switch(PhaseIn)//2301
		{
				case 0:{	 phase=1;
									 break;}
				case 1:{	 phase=0;
									 break;}
				case 2:{	 phase=3;
									 break;}
				case 3:{	 phase=2;
									 break;}
		}
		return	phase;
}

/*******************************************************************************
*	Function Name	 :PaperSpeedUpForward
*	Description		 :走纸电机加速进纸
*	Input					 :u8	PhaseIn
*	Return				 :none
*******************************************************************************/
void	PaperSpeedUpForward(u8	PhaseIn)
{
		u8	i,phase;
		for(i=0;i<20;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperForward(phase);
				delay(PACCTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperSpeedDownForward
*	Description		 :走纸电机减速进纸
*	Input					 :u8	PhaseIn
*	Return				 :none
*******************************************************************************/
void	PaperSpeedDownForward(u8	PhaseIn)
{
		u8	i,phase;
		for(i=0;i<4;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperForward(phase);
				delay(PDECTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperConstantSpeedForward
*	Description		 :走纸电机常速进纸
*	Input					 :u8	PhaseIn,u8	stepcount
*	Return				 :none
*******************************************************************************/
void	PaperConstantSpeedForward(u8	PhaseIn,u8	stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperForward(phase);
				delay(125);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperSlowSpeedForward
*	Description		 :走纸电机慢速进纸
*	Input					 :u8	PhaseIn,u8	stepcount
*	Return				 :none
*******************************************************************************/
void	PaperSlowSpeedForward(u8	PhaseIn,u8	stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperForward(phase);
				delay(700);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperBack
*	Description		 :走纸电机退纸
*	Input					 :u8	PhaseIn,								 
*	Return				 :CurrentPhase---0~3
*******************************************************************************/
u8	PaperBack(u8 PhaseIn)
{
		u8	phase;
		switch(PhaseIn)
		{
				case 0:{	 PaperPhase0;
									 break;}
				case 1:{	 PaperPhase1;
									 break;}
				case 2:{	 PaperPhase2;
									 break;}
				case 3:{	 PaperPhase3;
									 break;}
		}
		PaperION3;
		if(PhaseIn==3)
		phase=0;
		else
		phase=PhaseIn+1;
		PBP=phase;
		return	phase;
}
/*******************************************************************************
*	Function Name	 :PaperSpeedUpBack
*	Description		 :走纸电机加速退纸
*	Input					 :u8	PhaseIn,								 
*	Return				 :none
*******************************************************************************/
void	PaperSpeedUpBack(u8 PhaseIn)
{
		u8	i,phase;
		for(i=0;i<20;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperBack(phase);
				delay(PACCTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperSpeedDownBack
*	Description		 :走纸电机减速退纸
*	Input					 :u8	PhaseIn,								 
*	Return				 :none
*******************************************************************************/
void	PaperSpeedDownBack(u8 PhaseIn)
{
		u8	i,phase;
		for(i=0;i<4;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperBack(phase);
				delay(PDECTime[i]);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperConstantSpeedBack
*	Description		 :走纸电机常速退纸
*	Input					 :u8	PhaseIn,u8	stepcount								 
*	Return				 :none
*******************************************************************************/
void	PaperConstantSpeedBack(u8	PhaseIn,u8 stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperBack(phase);
				delay(125);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperSlowSpeedBack
*	Description		 :走纸电机慢速退纸
*	Input					 :u8	PhaseIn,u8	stepcount								 
*	Return				 :none
*******************************************************************************/
void	PaperSlowSpeedBack(u8	PhaseIn,u8 stepcount)
{
		u8	i,phase;
		for(i=0;i<stepcount;i++)
		{
				phase=(i+PhaseIn)%4;
				PaperBack(phase);
				delay(700);
		}		
}
/*******************************************************************************
*	Function Name	 :PaperHold
*	Description		 :走纸电机保持
*	Input					 :PhaseCycle 								 
*	Return				 :none
*******************************************************************************/
void	PaperHold(u16 PhaseCycle)
{
		PaperION1;
		delay(PhaseCycle);
}
/*******************************************************************************
*	Function Name	 :PrintDrive
*	Description		 :打印
*	Input			 :u8 bufferdata,u8 PrintCycle 								 
*	Return			 :none
*******************************************************************************/
void   PrintDrive(u8 bufferdata,u8 PrintCycle)
{
     PSD_REG.DATAOUT_B=~bufferdata;
     delay(PrintCycle);
     PSD_REG.DATAOUT_B=0xFF;
}
/*******************************************************************************
*	Function Name	 :PrinterPowerUpInitial
*	Description		 :打印机上电初始化
*	Input			 :none 								 
*	Return			 :none
*******************************************************************************/
void  PrinterPowerUpInitial(void)
{   
    u8  data	i,data	 temp=0,data	stepcount;
		//CRLP=1;//赋初始相位
    if(PositionSensorValue()==FALSE)//HP信号:0
    {
    		stepcount=0;
  			while(PositionSensorValue()==FALSE)
  			{
  			    if(stepcount<12)
  			    {
  			    		for(i=0;i<12;i++)
  			    		{
  			    			if(i==0)
  			    			CarriageRightToLeft(PhaseDirectionSwitch(CLRP));//字车左加速12步
  			    			else
  			    			CarriageRightToLeft(CRLP);//字车左加速12步
  			    			delay(ACCTime[i]);
  			    			stepcount++;
  			    			if(PositionSensorValue()==TRUE)
  			    			temp=stepcount;
  			    		}
  			    }
						else
						{
								CarriageConstantSpeedRightToLeft(CRLP,1);//字车左常速1步
								stepcount++;
								temp=10;
						}	
						if(stepcount>250)
  			    {   
  			    		CarriageIOFF;
  			        break;
  			    }
  			}
  			if(PositionSensorValue()==TRUE)
  			{   
  			  	if(temp<10)
  			  	{
  			  			i=temp;
  			  	}	
  			  	else
  			  	{
  			  			i=10;
  			  	}
  			  	CarriageConstantSpeedRightToLeft(CRLP,i);//字车左常速	
  			  	CarriageSpeedDownRightToLeft(CRLP);//字车左减速12步
  			}
  	}
  	//HP信号为1
		CarriageSpeedUpLeftToRight(PhaseDirectionSwitch(CRLP));//字车向右加速12步
		CarriageConstantSpeedLeftToRight(CLRP,28);//字车向右常速28步
		CarriageSpeedDownLeftToRight(CLRP);//字车向右减速12步
		if(PositionSensorValue()==TRUE)
		{
				CarriageIOFF;
			//	break;
		}
		else
		{
				CarriageSpeedUpRightToLeft(PhaseDirectionSwitch(CLRP));//字车向左加速12步
				stepcount=0;
				while(PositionSensorValue()==FALSE)	
				{
						CarriageConstantSpeedRightToLeft(CRLP,1);
						stepcount++;
						if(stepcount>51)
						{
							CarriageIOFF;
							break;
						}
				}
				if(PositionSensorValue()==TRUE)
				{
						CarriageConstantSpeedRightToLeft(CRLP,10);//字车左恒速10步
						CarriageSpeedDownRightToLeft(CRLP);//字车左减速12步
						
				}
				CarriageIOFF;		 
		}			
}

/*******************************************************************************
*	Function Name	 :PositionSensorValue
*	Description		 :位置传感器值 
*	Input			 		 :none									 
*	Return				 :value 
*******************************************************************************/
u8	PositionSensorValue(void)
{
		u8	value;
		if(PositionSensor==TRUE)
		{
				delay(15);
				if(PositionSensor==TRUE)
				{
						value=1;
				}
				else
				{
						value=0;
				}
		}
		else
		{
				delay(15);
				if(PositionSensor==FALSE)
				{
						value=0;
				}
				else
				{
						value=1;
				}
		}
		return value;	
}
/*******************************************************************************
*	Function Name	 :delay10us
*	Description		 :定时10us 
*	Input			 :none									 
*	Return				 :none 
*******************************************************************************/
/*
void	delay10us(void )
{	 
	 
	 while(TF0==0);
     TF0=0;	
}
*/
/*******************************************************************************
*	Function Name	 :delay
*	Description		 :延时程序 
*	Input					 :u16	count										
*	Return				 :none 
*******************************************************************************/
void	delay(u16	count)
{
     u16 i;
     TL0=TH0;
     TR0=1;
	 for(i=1;i<count;i++)
	 {
	 	while(TF0==0);
     	TF0=0;
	 }
	 TR0=0;
}
/*******************************************************************************
*	Function Name	 :delayt
*	Description		 :延时程序 
*	Input					 :u8	count										
*	Return				 :none 
*******************************************************************************/
void	delayt(u8	count)
{
		u8 i;
    TL0=TH0;
    TR0=1;
	 	for(i=1;i<count;i++)
	 	{
	 		while(TF0==0);
   	  TF0=0;
	 	}
	 //	TR0=0;
}

⌨️ 快捷键说明

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