Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<stdlib.h>
- #include<DAQlib.h>
- #include<Windows.h>
- #define TRUE 1
- #define False 0
- #define RUN_SWITCH 1
- #define RESET_SWITCH 0
- #define ONE_SECOND 1000
- #define NUM_DISPLAYS 8
- #define TURNOFF 0
- //Function Prototypes
- void writeNumber(int number);
- void writeDigit(int digit, int position);
- void runCounter(int startVal, int endVal);
- int main(void) {
- int setupNUM;
- int startVAL;
- int endVAL;
- printf("Please enter 4 for the simulator: ");
- scanf("%d", &setupNUM);
- if (setupDAQ(setupNUM) == TRUE) {
- while (continueSuperLoop() == TRUE) {
- printf("Please enter a starting value: ");
- scanf("%d", &startVAL);
- printf("Please enter an ending value: ");
- scanf("%d", &endVAL);
- while (digitalRead(RESET_SWITCH) || digitalRead(RUN_SWITCH) == TRUE) {
- printf("Both switches must be set to off to proceed.");
- }
- writeNumber(startVAL);
- runCounter(startVAL, endVAL);
- }
- }
- }
- void runCounter(int startVal, int endVal) {
- while (continueSuperLoop() == TRUE) {
- while (digitalRead(RESET_SWITCH) && digitalRead(RUN_SWITCH) == FALSE) {
- for (startVal; startVal <= endVal; startVal++) {
- writeNumber(startVal);
- Sleep(ONE_SECOND);
- }
- }
- }
- }
- void writeNumber(int number) {
- int pos = 0;
- int digit;
- do {
- digit = number % 10;
- number = number / 10;
- writeDigit(digit, pos);
- } while (pos < NUM_DISPLAYS && number != 0);
- while (pos < NUM_DISPLAYS) {
- displayWrite(TURNOFF, pos);
- pos++;
- }
- }
- void writeDigit(int digit, int position) {
- static int digitsTable[10] = { 252,96,218,242,102,182,190,224,254,256 };
- displayWrite(digitsTable[digit], position);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement