Skip to content

Instantly share code, notes, and snippets.

@yjroot
Created August 4, 2013 01:16
Show Gist options
  • Save yjroot/6148649 to your computer and use it in GitHub Desktop.
Save yjroot/6148649 to your computer and use it in GitHub Desktop.
#include <avr/io.h>
#include <util/delay.h>
void inkjet_init(){
PORTB &= ~0x07; //0000 0218
DDRB |= 0x07;
PORTC &= ~0x3e; //0076 5430
DDRC |= 0x3e;
PORTD &= ~0xf0; //9abc 0000
DDRD |= 0xf0;
}
void inkjet_print(unsigned int data){
char bit;
bit = (data >> 0) & 0x01;
PORTB |= bit << 1;
_delay_us(6);
PORTB &= ~0x07;
_delay_us(0.5);
bit = (data >> 1) & 0x01;
PORTC |= bit << 1;
_delay_us(6);
PORTC &= ~0x3e;
_delay_us(0.5);
bit = (data >> 2) & 0x01;
PORTB |= bit << 2;
_delay_us(6);
PORTB &= ~0x07;
_delay_us(0.5);
bit = (data >> 3) & 0x01;
PORTC |= bit << 2;
_delay_us(6);
PORTC &= ~0x3e;
_delay_us(0.5);
bit = (data >> 4) & 0x01;
PORTC |= bit << 3;
_delay_us(6);
PORTC &= ~0x3e;
_delay_us(0.5);
bit = (data >> 5) & 0x01;
PORTC |= bit << 4;
_delay_us(6);
PORTC &= ~0x3e;
_delay_us(0.5);
bit = (data >> 6) & 0x01;
PORTC |= bit << 5;
_delay_us(6);
PORTC &= ~0x3e;
_delay_us(0.5);
bit = (data >> 7) & 0x01;
PORTB |= bit << 0;
_delay_us(6);
PORTB &= ~0x07;
_delay_us(0.5);
bit = (data >> 8) & 0x01;
PORTD |= bit << 7;
_delay_us(6);
PORTD &= ~0xf0;
_delay_us(0.5);
bit = (data >> 9) & 0x01;
PORTD |= bit << 6;
_delay_us(6);
PORTD &= ~0xf0;
_delay_us(0.5);
bit = (data >> 10) & 0x01;
PORTD |= bit << 5;
_delay_us(6);
PORTD &= ~0xf0;
_delay_us(0.5);
bit = (data >> 11) & 0x01;
PORTD |= bit << 4;
_delay_us(6);
PORTD &= ~0xf0;
_delay_us(0.5);
_delay_us(800-78);
}
int main(void)
{
inkjet_init();
for(;;){
_delay_ms(1000);
inkjet_print(0x01e0); //0001 1110 0000
inkjet_print(0x07f8); //0111 1111 1000
inkjet_print(0x0ffa); //1111 1111 1100
inkjet_print(0x0ffa); //1111 1111 1100
inkjet_print(0x03fe); //0011 1111 1110
inkjet_print(0x007f); //0000 0111 1111
inkjet_print(0x03fe); //0011 1111 1110
inkjet_print(0x0ffa); //1111 1111 1100
inkjet_print(0x0ffa); //1111 1111 1100
inkjet_print(0x07f8); //0111 1111 1000
inkjet_print(0x01e0); //0001 1110 0000
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment