/* ****************************************************************************** C Language Sample #2 : SAMPLE2.C This program will display the status of each bit in the status register and displays the temperature inside your computer. Last Modified On: 2/11/98 ****************************************************************************** */ #include #include "kbinp.h" unsigned int BASE; unsigned char CurBit; float Tmp; void IOPermission() { if(iopl(3)<0) { fprintf(stderr, "NO IO PERMISSION\n"); } } unsigned AskForBaseAddress(unsigned int OldOne) { char msg[3]; unsigned int newone; unsigned int temp = 0; int index = 0; int letter; puts("Please enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); while(temp==0) { newone=0; index=0; while((letter = getchar())!='\n') //Read char by char and store in Msg msg[index++] = letter; sscanf(msg, "%X", &newone); if(newone==0){ //Check to see if address was inputed temp=OldOne; //Assign default if not } else if((newone>=0x100)&&(newone<=0xffff)){ //Check to see if inputed addres is valid temp=newone; } else { //If Newone invalid ask for new value. printf("\nEnter the Base Address or press ENTER for %x > ", OldOne); for(index=0; index<=3; index++) msg[index]=0; } //Run while until temp = valid address } return(temp); } /* end of AskForBaseAddress */ int main(void) { system("clear"); BASE = AskForBaseAddress(0x350); IOPermission(); puts("C Sample #2: Reading Control Register and Temperature\n"); puts("This program demonstrates how to read the Control Register and\n"); puts("Temperature at BASE+4 and BASE+5, respectively.\n"); puts("Please note that some feature require that options be installed.\n"); puts("A keystroke will stop the program.\n\n"); puts("Press enter to start.\n"); while(getch()!='\n'); /* Grab keystroke */ system("clear"); puts(" Status Control Register Values \n"); puts(" \n"); puts(" Bit Number Value Description \n"); puts(" 0 1 When 0, CTR1 has timed out \n"); puts(" 1 1 When 0, temperature is too high OPTION 2\n"); puts(" 2 1 Isolated digital input #0 OPTION 4\n"); puts(" 3 1 Isolated digital input #1 OPTION 4\n"); puts(" 4 0 When 0, Speed of fan is correct OPTION 4\n"); puts(" 5 1 When 0, the Voltage is too high OPTION 1\n"); puts(" 6 1 When 0, the Voltage is too low OPTION 1\n"); puts(" 7 1 When 0, an INT has occured \n\n"); puts(" Temperature inside computer is 000.0øC. OPTION 3 (=194.0 if not installed.)\n"); puts(" Press Enter to exit this program...\n"); do { for (CurBit = 0; CurBit <= 7; CurBit++) { if(CurBit==0){ system("tput cup 6 18"); } else if(CurBit==1) {system("tput cup 8 18");} if(CurBit==2) {system("tput cup 10 18");} else if(CurBit==3) {system("tput cup 12 18");} else if(CurBit==4) {system("tput cup 14 18");} else if(CurBit==5) {system("tput cup 16 18");} else if(CurBit==6) {system("tput cup 18 18");} else if(CurBit==7) {system("tput cup 20 18");} printf("%hu\n", (unsigned char)((inb(BASE+4) & (1 << CurBit)) == (1 << CurBit))); /* check bit */ } system("tput cup 23 34"); Tmp = (inb(BASE+5) * (11.0 / 15.0)) + 7; printf("%5.1f\n", Tmp); /* Temperature is simply ((BASE+5) * 11/15) + 7*/ } while (kbhit()==0); return 0; }