//program sourcenavn er gg.c #include //In use #include #include #include #include // In use #include //In use #define base 0x378 /*Here is Port defined*/ float x = 144.000; int value = 0; int s = 0x01; int kbhit(void) { struct termios oldt, newt; int ch; int oldf; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); oldf = fcntl(STDIN_FILENO, F_GETFL, 0); fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); fcntl(STDIN_FILENO, F_SETFL, oldf); if(ch != EOF) { ungetc(ch, stdin); return 1; } return 0; } int int_round(double n) // Round n { return (n > 0.0) ? (n + 0.5) : (n -0.5); } void setfrq() { if ((x>=144.000) && (x<=146.000)) { value = int_round((x - 140.8) * 40.0); /* Calculation */ printf("\nPortout= %d", value); /* Show Output on Led's */ outb(value, base); } else printf("\nInvalid input."); } void getfrq() { outb(0x01, base+2); printf("\nInput frequency as 144.000 in Step 25KHz.: "); scanf("%f",&x); setfrq(); } void togg_tx() { if (s==0x01) s=0x00; else s=0x01; char c = (char) (s+48); printf("\nStrobe=%c",c); outb(s, base+2); } void initmsg() { printf("\n------\nPress:"); printf("\n\"f\" - to input frequency,"); printf("\n\"q\" - to exit program,"); printf("\n - to toggle transmitter"); } main(int argc, char **argv) { // Main starting here printf("\nProgram Started-"); if (ioperm(base, 3, 1)) { perror("ioperm"); printf("\nError"); exit(1); } // Use sudo ! printf("\nPort open"); outb(s, base+2); setfrq(); initmsg(); while(1) { if (kbhit()) { char ch = getchar(); if ((ch == 'Q') || (ch == 'q')) { outb(0x01, base+2); printf("\nProgram Terminated."); exit(0); } if ((ch == 'F') || (ch == 'f')) getfrq(); if (ch == ' ') togg_tx(); initmsg(); } usleep(500); } }