Skip to content

Instantly share code, notes, and snippets.

@vijaypurohit
Last active December 26, 2017 12:07
Show Gist options
  • Save vijaypurohit/1f74d2a596817271c8664bbf4b454725 to your computer and use it in GitHub Desktop.
Save vijaypurohit/1f74d2a596817271c8664bbf4b454725 to your computer and use it in GitHub Desktop.
This cpp program is used to blink led using computer parallel port
#include <stdio.h>
#include <stdlib.h>
#include <asm/io.h>
#include <unistd.h>
#define base 0x378 /* printer port base address */
#define value 255 /* numeric value to send to printer port */
main()
{
char a,b,g;
if (ioperm(base,1,1))
/*fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);*/
printf("\n------------------------------------\n");
outb(0, base);
printf("enter the 1 for on ");
scanf("%c",&a);
if(a=='1')
{
usleep(2000000);
outb(value,base);
}
//scanf("%c",&b);
printf("\nenter the 0 for off:");
scanf(" %c",&b);
if(b=='0')
{
outb(0,base);
}
printf("enter the star for blinking:");
scanf(" %c",&g);
if(g=='*')
{
while(1)
{
outb(value,base),
usleep(250000),
outb(0,base),
usleep(250000);
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#define base 0x378 /* printer port base address */
#define value 255 /* numeric value to send to printer port */
main()
{
char a,b,g;
printf("\n------------------------------------\n");
outp(base,0);
printf("enter the 1 for on ");
scanf("%c",&a);
if(a=='1')
{
sleep(2000);
outp(base,0);
}
printf("\nenter the 0 for off:");
scanf(" %c",&b);
if(b=='0')
{
outp(base,0);
}
printf("enter the star for blinking:");
scanf(" %c",&g);
if(g=='*')
{
while(1)
{
outp(base,0);
sleep(2500),
outp(base,1),
sleep(2500);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment