コード例 #1
0
ファイル: lcd.c プロジェクト: scottmarshall17/ECE372_Lab2
/*
 * 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));
    
}
コード例 #2
0
ファイル: LCD.c プロジェクト: pdxfrog/ECE372
void testLCD(){
    clearLCD();
    moveCursorLCD(0,0);
    printStringLCD(" DUNCAN  JULIAN ");
    moveCursorLCD(0,1);
    printStringLCD(" KYLE    SULTAN ");
}
コード例 #3
0
ファイル: main.c プロジェクト: arwerchan/lab2
int main(void) {
    
    SYSTEMConfigPerformance(40000000);
    initKeypad();
    enableEnterruptKeypad();
    initTimer2();
    initLCD();
    enableInterrupts();
    moveCursorLCD(0,0);
    state = Wait;

    while (1) {
        switch (state) {
            case Wait:
                break;

            case Scan:
                key = scanKeypad();
                state = MoveCursor;
                break;
                
            case MoveCursor:
                if(count == 0) moveCursorLCD(0,0);
                else if (count == 9) moveCursorLCD(1,0);
                state = Print;
                break;
                
            case debounce1:
                delayUs(500);
                state = Scan;
                break;
                
            case debounce2:
                delayUs(500);
                state = MoveCursor;
                break;

            case Print:
                delayUs(100);
                if(key == 0) printCharLCD('0');
                else if(key == 1) printCharLCD('1');
                else if(key == 2) printCharLCD('2');
                else if(key == 3) printCharLCD('3');
                else if(key == 4) printCharLCD('4');
                else if(key == 5) printCharLCD('5');
                else if(key == 6) printCharLCD('6');
                else if(key == 7) printCharLCD('7');
                else if(key == 8) printCharLCD('8');
                else if(key == 9) printCharLCD('9');
                else if(key == 10) printCharLCD('*');
                else if(key == 11) printCharLCD('#');
                state = Wait;
                break;

        }
    }

    return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: Nathanh1/Lab2
int main(void)
{  
    initLCD();
    initKeypad();
    enableInterrupts();
    
    int counter = 1;
    char output = 'a';
    
    while(1)
    {
        switch(state)
        {
            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);      
                }
                
                state = Read_Keypad;
            
            break;         
         }
    } 
    return 0;
}
コード例 #5
0
ファイル: lcd.c プロジェクト: mackncheesiest/ECE372Labs
void addChar(char c){


    if (column == 8)
    {
        column = 0;
        row++;
    }
    if (row == 2)
        row = 0;
    
    moveCursorLCD(row, column);
    printCharLCD(c);
    column++;
    return;
    
    
    
    if(column != 8){    //end of the columns
        if(row != 2){   //end of the rows
        }
        else{
            row = 0;
            column = 0;
        }
    }
    else{
        ++row;
        column = 0;
        printCharLCD(c);
        ++column;
    }
      
    
}
コード例 #6
0
ファイル: ir.c プロジェクト: ECE372FA15/Team
 //**************REMOVE?****************
void testIR() {
#ifdef use_digital_ir
    printIR();
#endif
    moveCursorLCD(1, 2);
    printStringLCD("testing");

}
コード例 #7
0
ファイル: LCD.c プロジェクト: 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); 
}
コード例 #8
0
ファイル: ir.c プロジェクト: 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;
}
コード例 #9
0
ファイル: main.c プロジェクト: Els0/ECE372A
void __ISR(_CHANGE_NOTICE_VECTOR, IPL7SRS) _CNInterrupt(void) {
    //TODO: Implement the interrupt to capture the press of the button
    //char key;
      
      
    dummyVariable = PORTDbits.RD6; // change the value
    dummyVariable2 = PORTGbits.RG12;
    //dummyVariable2 = PORTDbits.RD5;
    dummyVariable3 = PORTDbits.RD9;
    
  
    IFS1bits.CNDIF = 0;
//    IFS1bits.CNBIF = 0;
    IFS1bits.CNGIF = 0;
 
    if (PORTDbits.RD6 == DISABLED) {
        Col = 1;} 
   
    if (PORTGbits.RG12 == DISABLED) {
        Col = 3;} 
    
    if (PORTDbits.RD9 == DISABLED) {
        Col = 2;}

    if ((state == ROW1) || (state == ROW2) || (state == ROW3) || (state == ROW4)) {
        state = DebouncePress;
    } 
    if (state == WaitRelease) {
        state = DebounceRelease;
    }

    if (i == 16) {
        moveCursorLCD(0, 2);
        
    }
    if (i >= 32) {
        moveCursorLCD(0, 0);
        i = 0;
    }
    i++;
}
コード例 #10
0
ファイル: lcd.c プロジェクト: shivani95/Lab1_Part1
/*
 * 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);
}
コード例 #11
0
ファイル: keyboard.c プロジェクト: bebtio/textMessaging.X
// Displays the currently selectable keys on a single row. Row can be set to values
// 1 - 5.
void displayKeyboard(int rowToBeDisplayed)
{
    int i = 0, j = 0;
 
    moveCursorLCD(0,rowToBeDisplayed);
    for(j = 0; j < strlen(KeyBoard.Characters[i]); j++)
    {
        if(KeyBoard.CursorPosition == j)
        {
            writeInvertedCharLCD(KeyBoard.Characters[KeyBoard.ArrayRow][j]);
        }
        else
        {
            writeCharLCD(KeyBoard.Characters[KeyBoard.ArrayRow][j]);
        }
    }
    highlightChar();
}
コード例 #12
0
ファイル: MainMenu.c プロジェクト: bebtio/textMessaging.X
void initMainMenuText()
{
    int i = 0, j = 0;

    for(i = 0; i <= mainMenuChoices; i++)
    {
        moveCursorLCD(0,i);
        for(j = 0; j < strlen(mainMenuOptions[i]); j++)
        {
            if(cursorHighlightMainMenu == i)
            {
                writeInvertedCharLCD(mainMenuOptions[i][j]);
            }
            else
            {
                writeCharLCD(mainMenuOptions[i][j]);
            }
        }
    }
}
コード例 #13
0
ファイル: main.c プロジェクト: pdxfrog/ECE372
int main() {
    SYSTEMConfigPerformance(10000000); //Does something with assembly to set clock speed
    enableInterrupts(); //Make interrupt work

    //initLEDs();
    //initTimer1();
    initTimer2();
    //initSW1();
    initLCD();
    delay(500);
    //printCharLCD(0);
    testLCD();
    
    moveCursorLCD(0,0);
    
    while (1) {
        printCharLCD('K');
                
    }
    return 0;
}
コード例 #14
0
ファイル: ir.c プロジェクト: 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'));


}
コード例 #15
0
ファイル: main.c プロジェクト: 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;
}
コード例 #16
0
ファイル: main.c プロジェクト: pdxfrog/ECE372
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;
}
コード例 #17
0
ファイル: main.c プロジェクト: talani/thisismystuff
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;
}
コード例 #18
0
ファイル: lcd.c プロジェクト: rtfi/final
void printRunning(){
    moveCursorLCD(0,0);
    printStringLCD("RUNNING");
}
コード例 #19
0
ファイル: lcd.c プロジェクト: rtfi/final
void printStopped(){
    moveCursorLCD(0,0);
    printStringLCD("STOPPED");
}
コード例 #20
0
ファイル: lcd.c プロジェクト: rtfi/final
void printTime(char* time){
    moveCursorLCD(1,0);
    printStringLCD(time);
}
コード例 #21
0
ファイル: main.c プロジェクト: mackncheesiest/ECE372Labs
int main(void)
{
    SYSTEMConfigPerformance(SYS_CLOCK);
    
    enableInterrupts();
    initADC();
    initTimer2(); //for PWM
    initPWM();
    initLCD();
    initTimer4(); //for pwm
    initSW();
    
    int track = 1;
    int SpeedR = 0;
    int SpeedL = 0;
    int ones = 0;
    int dec = 0;
    float voltage = 0;

    //Actual main state machine loop
    while(1)
    {
        Speed = ADC1BUF0;
        
        moveCursorLCD(0,0);
        voltage = Speed * ((double)3.3/1023);
        ones = floor(voltage);
        dec = (voltage - ones) * 10;
        printCharLCD('0'+ones);
        printCharLCD('.');
        printCharLCD('0'+dec);
        printCharLCD('V');
        
       delayUs(10000); //10ms - Just to help the LCD not strobe too much
        
        switch(state)
        {
            case wait_Press: //handled by ISR
                break;
            case debouncePress:
                state = wait_Release;
                break;
            case wait_Release: //handled by ISR
                break;
            case debounceRelease:
                if (track == 1){
                    state = forward;
                }
                if (track == 2){
                    state = idle2;
                }
                if (track == 3){
                    state = reverse;
                }
                if (track == 4){
                    state = idle1;
                }
                break;
            case idle1:
                track = 1;
                motorsOff();
                state = wait_Press;
                break;
            case forward:
                track = 2;       
                if(Speed == 511){
                    SpeedR = 1023;
                    SpeedL = 1023;
                }
                else if(Speed < 511){
                    SpeedR = 1023;
                    SpeedL = (2*Speed);
                }
                else if(Speed > 511){
                    SpeedR = 2*(1023 - Speed);
                    SpeedL = 1023;
                }
                else if (Speed == 1023){
                    SpeedR = 0;
                    SpeedL = 1023;
                }
                else if (Speed == 0){
                    SpeedR = 1023;
                    SpeedL = 0;
                }                
                RightMotor_Write(SpeedR);
                LeftMotor_Write(SpeedL);
                break;
            case idle2:
                track = 3;
                motorsOff();
                state = wait_Press;
                break;
            case reverse:
                track = 4;
                if(Speed == 511){
                    SpeedR = 1023;
                    SpeedL = 1023;
                }
                else if(Speed < 511){
                    SpeedR = 1023;
                    SpeedL = 2*Speed;
                }
                else if(Speed > 511){
                    SpeedR = 2*(1023 - Speed);
                    SpeedL = 1023;
                }
                else if (Speed == 1023){
                    SpeedR = 1023;
                    SpeedL = 0;
                }
                else if (Speed == 0){
                    SpeedR = 0;
                    SpeedL = 1023;
                }

                
                RightMotor_Write(0-SpeedR); //maybe it needs the zero to be interpreted as negative?
                LeftMotor_Write(0-SpeedL);
                break;                       
        }
    }
    
    return 0;
}
コード例 #22
0
ファイル: main.c プロジェクト: Team-212/Lab2Part1
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;
}
コード例 #23
0
ファイル: main.c プロジェクト: lodwkeef/general_projects
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;
}
コード例 #24
0
ファイル: lcd.c プロジェクト: DanielWilcoxUA/Lab3
void resetCursorLCD() {
    moveCursorLCD((unsigned char) 1, (unsigned char) 1);
}
コード例 #25
0
ファイル: ir.c プロジェクト: 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

}
コード例 #26
0
ファイル: main.c プロジェクト: ECE372FA15/Team
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;
}
コード例 #27
0
ファイル: main.c プロジェクト: lodwkeef/general_projects
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;
}