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

📄 u110_bak.c

📁 linux下打印驱动源代码 适用于双步进针打驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
	cstep_const ++;	if (direction == 0 && cstep_const == cmotor_const_param) {		ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_COIL, NCMOTOR);		cstep_const = 0;	} else if (direction == 1 && cstep_const == cmotor_const_param - 1) {		ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_COIL, NCMOTOR);		cstep_const = 0;	}	return;}/******************************************************************* ** Carriage motor work rush ** *******************************************************************/static void prn_cmotor_work_rush(unsigned char direction){	unsigned char port1, port2;	port1 = 90;	port2 = crun_i | motor_steps[cmotor_step % 4];  //must hold motor state	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;	ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_ACC, NCMOTOR);	return;}/******************************************************************* ** Carriage motor hold rush  ** *******************************************************************/static void prn_cmotor_hold_rush(unsigned char direction){	unsigned char port1, port2;	port1 = 70;	port2 =  crun_i | motor_steps[cmotor_step % 4]; //must hold motor state	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;	ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_STOP, NCMOTOR);		return;}/******************************************************************* ** ** *******************************************************************/static volatile unsigned char cstep_coil = 0;static void prn_cmotor_coil(unsigned char direction){	unsigned char test_val = 0;	unsigned char port1 = 12;	unsigned char port2;	int step = (direction) ? 1 : -1;	if (tmpp == 0) {		if (cstep_coil >= prn_line_max_steps) {			__prn_cmotor_data2irq_mask();			if (direction == 0 || cstep_coil > prn_line_max_steps){				ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_DEC,					      NCMOTOR);				cstep_coil = 0;			} else {				cmotor_step += step;				port2 = crun_i | motor_steps[cmotor_step % 4];				REG8(PRN_CMOTOR_PORT1) = port1;				REG8(PRN_CMOTOR_PORT2) = port2;				cstep_coil ++;			}			return;		}		cmotor_step += step;		port2 = crun_i | motor_steps[cmotor_step % 4];		REG8(PRN_CMOTOR_PORT1) = port1;		REG8(PRN_CMOTOR_PORT2) = port2;		cstep_coil ++;		tmpp = 1;	} else 		tmpp = 0;	test_val = prn_buffer[coil_counter];	if ((test_val & old_val)!=0) {		test_val = 0;	}	REG8(PRN_COIL_REG) = ~test_val;			old_val = test_val;	coil_counter++;	return;}/******************************************************************* ** Carriage Motor Accesleration State ** *******************************************************************/static volatile unsigned char cstep_acc = 0;static void prn_cmotor_acc(unsigned char direction){	unsigned char port1;	unsigned char port2;	int step = (direction) ? 1 : -1;        cmotor_step += step;	port1 = cmotor_acc[cstep_acc];	port2 = crun_i | motor_steps[cmotor_step % 4];	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;	cstep_acc ++;		if (cstep_acc == 11) {		if (cmotor_const_param)			ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_CONST, NCMOTOR);		else			ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_COIL, NCMOTOR);		tmpp = 0;		cstep_acc = 0;	}	return;}/******************************************************************* ** Carriage Motor Deceleration State ** *******************************************************************/static volatile unsigned char cstep_dec = 0;static void prn_cmotor_dec(unsigned char direction){	unsigned char port1;	unsigned char port2;	int step = (direction) ? 1 : -1;	cmotor_step += step;	port1 = cmotor_dec[cstep_dec];	port2 = crun_i | motor_steps[cmotor_step % 4];	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;	cstep_dec ++;	if (cstep_dec == 11) {		cstep_dec = 0;		if (direction)			cmotor_direction = 0;		else			cmotor_direction = 1;		ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_HOLDRUSH, NCMOTOR);	} 	return;}/******************************************************************* ** Is the line end? ** *******************************************************************/static void prn_cmotor_stop(unsigned char direction){	unsigned char port1=127;	unsigned char port2;	port2 = hold_i | motor_steps[cmotor_step % 4];	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;	switch (coil_counter / (prn_line_max_steps * 2 - 1)) {	case 1:		ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_STEP, NPMOTOR);		__prn_cmotor_irq_mask();		__prn_pmotor_irq_unmask();			break;	case 2:		ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_ACC, NPMOTOR);		__prn_cmotor_irq_mask();		__prn_pmotor_irq_unmask();		break;	}	return;}/* ** Page motor funcitons ** **/static void prn_pmotor_work_rush(unsigned char direction);static void prn_pmotor_hold_rush(unsigned char direction);/******************************************************************* ** page motor work rush ** *******************************************************************/static void prn_pmotor_work_rush(unsigned char direction){	unsigned char port1, port2;	port1 = 87;	port2 = crun_i | motor_steps[pmotor_step % 4];  //must hold motor state	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_ACC, NPMOTOR);	return;}/******************************************************************* ** page motor hold rush  ** *******************************************************************/static void prn_pmotor_hold_rush(unsigned char direction){	unsigned char port1, port2;	port1 = 87;	port2 = crun_i | motor_steps[pmotor_step % 4]; //must hold motor state	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_STOP, NPMOTOR);	return;}/******************************************************************* ** Page Motor Coil ** *******************************************************************/static volatile unsigned char pmotor_coilcount = 0;static void prn_pmotor_coil(unsigned char direction){	unsigned char port1 = 87;	unsigned char port2;	int step = (direction) ? 1 : -1;	port1 = 20;	port2 = prun_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	pmotor_step += step;	if (pmotor_coilcount >= pmotor_steps) {		ENCODE_STATUS(PRN_PAPERFETCH2, MOTOR_STAT_STOP, NPMOTOR);		pmotor_coilcount = 0;	} else		pmotor_coilcount ++;}/******************************************************************* ** Page Motor Move one step ** *******************************************************************/static void prn_pmotor_step(unsigned char direction){	unsigned char port1 = 127;	unsigned char port2;	int step = (direction) ? 1 : -1;	port2 = prun_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	pmotor_step += step;	ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_STOP, NPMOTOR);	return;}/******************************************************************* ** Page Motor Accesleration State ** *******************************************************************/static volatile unsigned char pstep_acc = 0;static void prn_pmotor_acc(unsigned char direction){	unsigned char port1;	unsigned char port2;	int step = (direction) ? 1 : -1;	port1 = pmotor_acc[pstep_acc];	port2 = prun_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	pstep_acc ++;	switch (PRN_STATUS()) {	case PRN_NEWLINE:		if (pstep_acc >= 16) {			ENCODE_STATUS(PRN_NEWLINE, MOTOR_STAT_STOP, NPMOTOR);			pstep_acc = 0;		} else			pmotor_step += step;		break;	case PRN_PRINTING:		if (pstep_acc >= 15) {			ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_STOP, NPMOTOR);			pstep_acc = 0;		} else			pmotor_step += step;		break;	case PRN_PAPERFETCH0:	case PRN_PAPERFETCH1:	case PRN_PAPERFETCH2:		if (pstep_acc >= 21) {			ENCODE_STATUS(PRN_STATUS(), MOTOR_STAT_CONST, NPMOTOR);			pstep_acc = 0;		}		pmotor_step += step;		break;	case PRN_BLACKMARK:		if (__prn_blackmark()) {			ENCODE_STATUS(PRN_BLACKMARK, MOTOR_STAT_DEC, NPMOTOR);			pstep_acc = 0;		} else {			if (pstep_acc == 21) {				ENCODE_STATUS(PRN_BLACKMARK,					      MOTOR_STAT_CONST,					      NPMOTOR);				pstep_acc = 0;			}		}		pmotor_step += step;		break;	}}/******************************************************************* ** ** *******************************************************************/static volatile unsigned char pstep_dec = 0;static void prn_pmotor_dec(unsigned char direction){	unsigned char port1;	unsigned char port2;	int step = (direction) ? 1 : -1;	port1 = pmotor_dec[pstep_dec];	port2 = prun_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	pstep_dec ++;	if (pstep_dec == 3) {		ENCODE_STATUS(PRN_STATUS(), MOTOR_STAT_STOP, NPMOTOR);		pstep_dec = 0;	} else		pmotor_step += step;}/******************************************************************* ** ** *******************************************************************/static volatile unsigned int pstep_const = 0;static unsigned int bm_timeout;static void prn_pmotor_const(unsigned char direction){	unsigned char port1 = 15;	unsigned char port2;	int step = (direction) ? 1 : -1;	port2 = prun_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	pmotor_step += step;	pstep_const ++;	switch (PRN_STATUS()) {	case PRN_PAPERFETCH0:	case PRN_PAPERFETCH1:		if (pstep_const >= 400) {			ENCODE_STATUS(PRN_STATUS(), MOTOR_STAT_DEC, NPMOTOR);			pstep_const = 0;		}		break;	case PRN_PAPERFETCH2:		if (pstep_const >= pmotor_steps) {			ENCODE_STATUS(PRN_STATUS(), MOTOR_STAT_DEC, NPMOTOR);			pstep_const = 0;		}		break;	case PRN_BLACKMARK:		if (__prn_blackmark() || bm_timeout >= 2000) {			ENCODE_STATUS(PRN_BLACKMARK, MOTOR_STAT_DEC, NPMOTOR);			pstep_const = 0;		} else			bm_timeout ++;		break;	}}/******************************************************************* ** ** *******************************************************************/static void prn_pmotor_stop(unsigned char direction){	unsigned char port1;	unsigned char port2;	port1 = 127;	port2 = hold_i | motor_steps[pmotor_step % 4];	REG8(PRN_PMOTOR_PORT1) = port1;	REG8(PRN_PMOTOR_PORT2) = port2;	switch (PRN_STATUS()) {	case PRN_PRINTING:		if (cmotor_direction == 0) {			if (__prn_paper_end())				ENCODE_STATUS(PRN_PAPERFETCH1, MOTOR_STAT_ACC,					      NPMOTOR);			else {				ENCODE_STATUS(PRN_STANDBY, 0, 0);				__prn_irq_mask();			}			coil_counter = 0;			wake_up(&prn_wait_queue);                } else {			__prn_pmotor_irq_mask();			ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_WORKRUSH, NCMOTOR);			__prn_cmotor_irq_unmask();		}		break;	case PRN_PAPERFETCH1:		ENCODE_STATUS(PRN_RST0, 0, 0);		wake_up(&prn_wait_queue);		__prn_irq_mask();		break;	default:		if ((PRN_STATUS() == PRN_PAPERFETCH2) &&		    (pmotor_direction == 0) &&		    !(__prn_paper_end()))			pmotor_direction = 1;		if (__prn_paper_end())			ENCODE_STATUS(PRN_PAPERFETCH1, MOTOR_STAT_ACC, NPMOTOR);		else {			ENCODE_STATUS(PRN_STANDBY, 0, 0);			wake_up(&prn_wait_queue);			__prn_irq_mask();		}		break;	}}/*******************************************************************

⌨️ 快捷键说明

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