Reprogram the cashier and print Keanu Reeves on it

Hello, Habr!



Once I had a “job” - it was necessary to manage the cash register Shtrikh-FR-K. Since my career began with the repair of KKT, I decided to take up this work.



image



This is how the box office itself and the trial image of my colleague look like:



image



In addition to controlling the engines and the thermal head in the device, I had to write a small python script using the OpenCV library. So let's go.



It all started with the study of rem. dock. to this cash desk and the subsequent connection of the logic analyzer to the thermal head pins. I sent the letter “C” to print through a bar test driver. And here is what I got:



image



According to DATA, the value of the points (432 points per line), SCK - clock signal, STB0, STB1, STB2 - strobes for heating the thermal head, LATCH - data latch. I drove a line into the shift register, burned it, went on.



The next step was finalizing the board to speed up the development process.



image



Now let's move on to the code.



void go(int n, int shag) { switch (shag) { case 0: PORTA=0b10001000; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 1: PORTA=0b10101010; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 2: PORTA=0b00100010; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 3: PORTA=0b01100110; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 4: PORTA=0b01000100; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 5: PORTA=0b01010101; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 6: PORTA=0b00010001; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; case 7: PORTA=0b10011001; PORTD|=(1<<2); dela(n); PORTD&=0b11111011; PORTA=0; PORTD|=(1<<2); PORTD&=0b11111011; break; } }
      
      





There are two stepper motor control circuits for this box office. 4-step and 8-step. I chose 8 as the engines worked better.



 #define DATA 2 #define SCK 1 #define LATCH 3 #define STB0 2 #define STB1 3 #define STB2 4 #define DATA_IN PORTB #define STB_IN PORTE int sck() { _delay_us(3); DATA_IN|= (1<<SCK); DATA_IN&= 0b11111101; } int x; int bit; void bait(int bait1) { x=0; while(x<8) { bit|= (1<<x); bit =bait1&bit; if (bit>0) { DATA_IN|=(1<<DATA); } else {DATA_IN&=0b11111011;} sck(); x++; } } void latch() { DATA_IN&=0b11110111; DATA_IN|=(1<<LATCH); }
      
      





Code for sending data to the thermal head. The thermal head acts as a shift register. How it works, I wrote above.



 void print_all_pixel() { while(n<55) { print_stroka(str[n]); _delay_us(3); n++; } latch(); n=0; STB_IN&=0b11111011; _delay_us(500); STB_IN|=(1<<STB0); STB_IN&=0b11110111; _delay_us(500); STB_IN|=(1<<STB1); STB_IN&=0b11101111; _delay_us(500); STB_IN|=(1<<STB2); //vpered(300); //n=0; //_delay_ms(100); //vpered(100); }
      
      





The function of printing and burning lines.



 void recieve() { ///while(f); if ((com==0x50)&&(rezhim==0))/// P { //USART_Transmit('X'); com=0; USART_Transmit('B'); rezhim=1; } if ((rezhim==1)&&(send!=0)) { str[iFF]=com; send=0; iFF++; if (send == 1) { USART_Transmit('B'); } if (iFF==54) { USART_Transmit('P'); USART_Transmit('R'); USART_Transmit('I'); USART_Transmit('N'); USART_Transmit('T'); USART_Transmit('E'); USART_Transmit('D'); PORTB|=1<<0; _delay_ms(1); print_all_pixel(); //print_all_pixel(); go1(1500,ggg); rezhim=0; iFF=0; ggg++; if (ggg==8) { ggg=0; } } } if ((com==0x52)&&(rezhim==0))///R { com=0; go1(1000,ggg); rezhim=0; iFF=0; ggg++; if (ggg==8) { ggg=0; } USART_Transmit('O'); USART_Transmit('K'); //vpered(300); } }
      
      





The main function that spins in the eternal file. When the letter “P” comes in, I turn on the print mode. Further, all other characters begin to be typed into the buffer. Further, when the buffer is packed with 54 bytes (or 432 bits), then we print the line and send the word PRINTED via USART.

Well, that's all with the iron part. In the next part I will write about the software part, namely about the program in python. Sources .



image







All Articles