3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Reverse Engineering to Emulate Ink Cartridges for a Epson Printer

Step 7Emulation Code Routines

Now the fun part!

I need the printer to think that there are four ink cartridges installed, to do this we need to implement some emulation functions first. Again from previous knowledge I have predefined these in the header:

• #define epsnCartReady() (_ecRST)
• extern unsigned char espnCartGetAddr(void);
• extern void epsnCartOut(unsigned char data);
• extern unsigned char epsnCartIn(unsigned char data);


epsnCartReady is a macro that is used check if the printer has RST set high.
epsnCartGetAddr returns the address that the print head is requesting.
epsnCartOut is used to send data to the Host controller
epsnCartIn is used to receive data from the Host when it’s writing

So this time, instead of controlling the SCK to go high or low, we need it to wait for it to go high or low, but if the reset goes low, then stop everything and return:

unsigned char espnCartGetAddr(void){
    char i=0;
    char temp = 0x00;

    while((i<4) && _ecRST){ // Loop while i < 4 and RST is HIGH
        temp>>=1; // Right Shift Temp by one
        while((!_ecSCK) && (_ecRST)); // Wait for the clock to go high
        if(_ecSDA){// only if SDA is high
            temp |= 0x08; // then set the 4th bit
        }
        while((_ecSCK) && (_ecRST));// wait for the clock to go low
        i++; // increment the counter
    }

    if(_ecRST == 0){
        return 0xFF;//if RST went low, means the Host killed the signal
    }
    return temp; //return the address and the read/write bit
}


And the Out function:

void epsnCartOut(unsigned char data){
    char i = 0;
    char temp = data;

    _ecSDATRIS = 0; // set the SDA to output
    _ecSDALat = 0; // set SDA low

    while((i<8) && _ecRST){ // Loop while I < 8 and RST is high
        while(!_ecSCK && _ecRST); // Wait for SCK to go high
        _ecSDALat = temp&0x01; // Set SDA high or low according to the first bit

        while(_ecSCK && _ecRST); // Wait for SCK to go low
        temp>>=1; // Right shift the data by one
        i++; // increment the counter by one
    }
    _ecSDATRIS = 1; // Set SDA to an output
    _ecSDA = 1; // not sure if this is needed
}


And finally the In function:

unsigned char epsnCartIn(void){
    unsigned char i=0;
    char temp = 0x00;

    while((i<8) && _ecRST){ // Loop while I < 8 and RST is high
        temp>>=1; // Right Shift the temp by one
        while(!_ecSCK && _ecRST); // Wait for SCK to go High
        if(_ecSDA){ //only id SDA is high
            temp |= 0x80; // Set the 8th bit
        }

        while(_ecSCK && _ecRST);// Wait for SCK to go low
        i++; // Increment the counter by one
    }
    return temp; // return what we have received
}


« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
2
Author:NZSmartie
I'm currently studying at Massey University in New Zealand. I'm doing Computer and Electrical Engineering which is a fun course and already proving my skills to professors around the campus. I enjoy ...
more »