/** * Software code to download Hex Code to Memory * @A Sahu iit guwahati * * It works in Turbo C++ * instead of "outp()" you can try other function "outportb()" * read outportb mannual properly */ #include #include #include #include #define DelayAmount 100 // Delay need to be calibrated void send2PP(int v){ int i=0; if (v<0 ||v>15) return; int data=0, portout=0x378; // Send data 0/1 at 0x378 and it will be avilable on pin 2 // send a Clock to retrive the data send at data 0/1 int databit0; int databit1; i=0; // send 4 bits and for each bit send at D0 and clock is // also generated at bit D1 (High for 100ms and Low for 100ms) while(i<4){ data=0; //retrive ith bit and put into data position D0 databit0=v%2;v=v/2; data=data|databit0; //Instert a LOW CLOCK value at data position D1 and send data D0 databit1=0;data=data|databit1; outp(portout,data); delay(DelayAmount); // Delay need to be calibrated //Instert a High CLOCK value at data position D1 and send data D0 databit1=2;data=data|databit1; outp(portout,data); delay(DelayAmount); // Delay need to be calibrated i++; } } void ProcessChar(char c){ int v=-1; // test if HEX value 0-9 and A-F/a-f if ( c>=48 && c<=57 ) v=c-48; // if '0' send 0; if '9' send 9 if ( c>=65 && c<=70 ) v=c-65+10; //if 'A' send 10 if ( c>=97 && c<=102) v=c-97+10; // if 'a' send 10 if (v!=-1){ send2PP(v); } } int main(int argc, char *argv[]){ char filename[20]; int ch; FILE *fp; if (agrc<1){ printf("\nEnter the filename of HEX code program\n C:>codePP.exe FileName \n"); exit(1); } strcpy(filename,argv[1]); fp=fopen(filename,"r"); //read character by character and process while ( ( ch = fgetc(fp) ) != EOF ) { putchar( ch ); ProcessChar(ch); } printf("\nFile Transfer Done\n"); return 0; }