2 Replies - 3122 Views - Last Post: 02 June 2008 - 05:22 AM Rate Topic: -----

#1 mese2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-May 08

Please help for C++ codes to read LED status using parallel port inter

Posted 31 May 2008 - 11:24 PM

//This example code shows how to switch a LED on/off in Visual C++.
//We use two variables N and L explained below.

//I am assuming you have some knowledge in C++. Instruction to connect the LED is given in the Tutorial.







#include <iostream.h> //The most important include to display data on screen.
#include <conio.h> //Include for outp and inp functions for the printer port.
#include <windows.h> //For _sleep functions for our time delay.

#define addr 0x3BC //IMPORTANT: Normaly 378 is the most common address,
//if not then insert your address instead of 378

int main()
{
int freq; //Variable for time delay.
int L; //Variable for counts of Blinking LED.


cout<<"\t\t XheavenlyX WELCOMES YOU!!! \n\n"; //How can I forget this ^_^

cout<<"How many times to blink?? Enter 0 to exit: "; //Ask user how many times to blink the LED
cin>>L; //And exit if zero is entered.


if (L==0)
{
cout<<endl<<"Exiting application..."<<endl; //Code to exit if L = 0.
for (int i=0;i<=5;i++) {_sleep(500);} //A lame pause before exit!
exit(0);
}

cout<<"Frequency (in mS): "; //Ask user to enter the frequency at which the LED will blink.
cin>>freq; //Store that value in freq.

//Bottom code is the Juice! This will blink your LED the number of times you put in L.
//The speed of blinks will depend on freq. As an example if you entered 500milliseconds. The LED
//will blink twice every second since 500ms is half of 1000ms (1000millisecondss = 1sec)

for (int i=1;i<=L;i++) //The loop. L times to blink.
{
_outp(addr,1); //Output is high in the first 'Data bit' of port(*), i.e Pin number 2 where you have connected the LED.
_sleep(freq); //freq mS delay between the high and low of LED.
_outp(addr,0); //Output is low now
_sleep(freq); //Pause again between the high,
}
return 0; //main returns nothing to you. ^_^
} // For an indepth look at


//(*)NOTE: There are some simple calculations to turn on/off the other PINs on the printer port.

//links
// http://msdn2.microso...y/733szwah.aspx _outp, _inp etc.

This post has been edited by mese2000: 31 May 2008 - 11:34 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Please help for C++ codes to read LED status using parallel port inter

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: Please help for C++ codes to read LED status using parallel port inter

Posted 02 June 2008 - 05:06 AM

What is your question/problem????


And please you [code] tags when posting code!
Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Please help for C++ codes to read LED status using parallel port inter

Posted 02 June 2008 - 05:22 AM

I think this is supposed to be a tutorial. Try posting it in the tutorials section, and if it gets approved you will get 50 Dream Kudos :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1