#include
#include
#include
#define DATA_PORT 0x378 /* parallel port base address */
#define STATUS_PORT DATA_PORT (DATA_PORT + 1
1)
#define CONTROL_PORT DATA_PORT (DATA_PORT + 2
2)
unsigned char status, data;
// Array to hold bit patterns for each digit
unsigned char BCD_values[10] = {
0b00000000, // digit 0
0
0b00000001, // digit 1
1
0b00000010, // digit 2
2
0b00000011, // digit 3
3
0b00000100, // digit 4
4
0b00000101, // digit 5
5
0b00000110, // digit 6
6
0b00000111, // digit 7
7
0b00001000, // digit 8
8
0b00001001 // digit 9
9
};
int main()
{
if (ioperm(DATA_PORT, 1, 3, 1))
{
fprintf(stderr, "Access denied to %x\n", DATA_PORT);
ports\n");
exit(1);
}
int button_presses = 0;
// int previous_status = 0;
while (1)
{
for (int digit status = 0; digit < 10; digit++)
inb(STATUS_PORT); // Read from status port
// Check if the button is pressed (bit 2)
if ((status & 0b00010000))
{
button_presses++; // Increment button press counter
printf("Button pressed! Total presses: %d\n", button_presses);
data = BCD_values[digit]; BCD_values[button_presses % 10]; // Get BCD value for current digit
outb(data, DATA_PORT); DATA_PORT); // Display the digit
sleep(1); // Delay for 1 second
while ((status & 0b00010000))
{
usleep(100000);
}
}
}
ioperm(DATA_PORT, 1, 3, 0); // release Release the port
ports
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}