This isn't very clearly written code, but if you can get a grasp of what it's trying to achieve, then porting it to a PIC ought to be trivial. I hope the comments help a bit, if not mail me. Regards Mike Rigby-Jones > Hi > I have a problem, because I don«t know C- language !!! > I wan«t to know how this C code works (it sends byte trough the parallel > port to my Ti calculator, the link only has 3 wires and one is GND ). > I want to translate it to PIC, so I can interface my Ti with the PIC > Anything would help, just a few comnents and I«ll try to figure out the > rest > Thanks for you time > Javier > > /* > * Sends a byte to the calculator > */ > int put92(char data) /* function put92, accepts a char(1 > byte in PC terms) and returns an int (16 bit word) > { > int bit; /* declares a 16 bit > variable called bit */ > for (bit=0; bit<8; bit++) { /* loop using bit as a counter. bit > is incremented for each loop iteration until bit = 8 */ > if (bit==1) tx(1); /* when bit=1 then function > tx is called passing an argument off 1. You don't seem to have this > function */ > if (data&1) { /* is bit 0 of variable > 'data' set ?*/ > outportb(lpt_out, 2); /* Yes it is. Output a value of 2 to the > printer port (sets bit 1) */ > while (inportb(lpt_in)&0x10); /* read port lpt_in and loop while > bit 5 is set */ > outportb(lpt_out, 3); /* outputs 3 to the printer > port (sets bits 0 and 1) */ > while ((inportb(lpt_in)&0x10)==0x00); /* read port lpt_in and loop > while bit 5 is not set */ > } else { > outportb(lpt_out, 1); /* bit 0 of data is NOT set, output a 1 to > the printer port. (sets bit 0) */ > while (inportb(lpt_in)&0x20); /* read port lpt_in and loop while > bit 6 is set */ > outportb(lpt_out, 3); /* output 3 to the printer > port, (sets bits 0 and 1) */ > while ((inportb(lpt_in)&0x20)==0x00); /* read port lpt_in and loop > while bit 6 is not set */ > } > data>>=1; /* shift > data right one place, roughly equivavlent to RRF on pic */ > // may need 10us delay here > } > } > > > /* > * Reads a byte from the calculator > */ > unsigned char get92(void) /* function get92 accepts no > arguments and returns an unsigned char (8 bit byte) */ > { > int bit; /* declare > 16 bit variable 'bit' */ > unsigned char data=0, v; /* declare 8 bit variabl es > 'data' and 'v'. Data is initialised to 0*/ > for (bit=0; bit<8; bit++) { /* set up loop as > before */ > while ((v=inportb(lpt_in)&0x30) == 0x30); /* read port lpt_in > and puts result in v. Loops while bits 4 and 5 are set; */ > if (v==0x10) { /* is v = 0x10 ? */ > data=(data>>1)|0x80; /* yes, shift data right one > place and OR the result with 0x80; > outportb(lpt_out, 1); /* output 1 to printer port > (sets bit 0) > while ((inportb(lpt_in)&0x20)==0x00); /* read port lpt_in and loop > while bit 5 is clear */ > outportb(lpt_out, 3); /* output 3 to printer port > (sets bits 0 and 1) */ > } else { /* > no, v is not equal to 0x10 */ > data=data>>1; /* shift 'data' > right one place */ > outportb(lpt_out, 2); /* output 2 to lpt_out (sets > bits 0 and 1) */ > while ((inportb(lpt_in)&0x10)==0x00); /* read port lpt_in and loop > while bit 4 is clear */ > outportb(lpt_out, 3); /* output 3 to printer port > (sets bits 0 and 1) */ > } > // may need 10us delay here > } > return data; /* returns > data to calling function */ > }