Ejemplo n.º 1
0
Archivo: LCD.c Proyecto: pdxfrog/ECE372
void testLCD(){
    clearLCD();
    moveCursorLCD(0,0);
    printStringLCD(" DUNCAN  JULIAN ");
    moveCursorLCD(0,1);
    printStringLCD(" KYLE    SULTAN ");
}
Ejemplo n.º 2
0
/*
 * The printTime() function takes a time value in milliseconds and a header value 
 * and prints the time and the header to the LCD.
 */
void printTime(int totalTime, char header){
    int mins = totalTime/60000;
    int mins_tens = mins/10;
    int secs = 0;
    int secs_tens = 0;
    int ms = 0;
    int ms_tens = 0;
    totalTime = totalTime - mins*60000;
    secs = totalTime/1000;
    secs_tens = secs/10;
    totalTime = totalTime - secs*1000;
    ms = totalTime/10;
    ms_tens = ms/10;
    
    if(header == RUNNING_CONST) {
        moveCursorLCD(0, 4);
        printStringLCD("Running:");
    }
    else {
        moveCursorLCD(0, 4);
        printStringLCD("Stopped:");
    }
    
    moveCursorLCD(1,4);
    printCharLCD(mins_tens|(0b00110000));
    printCharLCD((mins%10)|(0b00110000));
    printCharLCD(':');
    printCharLCD(secs_tens|(0b00110000));
    printCharLCD((secs%10)|(0b00110000));
    printCharLCD(':');
    printCharLCD(ms_tens|(0b00110000));
    printCharLCD((ms%10)|(0b00110000));
    
}
Ejemplo n.º 3
0
Archivo: ir.c Proyecto: ECE372FA15/Team
void printIRStateCode(irStateType data) {

    // table is not filled out all of the way...
    //IDK what to do for some of it 
    switch (data) {
        case findLine: // turn in circles until line is found 
            printStringLCD("FL ");
            return;
        case turnLeft: // turn left
            printStringLCD("TL ");
            return;
        case turnRight: // turn right 
            printStringLCD("TR ");
            return;
        case goFwd: // go forward 
            printStringLCD("FWD");
            return;
        case goBck: // fo backward 
            printStringLCD("BCK");
            return;
        case maintainSetting: // keep previous states speed setting 
            printStringLCD("MS ");
            return;
        case motorPiviotLeft_:
            printStringLCD("PL ");
            return;
        case motorPiviotRight_:
            printStringLCD("PR ");
            return;
        case stop: // stop! 
            printStringLCD("S! ");
            return;
    }
    return;
};
Ejemplo n.º 4
0
/*
 * This function is called in lab1p2.c for testing purposes.
 * If everything is working properly, you should get this to look like the video on D2L
 * However, it is suggested that you test more than just this one function.
 */
void testLCD(){
    initLCD();
    int i = 0;
    printCharLCD('c');
    for(i = 0; i < 1000; i++) delayUs(1000);
    clearLCD();
    printStringLCD("Hello!");
    moveCursorLCD(1, 2);
    for(i = 0; i < 1000; i++) delayUs(1000);
    printStringLCD("Hello!");
    for(i = 0; i < 1000; i++) delayUs(1000);
}
Ejemplo n.º 5
0
Archivo: ir.c Proyecto: ECE372FA15/Team
 //**************REMOVE?****************
void testIR() {
#ifdef use_digital_ir
    printIR();
#endif
    moveCursorLCD(1, 2);
    printStringLCD("testing");

}
Ejemplo n.º 6
0
Archivo: LCD.c Proyecto: pdxfrog/ECE372
void printTimeLCD(int time){
    char timeString[9] = {"\0"};
    int mm = time/6000; // integer division for the win
    int ss = (time%6000)/100;         
    int nn = time%100;
    moveCursorLCD(0,1);
    sprintf(timeString, "%02d:%02d:%02d", mm,ss,nn);
    printStringLCD(timeString); 
}
Ejemplo n.º 7
0
Archivo: ir.c Proyecto: ECE372FA15/Team
void analogPrintIR(int irData) {
    // gather data from ports 
    // may need to swap port1-2-3-4 function inupts with global definitions...


    ////////    printIRStateCode(lastTrackLineState);
    ////////    printCharLCD(' ');
    ////////
    ////////    printCharLCD(((irData & 128) >> 7) + '0');
    ////////    printCharLCD(((irData & 64) >> 6) + '0');
    ////////    printCharLCD(((irData & 32) >> 5) + '0');
    ////////
    ////////    moveCursorLCD(1, 1);
    ////////    printStringLCD("   ");
    ////////    printCharLCD(((irData & 16) >> 4) + '0');
    ////////
    ////////    printCharLCD(((irData & 4) >> 2) + '0');
    ////////    printCharLCD(((irData & 2) >> 1) + '0');
    ////////    printCharLCD(((irData & 1) >> 0) + '0');
    ////////
    ////////    printCharLCD(((irData & 8) >> 3) + '0');

    

    clearLCD();

    printIRStateCode(lastTrackLineState);
    printCharLCD(' ');

        
////////  printCharLCD(((irData % 100000000) / 10000000) + '0'); // print eight digit
////////    printCharLCD(((irData % 10000000) / 1000000) + '0'); // print seventh digit
////////    printCharLCD(((irData % 1000000) / 100000) + '0'); // print sixth digit
////////    moveCursorLCD(1, 1);
////////    printStringLCD("   ");
////////    
////////    
////////    printCharLCD(((irData % 100000) / 10000) + '0'); // print fifth digit
////////    printCharLCD(((irData % 10000) / 1000) + '0'); // print fourth digit
////////     printCharLCD(((irData % 100) / 10) + '0'); // print second digit 
////////    printCharLCD((irData % 10) + '0'); // print first digit 
////////    printCharLCD(((irData % 1000) / 100) + '0'); // print fourth digit
////////   
      printCharLCD(((irData % 100) / 10) + '0'); // print second digit 
   printCharLCD(((irData % 100000000) / 10000000) + '0'); // print eight digit 
      printCharLCD(((irData % 100000) / 10000) + '0'); // print fifth digit
     moveCursorLCD(1, 1);
    printStringLCD("   ");
    printCharLCD(((irData % 10000) / 1000) + '0'); // print fourth digit 
    printCharLCD(((irData % 1000000) / 100000) + '0'); // print sixth digit 
    printCharLCD((irData % 10) + '0'); // print first digit 
        printCharLCD(((irData % 10000000) / 1000000) + '0'); // print seventh digit
            printCharLCD(((irData % 1000) / 100) + '0'); // print fourth digit
            
            return;
}
Ejemplo n.º 8
0
Archivo: ir.c Proyecto: ECE372FA15/Team
void testMotorAndIR() {

    int data = 0;
    data = readIR();
    clearLCD();

    if (data == 0b1111) {
        setMotorsBackward(100);
        printStringLCD("backward");
        //setMotorsSweepForward(1023);
    } else if (data == 0) {
        setMotorsForward(100);
        printStringLCD("forward");
    }

    moveCursorLCD(1, 1);
    printCharLCD((((data & 8) >> 3) + '0'));
    printCharLCD((((data & 4) >> 2) + '0'));
    printCharLCD((((data & 2) >> 1) + '0'));
    printCharLCD((((data & 1) >> 0) + '0'));


}
Ejemplo n.º 9
0
void getAnalogVoltage (unsigned int val)
{
    unsigned char F1;
    unsigned char F10;
    unsigned char S1;
    unsigned char S10;
    unsigned char analogVoltage[5];
    
    
    
    
    
    //Set the 1's term
    F1 = val % 1;
    //Removes the 1's term and divides by ten
    val = (val - val%10)/10;
    //Set the 10's term
    F10 = val % 10;
    //Removes the 10's term and divides by ten
    val = (val - val%10)/10;
    //Set the 100's term
    S1 = val % 10;
    //Removes the 100's term and divides by ten
    val = (val - val%10)/10;
    //Set the 1000's term
    S10 = val%10;
    /*
    F1 = '1';
    F10 = '0';
    S1 = '2';
    S10 = '3';
    */
    
    
    analogVoltage[0] = F1;
    analogVoltage[1] = F10;
    analogVoltage[2] = S1;
    analogVoltage[3] = S10;
    analogVoltage[4] = '\0';
    
    printStringLCD(analogVoltage);
    //printStringLCD("1234");
}
Ejemplo n.º 10
0
void LCDprintInt(int x)
{
    char buffer[8];
    sprintf(buffer, "%d", x);
    printStringLCD(buffer);
}
Ejemplo n.º 11
0
int main(void)
{
    SYSTEMConfigPerformance(10000000);
    enableInterrupts();
   initTimer2();
   initKeypad();
   initLCD();
   
    char password1[5] = {'a','a','a','a','\0'}; //2D array of passwords 
 char password2[5] = {'a','a','a','a','\0'};
 char password3[5] = {'a','a','a','a','\0'};
 char password4[5] = {'a','a','a','a','\0'};
 char tempPassword[5] = {'\0','\0','\0','\0','\0'}; //password being entered

 char keyPressed = 'f';
 int row = 1;
 int position = 0; 
 int counter = 1;
 int numPasswords = 0; //number of passwords 
 int i =0; 
 int j =0;
 int set = 0; 
 
   //TRISA.RA7
   TRISAbits.TRISA7 = 0;
   
   //TRISCbits.TRISC4 = 0;
    while(1)
    {
       
        
        switch(state){
            
            case Wait: 
                            
                if( set == 1){
//                moveCursorLCD(1,1); //first line 
//                printStringLCD("Set Mode");
                }              
                else {
                    
                moveCursorLCD(1,1); //first line 
                printStringLCD("Enter"); 
                }
                
               
                break;
                
            case Wait2:
                
                
                if((PORTBbits.RB10 == 1) && (PORTBbits.RB12 == 1) && (PORTBbits.RB14 == 1) ) { //waits for button release
         
                   
                state = DeBounceRelease;
                break;
                }
                
                else state = Wait2;
                break;
                
            case DeBounce: 
                 
                //moveCursorLCD(1,1); //first line 
                //printStringLCD("DeBounce State");
                
                delayUs(500);
                state = SearchKeypad;
                
                break;
                
            case DeBounceRelease: 
                 
                //moveCursorLCD(1,1); //first line 
                //printStringLCD("DeBounce State");
                
                delayUs(500);
               // moveCursorLCD(1,2); //first line 
               // printStringLCD("Button Released");
                state = EnterPassword;
                //IEC1bits.CNBIE = ON;
                break;
                
            case Set:
                moveCursorLCD(1,1); //first line 
                printStringLCD("Set Mode");
                
                moveCursorLCD(1,2); // clears second line 
                    clearLCD;
                set = 1; 
                state = Wait; 
                
                break; 
                
            case EnterPassword:
                
                                                
                if(i == 4){
                    i = 0;
                                        
                }
               tempPassword[i] =  keyPressed;
               i = i + 1;
               
               if( i == 2){
                        
                        //if((passwords[0][numPasswords] == '*') && (passwords[1][numPasswords] == '*')) {
                         if((tempPassword[0] == '*') && (tempPassword[1] == '*')) {   
                            i = 0;
                            state = Set;
                        } 
                    }
               
               state = WriteLCD;
                break;
                
              case CheckNewPassword:
                        
                for(j = 0; j < 4; j++){ //checks all stored passwords 
                    
                    if ((tempPassword[j] == '*') || (tempPassword[j] == '#')){
                        moveCursorLCD(1,1); //first line 
                        printStringLCD("Invalid"); //print valid
                        delayUs(2000000);
                        moveCursorLCD(1,2); // clears second line 
                        clearLCD;
                        set = 0;
                        state = Wait;
                 
                        }
                }
                
                
                    moveCursorLCD(1,1); //first line 
                    printStringLCD("Valid"); //print invalid
                    delayUs(2000000);
                    moveCursorLCD(1,2); // clears second line 
                    clearLCD;
                    
                    numPasswords = numPasswords +1;
                    
                      if(numPasswords == 4){
                        numPasswords = 0;
                    }
                    
                    if(numPasswords == 0){
                        
                        for(j =0; j < 5; j++){
                            password1[j] = tempPassword[j];
                        }
                    }
                    
                    else if(numPasswords == 1){
                        
                        for(j =0; j < 5; j++){
                            password2[j] = tempPassword[j];
                        }
                    }
                    
                    else if(numPasswords == 2){
                        
                        for(j =0; j < 5; j++){
                            password3[j] = tempPassword[j];
                        }
                    }
                    
                    else if(numPasswords = 3){
                        
                        for(j =0; j < 5; j++){
                            password4[j] = tempPassword[j];
                        }
                    }
                    set = 0;
                    
                    state = Wait;
                
                    
                        
                        
                break;
                
            case CheckPassword:
                        
                                  
                    if (strcmp(password1, tempPassword) == 0){
                        moveCursorLCD(1,1); //first line 
                        printStringLCD("Good"); //print valid
                        delayUs(20000);
                        moveCursorLCD(1,2); // clears second line 
                        clearLCD;
                 
                        state = Wait;
                 
                        }
                     if (strcmp(password2, tempPassword) == 0){
                        moveCursorLCD(1,1); //first line 
                        printStringLCD("Good"); //print valid
                        delayUs(20000);
                        moveCursorLCD(1,2); // clears second line 
                        clearLCD;
                 
                        state = Wait;
                 
                        }
                    
                     if (strcmp(password3, tempPassword) == 0){
                        moveCursorLCD(1,1); //first line 
                        printStringLCD("Good"); //print valid
                        delayUs(20000);
                        moveCursorLCD(1,2); // clears second line 
                        clearLCD;
                 
                        state = Wait;
                 
                        }
                    
                     if (strcmp(password4, tempPassword) == 0){
                        moveCursorLCD(1,1); //first line 
                        printStringLCD("Good"); //print valid
                        delayUs(20000);
                        moveCursorLCD(1,2); // clears second line 
                        clearLCD;
                 
                        state = Wait;
                 
                        }
                
                
                
                    moveCursorLCD(1,1); //first line 
                    printStringLCD("Bad"); //print invalid
                    delayUs(20000);
                    moveCursorLCD(1,2); // clears second line 
                    clearLCD;
                    
                    
                    state = Wait;
                
                    
                        
                        
                break;
                        
            case SearchKeypad: 
                
                //moveCursorLCD(1,1); //first line 
                //printStringLCD("Search Keypad");
                //delayUs(5000);
                
              //  IEC1bits.CNBIE = OFF;// turn off ISR 
                
                CNCONBbits.ON = 0; //turn change notifications off 
                
                LATEbits.LATE0 = 1;// open drain collector for outputs
                LATEbits.LATE2 = 1;
                LATEbits.LATE4 = 1;
                LATEbits.LATE6 = 1;
                
                keyPressed = scanKeypad();
                
                LATEbits.LATE0 = 0;// open drain collector for outputs
                LATEbits.LATE2 = 0;
                LATEbits.LATE4 = 0;
                LATEbits.LATE6 = 0;
                
                CNCONBbits.ON = 1; // CN on 
                
               state = Wait2;
               //state = WriteLCD;
                break;
                
            case WriteLCD: 
                
                if (counter == 9){
//                    row = ~row;
                    counter = 1;
                }
                
                moveCursorLCD(counter,2);
                  delayUs(2000);
                printCharLCD(keyPressed);
                delayUs(200);
                counter = counter + 1;
                  
                if(i == 3){
                    
                    if(set == 1){
                        state = CheckNewPassword;
                    }
                    state = CheckPassword;
                }
                        state = Wait; 
                
               //IEC1bits.CNBIE = ON;
                break;
            
            
            
        }
    }
    
    return 0;
}
Ejemplo n.º 12
0
int main(void) {
    SYSTEMConfigPerformance(10000000);
    enableInterrupts();
    initTimerDebounce();
    initTimerDelay();
    initLCD();
    initKeypad();

    int runQATests = NTEST; //test keypad software functions if TEST, don't if NTEST
    if(runQATests == TEST) {
        test_clearString();
        delayUs(2000000);
        clearLCD();
        test_checkPass();
        delayUs(2000000);
        clearLCD();
        test_updatePass();
        return -1;
    }

    char key = NULL;
    char passStringa[5] = "";
    char passStringb[5] = "";
    char passStringc[5] = "";
    char passStringd[5] = "";
    int PassCount = 0;
    int correct = NOTMATCH;
    char tempPass[5] = "";
    char guessString[5] = "";
    moveCursorLCD(0,0);

    while(1) {
        switch(state) {
        case enter:
            if(mode != ENTER || prevState != enter) {
                clearLCD();
                printStringLCD("Enter");
                moveCursorLCD(1,0);
                mode = ENTER;
            }
            prevState = enter;
            break;
        case debounce:
            break;
        case update:
            if(row != -1) {
                key = scanKeypad(row);
            }
            else {
                break;
            }
            if(key != -1) {
                printCharLCD(key);
                if(mode == ENTER) {
                    guessString[keyPresses] = key;//append key to guessString
                    state = enter;
                }
                else if(mode == SET) {
                    tempPass[keyPresses] = key;//append key to passString
                    state = set_mode;
                }
                keyPresses = keyPresses + 1;
                if(mode == ENTER) {
                    correct = NOTMATCH;
                    correct = checkPass(guessString, passStringa, passStringb, passStringc, passStringd);
                    if(keyPresses == 4 && (correct == NOTMATCH)) {
                        state = bad;
                    }
                    else if(key == '#') {
                        state = bad;
                    }
                    else if((keyPresses > 1) && (keyPresses < 4) && (key == '*') && (strcmp(guessString, "**")!=0)) {
                        state = bad;
                    }
                    else if((keyPresses==2)&&(strcmp(guessString,"**")==0)) {
                        state = set_mode;
                    }
                    else if((keyPresses==2) && (key!='*')&&(guessString[0]=='*')) {
                        state = bad;
                    }
                    else if((keyPresses==4)&&(correct == 0)) {
                        state = good;
                    }
                }
                else if((keyPresses<4)&&(mode==SET)&&(key!='#')&&(key!='*')) {
                    state = set_mode;
                }
                else if(((key=='#')||(key=='*'))&&(mode==SET)) {
                    state = invalid;
                }
                else if((mode==SET)&&(keyPresses==4)&&(key!='#')&&(key!='*')) {
                    state = valid;
                }
                else if(keyPresses < 4 && mode == ENTER && key != '#') state = enter;
            }
            else {
                printCharLCD(' ');
                moveCursorLCD(1, keyPresses);
                if(mode == ENTER) state = enter;
                else if(mode == SET) state = set_mode;
            }
            key = NULL;
            break;
        case set_mode:
            if(mode != SET || prevState != set_mode) {
                clearLCD();
                printStringLCD("Set Mode");
                moveCursorLCD(1,0);
                keyPresses = 0;
                strcpy(guessString, "");
                clearString(guessString);
                mode = SET;
            }
            prevState = set_mode;
            break;
        case good:
            clearLCD();
            printStringLCD("Good");
            keyPresses = 0;
            clearString(guessString);
            state = enter;
            prevState = good;
            delayUs(2000000);
            break;
        case bad:
            clearLCD();
            printStringLCD("Bad");
            keyPresses = 0;
            clearString(guessString);
            state = enter;
            prevState = bad;
            delayUs(2000000);
            break;
        case valid:
            clearLCD();
            if(PassCount == 3) {
                PassCount = 0;
            }
            else PassCount = PassCount + 1;
            updatePass(tempPass, passStringa, passStringb, passStringc, passStringd, PassCount);
            printStringLCD("Valid");
            keyPresses = 0;
            clearString(tempPass);
            mode = ENTER;
            state = enter;
            prevState = valid;
            delayUs(2000000);
            break;
        case invalid:
            clearLCD();
            printStringLCD("Invalid");
            keyPresses = 0;
            clearString(tempPass);
            mode = ENTER;
            state = enter;
            prevState = invalid;
            delayUs(2000000);
            break;
        }
    }
    return 0;
}
Ejemplo n.º 13
0
Archivo: lcd.c Proyecto: rtfi/final
void printTime(char* time){
    moveCursorLCD(1,0);
    printStringLCD(time);
}
Ejemplo n.º 14
0
int main(void){
    SYSTEMConfigPerformance(10000000);
    enableInterrupts();
    initTimer1();
    initTimer2();
    initTimer45();
    initSW1();
    initLCD();
    initPWM();
    initADC();
    
    setMotorDirection(M1, 1); 
    setMotorDirection(M2, 1);
    while(1){      //Lab3 Part1
       switch(state){
            case forward:
                prevstate = forward; 
                ADCbuffer = getADCbuffer();
                if((dispVolt < ADCbuffer) && ((dispVolt + 1) <= ADCbuffer)){//to reduce excessive LCD updates
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                else if((dispVolt > ADCbuffer) && ((dispVolt - 1) >= ADCbuffer)){
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                moveCursorLCD(1,0);
                printStringLCD("forward ");
                if(remap == 1){
                    setMotorDirection(M1,1);
                    setMotorDirection(M2,1);
                    delayUs(1000);
                    remap = 0;
                }
                setMotorSpeed(ADCbuffer, direction);
                break;

            case backward:
                prevstate = backward;
                ADCbuffer = getADCbuffer();
                if((dispVolt < ADCbuffer) && ((dispVolt + 1) <= ADCbuffer)){//to reduce excessive LCD updates
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                else if((dispVolt > ADCbuffer) && ((dispVolt - 1) >= ADCbuffer)){
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                moveCursorLCD(1,0);
                printStringLCD("backward");
                if(remap == 1){
                    setMotorDirection(M1,0);
                    setMotorDirection(M2,0);
                    delayUs(1000);
                    remap = 0;
                }
                setMotorSpeed(ADCbuffer, direction);
                break;           

            case idle:
                unmapPins();
                ADCbuffer = getADCbuffer();
                if((dispVolt < ADCbuffer) && ((dispVolt + 1) <= ADCbuffer)){//to reduce excessive LCD updates
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                else if((dispVolt > ADCbuffer) && ((dispVolt - 1) >= ADCbuffer)){
                    printVoltage(ADCbuffer);
                    dispVolt = ADCbuffer;
                }
                moveCursorLCD(1,0);
                printStringLCD("Idle    ");
                delayUs(1000);
                break;
        }     
    }  
    return 0;
}
Ejemplo n.º 15
0
Archivo: lcd.c Proyecto: rtfi/final
void printStopped(){
    moveCursorLCD(0,0);
    printStringLCD("STOPPED");
}
Ejemplo n.º 16
0
int main() {
    SYSTEMConfigPerformance(10000000); //Does something with assembly to set clock speed
    enableInterrupts(); //Make interrupt work

    initLEDs();
    initTimer1();
    initTimer2();
    initTimer3();
    initTimer4();
    initSwitch();
    
    
    porta = PORTA;
    portd = PORTD;
    
    initLCD();
    delay(500);
    //printCharLCD(0);
    testLCD();
    
    state = InitState;
    nextState = InitState;

    while (1) {
        switch (state) {
            case RUN:
#ifdef _DEBUG_
                  LATDbits.LATD0=0;
                  LATDbits.LATD1=0;
                  LATDbits.LATD2=1;
#endif
                  LATGbits.LATG14=LedOFF; //TRD1
                  LATGbits.LATG12=LedON; //TRD2
                  moveCursorLCD(0,0);
                  printStringLCD("Running...");
                  if(counterCN==1){   // If the counter changed...
                      printTimeLCD(counter);
                      counterCN = 0;
                  }
                  if(AllowChange == 0){
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      AllowChange = 1;
                  }
                  if((ReqChange==1) && (AllowChange==1)){
                      state=WAIT1;
                      ReqChange=0;
                      AllowChange=0;  
                    //  CNCONAbits.ON = 1;
                  }
                  break;
                  
              case STOP:
#ifdef _DEBUG_
                  LATDbits.LATD0=1;
                  LATDbits.LATD1=0;
                  LATDbits.LATD2=0;
#endif
                  LATGbits.LATG14=LedON;
                  LATGbits.LATG12=LedOFF;
                  moveCursorLCD(0,0);
                  printStringLCD("Stopped");
                  if(AllowChange == 0){
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      AllowChange = 1;
                  }
                  if(AllowReset == 0){
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      AllowReset = 1;
                  }
                  if((ReqReset==1) && (AllowReset==1)){
                      AllowReset = 0;
                      ReqReset = 0;
                      counter = 0;
                      printTimeLCD(counter);
                  }
                  if((ReqChange==1) && (AllowChange==1)){
                      state=WAIT2;
                      ReqChange=0;
                      AllowChange=0;
                     // CNCONAbits.ON = 1;
                  }
                  break;
                  
              case WAIT1:
#ifdef _DEBUG_
                  LATDbits.LATD0=0;
                  LATDbits.LATD1=1;
                  LATDbits.LATD2=1;
#endif
                  T1CONbits.ON = 0; // Turn off counter
                  if(AllowChange == 0){
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      AllowChange = 1;
                  }
                  if((ReqChange==1) && (AllowChange==1)){
                      state=STOP;
                      ReqChange=0;
                      AllowChange=0;
                      ReqReset = 0; // So we don't reset as soon as we stop...
                      AllowReset = 0;   // See previous line
                     // CNCONAbits.ON = 1;
                  }
                  
                  break;
              case WAIT2:
#ifdef _DEBUG_
                  LATDbits.LATD0=1;
                  LATDbits.LATD1=1;
                  LATDbits.LATD2=0;
#endif
                  T1CONbits.ON = 1; // Turn on counter
                  if(AllowChange == 0){
                      delay(5000);// The sad part is this didn't even work.
                      delay(5000);
                      delay(5000);
                      delay(5000);
                      AllowChange = 1;
                  }
                  if((ReqChange==1) && (AllowChange==1)){   // Button Changed and De-bouncing period is done
                      state=RUN;
                      ReqChange=0;
                      AllowChange=0;
                      //CNCONAbits.ON = 1;
                  }
                  break;
              
              case InitState:// Only happens once
                   state=STOP;
                   clearLCD();
                   counter = 0;
                   printTimeLCD(counter);
                   T1CONbits.ON = 0;
                   TMR1 = 0;

                  break;
              default:// Should never happen. How did you get here?
                   state=InitState;
                   ReqChange = 0;
                   AllowChange=0;
                  break;
        }
    }
    return 0;
}
Ejemplo n.º 17
0
int main(void) {

    char passWord[passwords][wordLen]; //[nump][lenp]; 
    char temp[wordLen]; //string to hold characters as they are typed in
    int pwItt = 0; //index of the password being typed in by user 
    int pwStoreIndex = 0; //index for string# in passWord[][] array
    //index is used to add pws to passWord[][]

    int numCharsPrinted = 0; // counter to keep things tidy on the display 
    int modeStateEnable = 0; // enables the second state machine 
    int i = 0, j = 0;
    int match = 0;
    int count = 0;
    ANSELE = 0;
    SYSTEMConfigPerformance(40000000);
    initLCD();
    clearLCD();
    writeLCD(0b00001111, 0, 50);
    initTimer1();
    initKeypad();
    enableInterrupts();
    clearBuff(wordLen, temp);
    //initialize temp to NULL
    for (i = 0; i < wordLen; i++) {
        temp [i] = NULL;
    }
    //initialize passcode array to NULL
    for (i = 0; i < passwords; i++) {
        for (j = 0; j < wordLen; j++) {
            passWord[i][j] = NULL;
        }
    }

#ifdef TEST2
    int flag = 0;

    //Precode 2 passwords into password array and test if working

    for (i = 0; i < 2; i++) {
        for (j = 0; j < wordLen-3; j++) {
            if (flag == 0) {
                passWord[i][j] = '0'+j;
            } else {
                passWord[i][j] = '0'+j + 1;
            }
        }
        flag++;
        passWord[i][j] = '\0';
    }

#endif
    
    // initialize the state machine output 
    printStringLCD("Enter");

#ifdef run  
    while (1) {

        //<><><><>  button de bounce stuff  <><><><><><><><><><><><><><><><><><><><><><>        
        switch (state) {
            case printKey:
                modeStateEnable = 1;
                temp[pwItt] = keyScanned;
                pwItt++;
                state = waitForRelease;
                break;

            case scanKey:
                keyScanned = scanKeypad();
                state = printKey;
                break;

            case dbPress:
                delayUs(DBDelayTime);
                state = scanKey;
                break;

            case dbRelease:
                delayUs(DBDelayTime);
                state = waitForPress;
                break;

            case waitForPress:
                //enableInterrupts();
                break;

            case waitForRelease:
                // enableInterrupts(); 
                break;
        }
        //<><><><> END button de bounce stuff  <><><><><><><><><><><><><><><><><><><><><><>  

        //!!! TODO !!! every exit branch of the state machine WILL:
        //        enable/disable interrupts
        //        set the next state (even if it does not change)
        //        set modeStateEnable to 1 or 0

        //    THIS will help with debugging  

        //<><><><>  Mode setting state machine <><><><><><><><><><><><><><><><><><><><><><>       
        if (modeStateEnable == 1) { // need to ensure this is correct...
            disableInterrupts(); //messing with printing?
            modeStateEnable = 0; //wait for key input
            // the newKeyPressed variable gets changed to 1 everytime a key press is detected    
            switch (modeState) {
                case firstStar: //interrupts are ENABLED DELETEME
                    if (temp[1] == '*') {
                        modeState = set; // the state that allows you to add pws 
                        modeStateEnable = 0; //wait for new key to be pressed
                        clearLCD();
                        printStringLCD("Set Mode");
                        moveCursorLCD(2, 1);
                        enableInterrupts();
                    } else {
                        modeState = dispBad;
                        modeStateEnable = 1; //goto state
                        disableInterrupts();
                    }
                    break;

                case dispGood: //interrupts are DISABLED DELETEME
                    printOutput("Good");
                    clearLCD();
                    printStringLCD("Enter"); //prompt enter state
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeState = dispEnter; //switch state
                    modeStateEnable = 0; //wait for new key to be pressed
                    enableInterrupts();
                    break;

                case dispBad: //interrupts are DISABLED DELETEME
                    printOutput("Bad");
                    clearLCD();
                    printStringLCD("Enter"); // prompt enter state
                    modeState = dispEnter; // switch state
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeStateEnable = 0; // wait for new key to be pressed
                    enableInterrupts();
                    break;

                case dispEnter: //interrupts are DISABLED DELETEME
                    clearLCD();
                    printStringLCD("Enter");
                    moveCursorLCD(2, 1);
                    printStringLCD(temp); // print the characters as they are entered 
                    if (pwItt == 4) {


                        if (checkValid(temp, passWord) == 0) {
                            //if( match == 0){ 
                            modeState = dispBad; // 0 means invalid pw
                            modeStateEnable = 1; //goto state
                            disableInterrupts();
                        } else {
                            modeState = dispGood; //1 means valid pw
                            modeStateEnable = 1; //goto state
                            disableInterrupts();
                            printCharLCD('&');
                        }
                    } else if (temp[0] == '*') {
                        modeState = firstStar;
                        modeStateEnable = 0; //wait for new key to be pressed 
                        enableInterrupts();
                    } else if (temp[0] == '#') {
                        modeState = dispBad;
                        modeStateEnable = 1; //continue
                        disableInterrupts();
                    } else {
                        modeState = dispEnter;
                        modeStateEnable = 0; //wait for new key to be pressed 
                        enableInterrupts();
                    }

                    break;
                case dispValid://-
                    printOutput("Valid   ");
                    clearLCD();
                    printStringLCD("Enter");

                    if (addNewPw(temp, passWord) == 0) { // if password is not in list 
                        //if(match == 0){           // if password is not in list 
                        strcpy(passWord[pwStoreIndex], temp); // add it
                        pwStoreIndex++; // increment itterator 
                    }
                    modeState = dispEnter;
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator
                    modeStateEnable = 0; //wait for new key to be pressed 
                    enableInterrupts();
                    break;

                case dispInvalid://-
                    printOutput("Invalid ");
                    clearLCD();
                    printStringLCD("Enter");
                    modeState = dispEnter;
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeStateEnable = 0; //wait for new key to be pressed 
                    enableInterrupts();
                    break;

                case set:

                    printCharLCD(keyScanned); // might work better to press key pressed 
                    if (keyScanned == '*' || keyScanned == '#') { // if an invalid key was entered 
                        modeState = dispInvalid; // if new pw is not valid 
                        modeStateEnable = 1; //next state needs to be executed
                        disableInterrupts();
                    } else if (pwItt == 6) { // pw == "**xxxx"...
                        temp[0] = temp[2];
                        temp[1] = temp[3]; // remove leading "**" 
                        temp[2] = temp[4];
                        temp[3] = temp[5];
                        temp[4] = NULL;
                        temp[5] = NULL;

                        modeState = dispValid;
                        modeStateEnable = 1; //next state needs to be executed
                        disableInterrupts();
                    } else {
                        modeStateEnable = 0; //next state needs to be executed
                        enableInterrupts();
                    }

                    break;
            }
        }
        //<><><><> END Mode setting state machine <><><><><><><><><><><><><><><><><><><><><><>   

    }

    return 0;
}
Ejemplo n.º 18
0
Archivo: ir.c Proyecto: ECE372FA15/Team
int trackLine(int i) {

    irStateType nextState = maintainSetting;
    //increased motor speed from 85 to 100
    int motorSpeed = 90; // full speed ahead!!
    int secondMotorSpeed = 515;
    char str[6] = {0, 0, 0, 0, 0, 0};
    int irData = 0;

    // possible irData values 0-15

    switch (trackLineState) {
            // motor movement definitions are in pwm .h and .c files 
        case findLine: // turn in circles until line is found 
            motorFindLine(motorSpeed);
            lastTrackLineState = findLine;
            trackLineState = maintainSetting;
            break;
        case turnLeft: // turn left
            setMotorsLeft(motorSpeed);
            lastTrackLineState = turnLeft;
            trackLineState = maintainSetting;
            break;
        case turnRight: // turn right 
            setMotorsRight(motorSpeed);
            lastTrackLineState = turnRight;
            trackLineState = maintainSetting;
            break;
        case goFwd: // go forward 
            setMotorsForward(motorSpeed);
            lastTrackLineState = goFwd;
            trackLineState = maintainSetting;
            break;
        case goBck: // go backward
            setMotorsBackward(motorSpeed);
            lastTrackLineState = goBck;
            trackLineState = maintainSetting;
            break;
        case stop: // stop! 
            setMotorsIdle();
            lastTrackLineState = stop;
            trackLineState = maintainSetting;
            break;
        case maintainSetting:
            // check the ir data 
#ifdef use_digital_ir
            irData = readNewIR(); // changed from readIR()
            nextState = parseIRData(irData);
#endif
#ifdef use_analog_ir
            irData = analogReadIR();
           // nextState = parseNewIRData(irData);
            if(i == 0){
                nextState = turnLeft;
                delayUs(1000000);
            }
            else{
            nextState = turnRight;
            delayUs(5000000);
            }
#endif 
            // only change states if necessary 
            if (nextState != lastTrackLineState) {
                trackLineState = nextState;
                lastTrackLineState = maintainSetting;
            } else {
                trackLineState = maintainSetting;
            }
            break;

    }

    //****************REMOVE?***************
#ifdef debug_ir
    //clearLCD();

    // the following print Char statments output the state name as a 3 char
    // code ### and code info  ( as shown below )

    // ### 000
    //    00000

#ifdef use_digital_ir
    printIRStateCode(lastTrackLineState);
    printCharLCD(' ');

    printCharLCD(((irData & 128) >> 7) + '0');
    printCharLCD(((irData & 64) >> 6) + '0');
    printCharLCD(((irData & 32) >> 5) + '0');

    moveCursorLCD(1, 1);
    printStringLCD("   ");
    printCharLCD(((irData & 16) >> 4) + '0');

    printCharLCD(((irData & 4) >> 2) + '0');
    printCharLCD(((irData & 2) >> 1) + '0');
    printCharLCD(((irData & 1) >> 0) + '0');

    printCharLCD(((irData & 8) >> 3) + '0');

    //        printCharLCD(((trackLineState & 8) >> 3) + '0');
    //        printCharLCD(((trackLineState & 4) >> 2) + '0'); 
    //        printCharLCD(((trackLineState & 2) >> 1) + '0');
    //        printCharLCD(((trackLineState & 1) >> 0) + '0');

    //        printIR();
    //        printCharLCD(((lastTrackLineState & 8) >> 3) + '0');
    //        printCharLCD(((lastTrackLineState & 4) >> 2) + '0'); 
    //        printCharLCD(((lastTrackLineState & 2) >> 1) + '0');
    //        printCharLCD(((lastTrackLineState & 1) >> 0) + '0');

#endif

#endif

}
Ejemplo n.º 19
0
int main(void)
{
    SYSTEMConfigPerformance(40000000);
    initLCD(); //initialize the LCD
    enableInterrupts();
    initADC(); //initialize the ADC
    initPWM(); //initialize the PWM
    initTimer3(); //initialize the timer
    TRISDbits.TRISD0 = 0;
    LATDbits.LATD0 = 0;
    initUART(); //initialize UART
    
    sendByte('M');
    
   while(1)
   {
        if(U2STAbits.URXDA)
        {
            input = U2RXREG; //saves RX reg buffer
            sendByte(input); //echos pressed key back to prompt
            sendByte(':'); //sends : to terminal prompt
        }
       
        switch(input) {
            case 'w': //forward
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700;
                LW = 700; 
                break;
            case 'a': //left
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700; 
                LW = 100;
                break;
            case 's': //backward
                LEFTMOTORDIRECTION1 = 1; 
                LEFTMOTORDIRECTION2 = 0;         
                RIGHTMOTORDIRECTION1 = 1;
                RIGHTMOTORDIRECTION2 = 0;
                RW = 700; 
                LW = 700;               
                break;
            case 'd': //right
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 100; 
                LW = 700;                
                break;
            case 'p':
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 0;
                LW = 0; 
                break;
        }
        
        
       startRead(0); //starts reading from ADC (POT)
       adcVal0 = waitToFinish0(); //save digital value of pot
       
       startRead(1); //starts reading from ADC (Leftmost)
       adcVal1 = waitToFinish1(); //save digital value of leftmost phototransistor
       
       startRead(2); //starts reading from ADC (Middle)
       adcVal2 = waitToFinish2(); //save digital value of middle phototransistor
       
       startRead(3); //starts reading from ADC (Rightmost)
       adcVal3 = waitToFinish3(); //save digital value of rightmost phototransistor
       
       moveCursorLCD(0,2);
       sprintf(str, "%d,%d,%d", adcVal1/10, adcVal2/10, adcVal3/10);
       printStringLCD(str);
       
       scan(); //scan three transistors
       
       moveCursorLCD(0,1);
       sprintf(str, "%d, %d, %d", L1, L2, L3);
       printStringLCD(str);
       
       determineState();
       
       switch(jason)
       {
           case followLine_detectEnd:
               followLine();
               detectEnd();
               break;
           case turnAroundJason:
               turnAround();
               break;      
       }       
   }
    
    return 0;
}
Ejemplo n.º 20
0
int main(void)
{
    
    int i = 0;
    int c = 0;
    int r = 0;
    
    char pass1[5] = "0000";
    char pass2[5] = "0000";
    char pass3[5] = "0000";
    char pass4[5] = "0000";
    char passEntry[5] = "";
    
    enableInterrupts();                   //This function is necessary to use interrupts.
    initTimer2();
    initLCD();
    initKeypad();
    
    SYSTEMConfigPerformance(10000000);
    
    while(1){
        
        switch(state){
            case WAIT4PRESS:
                //INTERRUPT_E_PINS = _ON;
                delayUs(1000);
                KEYPAD_LAT_COL0 = ODC_CLOSED;
                KEYPAD_LAT_COL1 = ODC_CLOSED;
                KEYPAD_LAT_COL2 = ODC_CLOSED;
                if ((i == 4) && (set_mode == 0)){
                    if (!(strcmp(passEntry, pass1)) || !(strcmp(passEntry, pass2)) || !(strcmp(passEntry, pass3)) || !(strcmp(passEntry, pass4))){
                        state = GOOD; 
                    }
                    else{
                        state = BAD;
                    }
                }
                else if ((i == 4) && (set_mode == 1)){
                    j = 0;
                    for(j=0;j<4;j++){
                        if ((passEntry[j] == '*') || (passEntry[j] == '#')){
                            state = INVALID;
                            break;
                        }
                        else{
                            state = VALID;
                        }
                    }
                }
                else if ((i == 2) && (set_mode == 0)){
                    if ((passEntry[0] == '*') && (passEntry[1] == '*')){
                        i = 0;
                        set_mode = 1;
                        state = SETMODE;
                    }
                }
                if (i == 4) i = 0;
                break;
                
            case WAIT:
                KEYPAD_LAT_COL0 = ODC_OPEN;
                KEYPAD_LAT_COL1 = ODC_OPEN;
                KEYPAD_LAT_COL2 = ODC_OPEN;
                state = COL0;
                break;
                
            case WAIT4RELEASE:
                INTERRUPT_E_PINS = _ON;
                break;
                
            case COL0:
                KEYPAD_LAT_COL1 = ODC_OPEN;
                KEYPAD_LAT_COL2 = ODC_OPEN;
                KEYPAD_LAT_COL0 = ODC_CLOSED;
                delayUs(1000);
                //********************************
                returnedKey = scanKeypad(0);
                if (returnedKey != '!'){
                    delayUs(1000);
                    //printCharLCD(returnedKey);
                    //moveCursorLCD(1,0);
                    if (i > 3) i = 0;
                    passEntry[i] = returnedKey;
                    i = i + 1;
                    delayUs(1000);
                    state = WAIT4RELEASE;
                }
                else state = COL1;
                break;
                
            case COL1:
                KEYPAD_LAT_COL0 = ODC_OPEN;
                KEYPAD_LAT_COL2 = ODC_OPEN;
                KEYPAD_LAT_COL1 = ODC_CLOSED;
                delayUs(1000);
                //********************************
                returnedKey = scanKeypad(1);
                if (returnedKey != '!'){
                    delayUs(1000);
                    //printCharLCD(returnedKey);
                    //moveCursorLCD(1,0);
                    if (i > 3) i = 0;
                    passEntry[i] = returnedKey;
                    i = i + 1;
                    delayUs(1000);
                    state = WAIT4RELEASE;
                }
                else state = COL2;
                break;
                
            case COL2:
                KEYPAD_LAT_COL0 = ODC_OPEN;
                KEYPAD_LAT_COL1 = ODC_OPEN;
                KEYPAD_LAT_COL2 = ODC_CLOSED;
                delayUs(1000);
                //********************************
                returnedKey = scanKeypad(2);
                if (returnedKey != '!'){
                    delayUs(1000);
                    //printCharLCD(returnedKey);
                    //moveCursorLCD(1,0);
                    if (i > 3) i = 0;
                    passEntry[i] = returnedKey;
                    i = i + 1;
                    delayUs(1000);
                    state = WAIT4RELEASE;
                }
                //********************************
                state = WAIT4RELEASE;
                break;
                
            //************PART2************************************************
            case ENTER:
                printStringLCD("Enter");
                state = WAIT4PRESS;
                break;

            case SETMODE:
                clearLCD();
                delayUs(1000);
                printStringLCD("Set Mode");
                state = WAIT4PRESS;
                break;
            case SETMODE_ENTRY:
                break;
            case GOOD:
                clearLCD();
                printStringLCD("Good");
                j = 0;
                for(j=0;j<1000;j++) delayUs(1000);
                clearLCD();
                set_mode = 0;
                state = ENTER;
                break;
                
            case BAD:
                clearLCD();
                printStringLCD("Bad");
                j = 0;
                for(j=0;j<1000;j++) delayUs(1000);
                clearLCD();
                set_mode = 0;
                state = ENTER;
                break;
                
            case VALID:
                clearLCD();
                printStringLCD("Valid");
                j = 0;
                for(j=0;j<1000;j++) delayUs(1000);
                clearLCD();
                j = 0;
                if (c == 4) c = 0;
                c = c + 1;

                if (c == 1) strcpy(pass1,passEntry);
                if (c == 2) strcpy(pass2,passEntry);
                if (c == 3) strcpy(pass3,passEntry);
                if (c == 4) strcpy(pass4,passEntry);
                    
                set_mode = 0;
                state = ENTER;
                break;
                
            case INVALID:
                clearLCD();
                printStringLCD("Invalid");
                j = 0;
                for(j=0;j<1000;j++) delayUs(1000);
                clearLCD();
                set_mode = 0;
                state = ENTER;
                break;
        }
        
    }
    
    return 0;
}
Ejemplo n.º 21
0
Archivo: main.c Proyecto: Nathanh1/Lab2
int main(void)
{  
    initLCD();
    initKeypad();
    enableInterrupts();
    
    int counter = 1;
    char output = 'a';
    int count = 0;
    
    char p1[4]={'1','3','3','7'};//PRESET PASSWORD 1
    char p2[4];//PASSWORD 2
    char p3[4];//PASSWORD 3
    char p4[4];//PASSWORD 4
    
    char UserInput[4]; //USER INPUT ARRAY
    int i=0; //USER INPUT ARRAY ELEMENT
    
    int InSet = TURNOFF;
    int InEnter = TURNON;
    int GUESS1;
    int GUESS2;
    int GUESS3;
    int GUESS4;
    
    int StarCount=0;
    
    int PASSWORD2 = EMPTY;
    int PASSWORD3 = EMPTY;
    int PASSWORD4 = EMPTY;
    
    int USERINPUT= VALID; //for checking * or 
    
    while(1)
    {
        switch(state)
        {
            case  Enter_Mode:
                
                InSet = TURNOFF;
                InEnter = TURNON;             
                clearLCD();
                printStringLCD("Enter Code:");
                moveCursorLCD(0,2); //COL ROW
                count=0;
                StarCount=0;
            
                if(count == 4)
                {
                   count = 0;
                
                   for(i=0;i<4;i++)
                   {
                        if(p1[i]!=UserInput[i])
                        {
                            GUESS1=BAD;
                            break;
                        }
                        else
                        {
                            GUESS1=GOOD;
                        }
                    }
                    for(i=0;i<4;i++)
                    {
                        if(p2[i]!=UserInput[i])
                        {
                           GUESS2=BAD;
                           break;
                        }
                        else
                        {
                           GUESS2=GOOD;
                        }
                    }
                    for(i=0;i<4;i++)
                    {
                        if(p3[i]!=UserInput[i])
                        {
                            GUESS3=BAD;
                            break;
                        }
                        else
                        {
                            GUESS3=GOOD;
                        }
                    }
                    for(i=0;i<4;i++)
                    {
                        if(p4[i]!=UserInput[i])
                        {
                            GUESS4=BAD;
                            break;
                        }
                        else
                        {
                            GUESS4=GOOD;
                        }
                    }  
                    if(GUESS1==GOOD || GUESS2==GOOD || GUESS3==GOOD || GUESS4==GOOD)
                    {
                        clearLCD();
                        printStringLCD("GOOD");
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }
                    else if(GUESS1==BAD && GUESS2==BAD && GUESS3==BAD && GUESS4==BAD)
                    {
                        clearLCD();
                        printStringLCD("BAD");
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }        
                }
                if(StarCount==1)
                {
                    USERINPUT=VALID; //ASSUME
                    InSet = TURNOFF;
                    InEnter = TURNON;
                    StarCount=0;
                    count=0;
                
                    for(i=0;i<4;i++)//RESET USER INPUT
                    {
                        UserInput[i]='0';
                    }  
                    state = Set_Mode;
                }
            
                break;
            
            case Read_Keypad:
               
               if(ROW1 == PRESSED || ROW2 == PRESSED || ROW3 == PRESSED || ROW4 == PRESSED)
               {
                   output = scanKeypad();
               }
               
               if(ROW1 == RELEASED || ROW2 == RELEASED || ROW3 == RELEASED ||  ROW4 == RELEASED)   
               {
                   state = Print_LCD;  
               }
               break;
                
            case Print_LCD:
                 
                if( counter < 8)
                {
                    printCharLCD(output);
                    counter++;          
                }
                else if (counter == 8)
                {
                    printCharLCD(output);
                    counter++; 
                    moveCursorLCD(1, 2);
                }
                else if (counter > 8 && counter < 16)
                {
                    printCharLCD(output);
                    counter++;        
                }
                else if(counter == 16)
                {
                    printCharLCD(output);
                    counter = 0; 
                    moveCursorLCD(1, 1);      
                }
                
                count++;
                          
                break;
            
            case Set_Mode:
                
                InSet = TURNON;
                InEnter = TURNOFF;
                
                clearLCD();
                printStringLCD("Set Mode:");
                moveCursorLCD(0,2); //COL ROW
                
                
                USERINPUT=VALID;
            
                for(i=0;i<4;i++)//Check UserInput values UI[0]->UI[4]      
                {
                    if(UserInput[i]=='*' || UserInput[i]=='#')//Check for * or # 
                    {
                        USERINPUT=NOTVALID; //SET USERINPUT to NOTVALID
                        
                    }
                }
            
                if(USERINPUT==VALID)// No * or # in USERINPUT VALUES
                {
                    if(PASSWORD2==EMPTY)
                    {
                                for(i=0;i<4;i++)
                                    {
                                        p2[i]=UserInput[i]; 

                                    }
                                PASSWORD2 = FULL;
                            
                                clearLCD();
                                printStringLCD("PW2 STORED");
                                for(i=0;i<500;i++)
                                    {
                                        delayUs(1000);
                                    }
           
                    }
                    else if(PASSWORD2==FULL && PASSWORD3==EMPTY)
                    {
                        for(i=0;i<4;i++)
                        {
                            p3[i]=UserInput[i]; 

                        }
                        PASSWORD3 = FULL;
                            
                        clearLCD();
                        printStringLCD("PW3 STORED");
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }
                    
                     else if(PASSWORD2==FULL && PASSWORD3==FULL && PASSWORD4==EMPTY)
                    {
                        for(i=0;i<4;i++)
                        {
                            p4[i]=UserInput[i]; 
                        }
                        PASSWORD4 = FULL;
                            
                        clearLCD();
                        printStringLCD("PW4 STORED");
                            
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }

                        clearLCD();
                        printStringLCD("VALID"); //PW4 IS THE LAST PASSWORD ENTERED

                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }
                    if (PASSWORD2==FULL && PASSWORD3==FULL && PASSWORD4==FULL) //ALL PASSWORDS ARE FULL
                    {
                        clearLCD();
                        printStringLCD("STORAGE FULL");
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }
                    else if (PASSWORD2==EMPTY || PASSWORD3==EMPTY || PASSWORD4==EMPTY) //At LEAST ONE PASSWORD IS EMPTY
                    {
                        clearLCD();
                        printStringLCD("VALID");
                        for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
                    }
                
                }
            
            else if(USERINPUT==NOTVALID)// * or # is in USERINPUT VALUES
            {
                    clearLCD();
                    printStringLCD("NOT VALID");
                    
                    for(i=0;i<500;i++)
                        {
                            delayUs(1000);
                        }
            }
                break;
          
         }   
    } 
    return 0;
}
Ejemplo n.º 22
0
Archivo: lcd.c Proyecto: rtfi/final
void printRunning(){
    moveCursorLCD(0,0);
    printStringLCD("RUNNING");
}