📄 u110.c
字号:
*******************************************************************/static int arca_prn_home_position(void){ int r=0; if (!__prn_home_position()) { //HPS为L电平 prn_cmotor_test_acc(1); r = prn_cmotor_test_const(230, 1, 1); //反向最大走230步到HPS由L变H位置 prn_cmotor_test_dec(1); } //HPS为H prn_cmotor_test_acc(0); //向左加速 prn_cmotor_test_const(29, 0, 2);//向左最大匀速29步到HPS由H变L。 prn_cmotor_test_const(29, 0, 0);//H变L处,再向左走29步。 prn_cmotor_test_dec(0); prn_cmotor_test_acc(1); r = prn_cmotor_test_const(50, 1, 1);//向右匀速到HPS由L变H位置 prn_cmotor_test_dec(1); if (r == 50) { printk ("Error: motor can not reset home position!\n"); return -EIO; } cmotor_const_param = 3; //位置初始化结束 printk("cmotor const parameter = %d\n", cmotor_const_param); return 0;}/* * Two motor's primitives. */ DECLARE_WAIT_QUEUE_HEAD (prn_wait_queue);/******************************************************************* ** ** *******************************************************************/static volatile unsigned char cstep_const = 0; //????cstep_const为字车步数static void prn_cmotor_const(unsigned char direction){ unsigned char port1 = 12; //匀速时间 unsigned char port2; int step = (direction) ? 1 : -1; cmotor_step += step; //cmotor_step绝对步数 port2 = crun_i | motor_steps[cmotor_step % 4]; REG8(PRN_CMOTOR_PORT1) = port1; REG8(PRN_CMOTOR_PORT2) = port2; cstep_const ++;/******************************************************************* **位置初始化完成后cmotor_const_param=3 正向匀速时,当匀速步数cstep_const=3时,则cstep_const=0,置prn_state状态 **反向匀速时,当匀速步数cstep_const=2时,则cstep_const=0,置prn_state状态 *******************************************************************/ if (direction == 0 && cstep_const == cmotor_const_param) { ENCODE_STATUS(PRN_PRINTING, MOTOR_STAT_COIL, NCMOTOR); //结果:prn_status=66H 表示置下一阶段是字车打印的慢速过程 //define ENCODE_STATUS(prns, motors, motor) //prn_state = (prns) | ((motors) << 1) | ((motor) & 0x01); 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; //rush time 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); //结果:prn_status=62H 表示置下一阶段是字车打印的加速过程 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); //结果:prn_status=60H 表示置下一阶段是字车打印的停止 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) //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);//置下步状态 rush完-Acc 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; //为什么port1两个值???? 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) { //?????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: //定位黑标,当遇到黑标从黑变白,则开始减速3步,定位黑标位置。 if (__prn_blackmark()) { //????????!(REG8(PRN_STATUS_REG) & STATUS_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 ++; //黑标时间自增2000/15*0.176=23mm 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -