Step 7Emulation Code Routines
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 Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|









































