Kode: Vælg alt
#include <stdio.h>//In use
#include <stdlib.h>// In use
#include <sys/io.h>//In use
#define base 0x378 /*Here is Port defined*/
main(int argc, char **argv)
{
float x;
int value;
int int_round(double n) // Round n
{
return (n > 0.0) ? (n + 0.5) : (n -0.5);
}
if (ioperm(base, 3, 1)) {perror("ioperm"); exit(1);// Use sudo !
}
start:
printf("\nInput frequenz as 144.000 in Step 25KHz ");
scanf("%f",&x);
value = int_round((x - 140.8) * 40.0); /* Calculation */
if ((x<144.000) || (x>146.000 ))
printf("\nfreq Outside 2 Meter band\n ");
printf("\nPortout= %d", value); /* Show Output on Led's */
outb(value, base);
goto start;
}
der skal stå 140.8 ved den smiley der hos nogle hedder Sej Aner ikke hvor den kommer fra
Ikke ideelt da goto anvendes, hvilket ikke er god programmering. Men det virker da. Forsøger at finde ud af, hvordan man bruger WHILE
Her ses programmet i funktion.
ole@ubuntu:~$ cd Skrivebord
ole@ubuntu:~/Skrivebord$ sudo ./yyyy
[sudo] password for ole:
Input frequenz as 144.000 in Step 25KHz 143.975
freq Outside 2 Meter band
Portout= 127
Input frequenz as 144.000 in Step 25KHz 144.000
Portout= 128
Input frequenz as 144.000 in Step 25KHz 145.025
Portout= 169
Input frequenz as 144.000 in Step 25KHz 146
Portout= 208
Input frequenz as 144.000 in Step 25KHz 146.075
freq Outside 2 Meter band
Portout= 211
Input frequenz as 144.000 in Step 25KHz
Venlig hilsen en ivrig 75 årig nybegynder OZ6OH alias OZ7T Ole