Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,208 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,327 people online right now. Registration is fast and FREE... Join Now!




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

 
Reply to this topicStart new topic

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

mese2000
31 May, 2008 - 10:24 PM
Post #1

New D.I.C Head
*

Joined: 31 May, 2008
Posts: 1

//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 happy.gif

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. happy.gif
} // 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.microsoft.com/en-us/library/733szwah.aspx _outp, _inp etc.

This post has been edited by mese2000: 31 May, 2008 - 10:34 PM
User is offlineProfile CardPM
+Quote Post

jjsaw5
RE: Please Help For C++ Codes To Read LED Status Using Parallel Port Inter
2 Jun, 2008 - 04:06 AM
Post #2

I must break you
Group Icon

Joined: 4 Jan, 2008
Posts: 1,411



Thanked: 7 times
Dream Kudos: 125
Expert In: HTML, CSS, Database,

My Contributions
What is your question/problem????


And please you [code] tags when posting code!
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Please Help For C++ Codes To Read LED Status Using Parallel Port Inter
2 Jun, 2008 - 04:22 AM
Post #3

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,556



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
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 smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 12:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month