Le Messe Noir's Profile
Reputation: 1
Apprentice
- Group:
- Members
- Active Posts:
- 33 (0.07 per day)
- Joined:
- 27-February 12
- Profile Views:
- 219
- Last Active:
Mar 12 2012 11:18 PM- Currently:
- Offline
Previous Fields
- Country:
- CA
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: DELETE ALL DUPLICATION ELEMENTS FROM ARRAY
Posted 12 Mar 2012
umm.... what exactly is the question? -
In Topic: Western C Board
Posted 12 Mar 2012
#define, on 09 March 2012 - 09:07 PM, said:Hi, your welcome suggests that your code is more complicated than necessary.
printf("Welcome \n\n\n"); printf("Put the switches in the open position to begin.\n\n"); printf("Input an interger in hex format with no spaces OR ELSE\n\n"); printf("The LEDs will then cycle through your hex integer putting \nin 0's where no number was entered\n\n"); printf("If a switch is closed the LED will stay on that corresponding byte \nuntil the switches are all in the open position where \nit will ask for a new integer\n\n\n\n"); printf("For switch states 0 is open and 1 is closed.\n\n"); printf("For LED states the left value is for the left 4 LED and \nthe right value is for the right 4 LED\n\n");
pseudocode:
while(true) { set switches to open get integer from user cycle LED's }
You repeat code which could be put in a function eg updating the screen
system("CLS"); timeDate(); swShow(swSt); ledShow(leds);
Output number to LED's:
OutPort( LPT1_OUT, kbnum ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay
Here you pass a value to a function then override the value. So passing the value is not required.
int ledShow (unsigned char leds) { leds = InPort( LPT1_OUT ) ; printf("\rLED States: %X",leds); // \r makes it start at the line again every time return 0; }
Oh it was pretty complicated I got it to work though//lab 9 V OMGIAMGOINGTOKILLMYSELFIHATETHISWESTERNCBOARD.217 Sam Sloane c0353667 /* This program communicates with the Western C Board via the PC's parallel port. This program should detect and display on the console the switch settings and the LED states. Different switch settings should cause different behaviours USER INTERFACE EXAMPLE DATE SWITCH Positions: 0000 //0 = open 1 = closed LED States: F1 //the first digit correspondes to the left 4 led and the right digit is for the right leds */ #include <stdio.h> #include <stdlib.h> #include "pport_io.h" #include <time.h> int timeDate (void); int swShow (unsigned char swSt); int ledShow (unsigned char ledSt);//my function prototypes enum { kbEntry, //0 scrollNum, //1 sw3, //2 sw2, //3 sw1, //4 sw0, //5 undefined //6 } wcbState; int main() { unsigned char leds = 0x00; unsigned char led = 0x00; //ledSt = 0x00; unsigned char switches = 0x00, swSt = 0x00; //switch state int i; unsigned int kbnum = 0, //keyboard number tempnum = 0; //temp number InitPortIO (); printf("Welcome \n\n\n"); printf("Put the switches in the open position to begin.\n\n"); printf("Input an interger in hex format with no spaces OR ELSE\n\n"); printf("The LEDs will then cycle through your hex integer putting \nin 0's where no number was entered\n\n"); printf("If a switch is closed the LED will stay on that corresponding byte \nuntil the switches are all in the open position where \nit will ask for a new integer\n\n\n\n"); printf("For switch states 0 is open and 1 is closed.\n\n"); printf("For LED states the left value is for the left 4 LED and \nthe right value is for the right 4 LED\n\n"); system("pause"); if ( !InitPortIO( ) ) //if the program cannot initiate port io it gives an error. { printf( "ERROR loading Inpout.dll.\n Terminating Program.\n\n" ); system( "PAUSE" ); exit( 1 ); } //start of program switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits swSt = InPort( LPT1_IN ) & 0xF0; while (1) { system( "CLS" ); // clear the screen if ((switches & 0xF0) == 0x00) //if the upper 4 bits are 0, the switches are open, start keyboard entry mode { wcbState = kbEntry; } else if ((switches & 0xF0) == 0x80) //if msd is 1 then switch 0 is closed { wcbState = sw3; } else if ((switches & 0xF0) == 0x40) { wcbState = sw2; } else if ((switches & 0xF0) == 0x20) { wcbState = sw1; } else if ((switches & 0xF0) == 0x10) { wcbState = sw0; } else { wcbState = undefined; } led = InPort ( LPT1_OUT ); // read the pport output leds for (i = 0; i < 1000000; i++); // delay a while switch (wcbState)//switch statement for the wcb statement { case kbEntry://case statement for keyboard entry mode timeDate(); swShow(swSt); ledShow(leds); printf("\n\n\nPlease enter an integer in HEX format fom 00 00 00 00 to FF FF FF FF\n\nNO SPACES PLEASE\n\n"); scanf("%x", &kbnum);//scanf statement for keyboard entry mode system("CLS"); while ((switches & 0xF0) == 0) //if the switches and the mask is on and equals open { OutPort( LPT1_OUT, kbnum ); //puts kbnum onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; system("CLS");//clears the screen timeDate();//date time function swShow(swSt); ledShow(leds); tempnum = kbnum >>8; //shift bits over 8 OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay switches = InPort( LPT1_IN ) & 0xF0; system("CLS");//clear screen timeDate();//time declarations swShow(swSt); ledShow(leds); tempnum = tempnum >>8;//shifts bits over 8 OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay switches = InPort( LPT1_IN ) & 0xF0; system("CLS");//clears screen timeDate();//time feature swShow(swSt); ledShow(leds); tempnum = tempnum >>8;//shifts bit over 8 right OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay switches = InPort( LPT1_IN ) & 0xF0; system("CLS");//clears screen timeDate();//displays the time in each cycle swShow(swSt); ledShow(leds); switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits } break; case scrollNum: /******************************************************************************************/ printf("inside scrollNum"); break; case sw3: while ((switches & 0xF0) == 0x80) { OutPort( LPT1_OUT, kbnum >>24 ); //puts kbnum shifted 3 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS");//clears screen timeDate(); swShow(swSt); ledShow(leds); } break; case sw2: while ((switches & 0xF0) == 0x40) { OutPort( LPT1_OUT, kbnum >>16 ); //puts kbnum shifted 2 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw1: while ((switches & 0xF0) == 0x20) { OutPort( LPT1_OUT, kbnum >>8 ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw0: while ((switches & 0xF0) == 0x10) { OutPort( LPT1_OUT, kbnum ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; /****************************************************************************/ case undefined: // printf("inside undefined\n"); while (!(switches & 0xF0) == 0x00) { printf("\nUNDEFINED\nPlease place all of the switches in the open position.\n"); switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system( "CLS" ); timeDate(); swShow(swSt); ledShow(leds); } break; } } return 0; } int timeDate (void) { time_t startTime; startTime = time( NULL ); printf( ctime( &startTime ) ); // print out a formatted time return 0; } int swShow (unsigned char swSt) { swSt = InPort( LPT1_IN ) & 0xF0; if ( swSt == 0x00) { printf("Switch Positions: 0000\n"); } else if ( swSt == 0x10) { printf("Switch Positions: 0001\n"); } else if ( swSt == 0x20) { printf("Switch Positions: 0010\n"); } else if ( swSt == 0x30) { printf("Switch Positions: 0011\n"); } else if ( swSt == 0x40) { printf("Switch Positions: 0100\n"); } else if ( swSt == 0x50) { printf("Switch Positions: 0101\n"); } else if ( swSt == 0x60) { printf("Switch Positions: 0110\n"); } else if ( swSt == 0x70) { printf("Switch Positions: 0111\n"); } else if ( swSt == 0x80) { printf("Switch Positions: 1000\n"); } else if ( swSt == 0x90) { printf("Switch Positions: 1001\n"); } else if ( swSt == 0xa0) { printf("Switch Positions: 1010\n"); } else if ( swSt == 0xb0) { printf("Switch Positions: 1011\n"); } else if ( swSt == 0xc0) { printf("Switch Positions: 1100\n"); } else if ( swSt == 0xd0) { printf("Switch Positions: 1101\n"); } else if ( swSt == 0xe0) { printf("Switch Positions: 1110\n"); } else if ( swSt == 0xf0) { printf("Switch Positions: 1111\n"); } return 0; } int ledShow (unsigned char leds) { leds = InPort( LPT1_OUT ) ; printf("\rLED States: %X",leds); // \r makes it start at the line again every time return 0; } -
In Topic: Western C Board
Posted 9 Mar 2012
so basically my output in the cmd shows the print messages. Then I am prompted to enter a number in hex and if I enter F8 for example I get 11111000 where '1' is an illuminated LED and '0' is not then If I close more than 1 switch the state becomes undefined. It also display the switch state so all open in 0000 and the last digit is open 0001 and third and fourth switch is 0011 but also undefined. I just need it to display the the switch state on the led. So for example if switch 3 is close it will display on the 3rd led. I know I am not giving alot of information but this LAB I am required to do is way above me and I have asked several classmates well more like 25 and this is as far as I have gotten. Thanks in advance for the help. -
In Topic: Western C Board
Posted 9 Mar 2012
so Isolated the section of code that is the problem.... well not problem but needs work. its the section between the two bars of astriks
//lab 9 V OMGIAMGOINGTOKILLMYSELFIHATETHISWESTERNCBOARD.217 Sam Sloane c0353667 /* This program communicates with the Western C Board via the PC's parallel port. This program should detect and display on the console the switch settings and the LED states. Different switch settings should cause different behaviours USER INTERFACE EXAMPLE DATE SWITCH Positions: 0000 //0 = open 1 = closed LED States: F1 //the first digit correspondes to the left 4 led and the right digit is for the right leds */ #include <stdio.h> #include <stdlib.h> #include "pport_io.h" #include <time.h> int timeDate (void); int swShow (unsigned char swSt); int ledShow (unsigned char ledSt);//my function prototypes enum { kbEntry, //0 scrollNum, //1 sw3, //2 sw2, //3 sw1, //4 sw0, //5 undefined //6 } wcbState; int main() { unsigned char leds = 0x00; unsigned char led = 0x00; //ledSt = 0x00; unsigned char switches = 0x00, swSt = 0x00; //switch state int i; unsigned int kbnum = 0, //keyboard number tempnum = 0; //temp number InitPortIO (); printf("Welcome \n\n\n"); printf("Put the switches in the open position to begin.\n\n"); printf("Input an interger in hex format with no spaces OR ELSE\n\n"); printf("The LEDs will then cycle through your hex integer putting \nin 0's where no number was entered\n\n"); printf("If a switch is closed the LED will stay on that corresponding byte \nuntil the switches are all in the open position where \nit will ask for a new integer\n\n\n\n"); printf("For switch states 0 is open and 1 is closed.\n\n"); printf("For LED states the left value is for the left 4 LED and \nthe right value is for the right 4 LED\n\n"); system("pause"); if ( !InitPortIO( ) ) //if the program cannot initiate port io it gives an error. { printf( "ERROR loading Inpout.dll.\n Terminating Program.\n\n" ); system( "PAUSE" ); exit( 1 ); } //start of program switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits swSt = InPort( LPT1_IN ) & 0xF0; while (1) { system( "CLS" ); // clear the screen if ((switches & 0xF0) == 0x00) //if the upper 4 bits are 0, the switches are open, start keyboard entry mode { wcbState = kbEntry; } else if ((switches & 0xF0) == 0x80) //if msd is 1 then switch 0 is closed { wcbState = sw3; } else if ((switches & 0xF0) == 0x40) { wcbState = sw2; } else if ((switches & 0xF0) == 0x20) { wcbState = sw1; } else if ((switches & 0xF0) == 0x10) { wcbState = sw0; } else { wcbState = undefined; } led = InPort ( LPT1_OUT ); // read the pport output leds for (i = 0; i < 1000000; i++); // delay a while switch (wcbState)//switch statement for the wcb statement { case kbEntry://case statement for keyboard entry mode timeDate(); swShow(swSt); ledShow(leds); printf("\n\n\nPlease enter an integer in HEX format fom 00 00 00 00 to FF FF FF FF\n\nNO SPACES PLEASE\n\n"); scanf("%x", &kbnum);//scanf statement for keyboard entry mode system("CLS"); while ((switches & 0xF0) == 0) //if the switches and the mask is on and equals open { OutPort( LPT1_OUT, kbnum ); //puts kbnum onto LED for (i = 0; i < 100000000; i++); //delay system("CLS");//clears the screen timeDate();//date time function swShow(swSt); ledShow(leds); tempnum = kbnum >>8; //shift bits over 8 OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay system("CLS");//clear screen timeDate();//time declarations swShow(swSt); ledShow(leds); tempnum = tempnum >>8;//shifts bits over 8 OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay system("CLS");//clears screen timeDate();//time feature swShow(swSt); ledShow(leds); tempnum = tempnum >>8;//shifts bit over 8 right OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++);//delay system("CLS");//clears screen timeDate();//displays the time in each cycle swShow(swSt); ledShow(leds); switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits } break; case scrollNum: /******************************************************************************************/ printf("inside scrollNum"); break; case sw3: // printf("inside sw3"); while ((switches & 0xF0) == 0x80) { OutPort( LPT1_OUT, kbnum >>24 ); //puts kbnum shifted 3 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS");//clears screen timeDate(); swShow(swSt); ledShow(leds); } break; case sw2: //printf("inside sw2"); while ((switches & 0xF0) == 0x40) { OutPort( LPT1_OUT, kbnum >>16 ); //puts kbnum shifted 2 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw1: //printf("inside sw1"); while ((switches & 0xF0) == 0x20) { OutPort( LPT1_OUT, kbnum >>8 ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw0: //printf("inside sw0"); while ((switches & 0xF0) == 0x10) { OutPort( LPT1_OUT, kbnum ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; /****************************************************************************/ case undefined: // printf("inside undefined\n"); while ((!(switches & 0xF0) == 0x00)||(!(switches & 0xF0) == 0x10)||(!(switches & 0xF0) == 0x20)||(!(switches & 0xF0) == 0x40)||(!(switches & 0xF0) == 0x80)) { printf("\nUNDEFINED\nPlease place all of the switches in the open position.\n"); switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system( "CLS" ); timeDate(); swShow(swSt); ledShow(leds); } break; } } return 0; } int timeDate (void) { time_t startTime; startTime = time( NULL ); printf( ctime( &startTime ) ); // print out a formatted time return 0; } int swShow (unsigned char swSt) { swSt = InPort( LPT1_IN ) & 0xF0; if ( swSt == 0x00) { printf("Switch Positions: 0000\n"); } else if ( swSt == 0x10) { printf("Switch Positions: 0001\n"); } else if ( swSt == 0x20) { printf("Switch Positions: 0010\n"); } else if ( swSt == 0x30) { printf("Switch Positions: 0011\n"); } else if ( swSt == 0x40) { printf("Switch Positions: 0100\n"); } else if ( swSt == 0x50) { printf("Switch Positions: 0101\n"); } else if ( swSt == 0x60) { printf("Switch Positions: 0110\n"); } else if ( swSt == 0x70) { printf("Switch Positions: 0111\n"); } else if ( swSt == 0x80) { printf("Switch Positions: 1000\n"); } else if ( swSt == 0x90) { printf("Switch Positions: 1001\n"); } else if ( swSt == 0xa0) { printf("Switch Positions: 1010\n"); } else if ( swSt == 0xb0) { printf("Switch Positions: 1011\n"); } else if ( swSt == 0xc0) { printf("Switch Positions: 1100\n"); } else if ( swSt == 0xd0) { printf("Switch Positions: 1101\n"); } else if ( swSt == 0xe0) { printf("Switch Positions: 1110\n"); } else if ( swSt == 0xf0) { printf("Switch Positions: 1111\n"); } return 0; } int ledShow (unsigned char leds) { leds = InPort( LPT1_OUT ) ; printf("\rLED States: %X",leds); // \r makes it start at the line again every time return 0; } -
In Topic: Western C Board
Posted 9 Mar 2012
so ya I did this late last night a forgot to comment it so I am not sure what exactly this does... if anything can someone help me to understand this code segmentswitch (wcbState) { case kbEntry: timeDate(); swShow(swSt); ledShow(leds); printf("\n\n\nPlease enter an integer in HEX format fom 00 00 00 00 to FF FF FF FF\n\nNO SPACES PLEASE\n\n"); scanf("%x", &kbnum); system("CLS"); while ((switches & 0xF0) == 0) { OutPort( LPT1_OUT, kbnum ); //puts kbnum onto LED for (i = 0; i < 100000000; i++); //delay system("CLS"); timeDate(); swShow(swSt); ledShow(leds); tempnum = kbnum >>8; //shift bits over 8 OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++); system("CLS"); timeDate(); swShow(swSt); ledShow(leds); tempnum = tempnum >>8; OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++); system("CLS"); timeDate(); swShow(swSt); ledShow(leds); tempnum = tempnum >>8; OutPort( LPT1_OUT, tempnum ); //puts tempnum onto LED for (i = 0; i < 100000000; i++); system("CLS"); timeDate(); swShow(swSt); ledShow(leds); switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits } break; case scrollNum: printf("inside scrollNum"); break; case sw3: // printf("inside sw3"); while ((switches & 0xF0) == 0x80) { OutPort( LPT1_OUT, kbnum >>24 ); //puts kbnum shifted 3 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw2: //printf("inside sw2"); while ((switches & 0xF0) == 0x40) { OutPort( LPT1_OUT, kbnum >>16 ); //puts kbnum shifted 2 bytes onto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw1: //printf("inside sw1"); while ((switches & 0xF0) == 0x20) { OutPort( LPT1_OUT, kbnum >>8 ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break; case sw0: //printf("inside sw0"); while ((switches & 0xF0) == 0x10) { OutPort( LPT1_OUT, kbnum ); //puts kbnum shifted 1 byteonto LED for (i = 0; i < 100000000; i++); //delay switches = InPort( LPT1_IN ) & 0xF0; //puts the switch bits into switches; masks the lower 4 bits system("CLS"); timeDate(); swShow(swSt); ledShow(leds); } break;
currently going through the above code segment figuring out what it does.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Interests:
- Computers, Video Games, Guitar, Drums
- Full Name:
- Samuel James Sloane
- Programming Languages:
-
A bit of java
Some C
Contact Information
- E-mail:
- Private
Friends
Le Messe Noir hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
Le Messe Noir has no profile comments yet. Why not say hello?