예제 #1
0
int main( void ) {
    initPMP();
    initLCD(7);
    initSerial2();

//    initSPI();
    cmdLCD(0b00000010); //return home??
    //writeLCD("hello");

    writeLCD("Begin");

//    int tempStepperCounts[5];
//    int heading_fp; // remember this is in fixed point from spi; 2,14
//    double heading;
//    int i=0;
    while(1) {
        if(newMSG) {
            cmdLCD(0b00000010); //return home??
            writeLCD("                ");
            cmdLCD(0b00000010); //return home??
            writeLCD(msg);
            txSerial("ASS!");
            newMSG = 0;
        }
//        writeLCD("FWD...");
//        writeSlave(MOTOR_DRIVER,SPI_MOTOR,(MOTOR_FWD SPI_MOTOR_RIGHT_DIR) |
//                                      (MOTOR_FULL_SPEED SPI_MOTOR_RIGHT_SPEED));
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_DIR,'F');
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_SPEED,30000);
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_STEPS,1500);
//        for(i=1;i<5000;i+=500)
//            writeSlave(STEPPER_DRIVER,SPI_STEPPER_SPEED,30000-i);

//        msDelay(1500);
//        writeSlave(MOTOR_DRIVER,SPI_MOTOR,(MOTOR_REV SPI_MOTOR_RIGHT_DIR) |
//                                            (MOTOR_STOP SPI_MOTOR_RIGHT_SPEED));
//        msDelay(1500);
//        writeLCD("REV...");
//        writeSlave(MOTOR_DRIVER,SPI_MOTOR,(MOTOR_REV SPI_MOTOR_RIGHT_DIR) |
//                                      (MOTOR_FULL_SPEED SPI_MOTOR_RIGHT_SPEED));
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_DIR,'R');
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_SPEED,25000);
//        writeSlave(STEPPER_DRIVER,SPI_STEPPER_STEPS,1000);
//        msDelay(500);
//        tempStepperCounts[0] = readSlave(STEPPER_DRIVER,SPI_STEPPER_INPROG);
//        tempStepperCounts[1] = readSlave(STEPPER_DRIVER,SPI_STEPPER_INPROG);
//        tempStepperCounts[2] = readSlave(STEPPER_DRIVER,SPI_STEPPER_INPROG);
//        msDelay(100);
//        tempStepperCounts[3] = readSlave(STEPPER_DRIVER,SPI_STEPPER_INPROG);
//        msDelay(100);
//        tempStepperCounts[4] = readSlave(STEPPER_DRIVER,SPI_STEPPER_INPROG);
//        msDelay(1500);
//        writeSlave(MOTOR_DRIVER,SPI_MOTOR,(MOTOR_REV SPI_MOTOR_RIGHT_DIR) |
//                                            (MOTOR_STOP SPI_MOTOR_RIGHT_SPEED));
//        msDelay(1500);
////        heading_fp = readSlave(COMPASS,COMPASS_HEADING);
////        heading = ((double) heading_fp) / FIXEDPOINT_13BIT;
//        cmdLCD(0b00000010); //return home??
//        writeLCD("               ");
//        cmdLCD(0b00000010); //return home??
    };
    return (EXIT_SUCCESS);
}
예제 #2
0
파일: main.c 프로젝트: freq0ut/Stir-Plate
/** Main **/
int main(void){  
    /** Declare Local Variables **/
    
    /** Initialize State Variables **/
    myBOOLs.mainMenuTrue = TRUE;    // want program to enter into the main menu
    myBOOLs.mainDecide = TRUE;      // want program to enter into the main menu
    myBOOLs.modeMenuTrue = FALSE;
    myBOOLs.modeDecide = FALSE;
    myBOOLs.rpmMenuTrue = FALSE;
    myBOOLs.rpmDecide = FALSE;
    
    /** Initialize Value Variables **/
    rpm = 60;
    
    /** Configure Analog Ports **/
    AD1PCFGbits.PCFG5 = HIGH;  // disable analog functionality for AN5 (Encoder Pin A)
    AD1PCFGbits.PCFG0 = HIGH;  // disable analog functionality for AN0 (SPI - SS)
    AD1PCFGbits.PCFG2 = HIGH;  // disable analog functionality for AN2 (SPI - SDI)
    AD1PCFGbits.PCFG4 = HIGH;  // disable analog functionality for AN4 (SPI - SCK)

    /** Configure Pin Directions **/
    TRISAbits.TRISA2 = OUTPUT;      // *output* Stepper Motor Dir
    TRISAbits.TRISA4 = OUTPUT;      // *output* Red LED Sink
    
    TRISBbits.TRISB3 = INPUT;       // *input* (Encoder Pin A) ~interrupt
    TRISBbits.TRISB4 = INPUT;       // *input* (Encoder Pin B)
    TRISBbits.TRISB9 = INPUT;       // *input* (Encoder PUSH) ~interrupt
    
    TRISAbits.TRISA0 = OUTPUT;      // *output* (SS for Thermo)
    TRISBbits.TRISB0 = INPUT;       // *input*  (SPI - SDI)
    TRISBbits.TRISB2 = OUTPUT;      // *output* (SPI - SCK)
    
    /** Initialize Pin States **/
    LATAbits.LATA2 = LOW;       // Set direction to CW
    LATAbits.LATA4 = LOW;       // Set Red LED ON (sink current)
    LATAbits.LATA0 = HIGH;      // Set SS high
    TRISBbits.TRISB2 = LOW;     // Set SCK low
    
    /** Configure Peripheral Pin Selects **/
    __builtin_write_OSCCONL(OSCCON & 0xBF); // unlock registers to configure PPS
    RPINR0bits.INT1R = 3;   // configure RP3 as Ext. Int. 1
    RPINR1bits.INT2R = 9;   // configure RP9 as Ext. Int. 2
    RPOR7bits.RP15R = 18;   // configure RP15 as OC1 (PWM for EasyDriver)
    RPOR5bits.RP10R = 19;   // configure RP11 as OC2 (PWM for buzzer)
    __builtin_write_OSCCONL(OSCCON | 0x40); // lock registers
    
    /** Configure PWMs **/
    period = ((8000000*60)/(1600*rpm));     // calculate PR based on desired PRM
    duty = period/2;                        // duty cycle of 50%
    initPWM(period, duty);                  // PWM initialization function
    initPWMbuzz();

    /** Configure PMP & LCD **/
    initPMP();
    initLCD();
    
    setLCDG(0);
    putLCD(0b00000);
    putLCD(0b01100);
    putLCD(0b01100);
    putLCD(0b01100);
    putLCD(0b11110);
    putLCD(0b11110);
    putLCD(0b01100);
    putLCD(0);
    
    /** Configure Interrupts **/
    INTCON2bits.ALTIVT = 0; //use primary IVT
    //EXT1 interrupt
    INTCON2bits.INT1EP = 1; // interrupt on falling edge
    IPC5bits.INT1IP = 4; //set priority level to 4
    IFS1bits.INT1IF = 0; //initialize INT1 flag to zero
    IEC1bits.INT1IE = 1; //enable the interrupt source
    //EXT2 interrupt
    INTCON2bits.INT2EP = 1; // interrupt on falling edge
    IPC7bits.INT2IP = 7; //set priority level to 4
    IFS1bits.INT2IF = 0; //initialize INT2 flag to zero
    IEC1bits.INT2IE = 1; //enable the interrupt source

    /** LCD Splash Screen **/
    clearLCD();
    setCursor(1,0);
    putsLCD("   Stir Plate   ");
    setCursor(2,0);
    putsLCD("      9000      ");
    delay_ms(3000);
    clearLCD();
    OC2CON = 0x0000;
    /*------------------INFINITE LOOP------------------*/
    while(1)
    {
        menuDecision();
    }
    return (EXIT_SUCCESS);
}
예제 #3
0
/*------------------MAIN FUNCTION------------------*/
int main(void)
{  
    __builtin_write_OSCCONL(2); // Enable secondary oscillator with unlock sequence
    T1CON = 0x8012; // Enable T1 from external oscillator (SECONDARY), pre-scaler of 8)
    T2CON = 0x8000;
    PR1 = 410;      // this value generates an interrupt every 100 milliseconds (Primary)

    /*------------------CONFIGURE INTERRUPTS------------------*/
    INTCON2bits.INT0EP = 0;     // interrupt on positive edge
    INTCON2bits.ALTIVT = 0;     // use primary IVT
    IPC0bits.T1IP = 4;          // set priority level to 4 (100)
    IFS0bits.T1IF = 0;          // initialize T1 flag to zero
    IEC0bits.T1IE = 1;          // enable the T1 timer interrupt source
    
    TRISBbits.TRISB2 = 0; // Used as Register Select for LCD
    initPMP();
    initLCD();
    
    setLCDG(0);
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b01110);
    putLCD(0);
    
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b00000);
    putLCD(0b11111);
    putLCD(0);
    
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b01110);
    putLCD(0b10001);
    putLCD(0);

    int Buf = 0;
    initADC();
    //TRISB = 0xFF00; // configure LED port as outputs
    char BufString[20];
    char BufString2[5];
    char BufString3[16];
    double voltage, vAvg, avgTime;
    int i, time;
    unsigned long bufAvg;
    int nAvg = 100;
    TMR1 = 0;
    /*------------------INFINITE LOOP------------------*/
    while(1)
    {
        vAvg = 0;
        voltage = 0;
        bufAvg = 0;
        time = 0;
        avgTime = 0;
        for(i=0;i<nAvg;i++)
        {
            TMR2 = 0;
            Buf = getADC(0);    // read channel 1 of ADC
            time = TMR2;
            voltage = Buf*3.3/1023;
            vAvg = vAvg + voltage;
            bufAvg = bufAvg + Buf;
            avgTime = avgTime + time;
        }
        vAvg = vAvg/nAvg;
        bufAvg = bufAvg/nAvg;
        avgTime = avgTime/nAvg/16/1000;
        if(myBOOLs.timer_flag == TRUE)
        {
            setCursor(1,0);
            putsLCD("Voltage: ");
            sprintf(BufString,"%.02f",vAvg);
            sprintf(BufString2,"%lu",bufAvg);
            sprintf(BufString3,"%.05f",avgTime);
            setCursor(1,9);
            putsLCD(BufString);
            setCursor(1,16);
            putsLCD(BufString2);
            putsLCD("   ");
            setCursor(2,0);
            putsLCD("Time: ");
            setCursor(2,6);
            putsLCD(BufString3);
            setCursor(2,14);
            putsLCD("ms");
            setCursor(2,19);
            if(bufAvg > 1023*2/3)
                putLCD(0);
            if(bufAvg < 1023*2/3 && bufAvg > 1023*1/3)
                putLCD(1);
            if(bufAvg < 1023*1/3 && bufAvg > 0)
                putLCD(2);
            myBOOLs.timer_flag = FALSE;
        }
    }
    return (EXIT_SUCCESS);
}
예제 #4
0
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// MAIN FUNCTION ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
int main(void) 
{
    ///////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////// SETUP ////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////
    // Analog/Digital Pin Configuration
    ANSELA = 0x0000;
    ANSELB = 0x0000;
    ANSELC = 0x0000;
    ANSELD = 0x0000;
    ANSELG = 0x0000;
    ANSELCbits.ANSC1 = 0; // Pin 22 (RC1/AN7) is analog (Trigger)
    ANSELAbits.ANSA0 = 1; // Pin 13 (RA0/AN0) is analog (ADC1CH0)
    ANSELAbits.ANSA1 = 1; // Pin 14 (RA1/AN1) is analog (ADC1CH1)
    ANSELBbits.ANSB0 = 1; // Pin 15 (RB0/AN2) is analog (ADC1CH2)
    ANSELBbits.ANSB1 = 1; // Pin 16 (RB1/AN3) is analog (ADC1CH3)
    
    __builtin_write_OSCCONL(OSCCON & 0xBF); // unlock registers to configure PPS
    RPOR7bits.RP57R = 0b10000;   // configure RP57 as OC1 (PWM Horizontal)
    __builtin_write_OSCCONL(OSCCON | 0x40); // lock registers
    
    // Digital I/O Pin Configuration
    //TRISCbits.TRISC9 = 0;
    
    TRISEbits.TRISE14 = 0; // Pin 29 (RE14) is a digital output (Chip Select 1)
    SPI_CS1_HIGH;

    TRISEbits.TRISE15 = 0; // Pin 30 (RE15) is a digital output (Chip Select 2)
    SPI_CS2_HIGH;

    TRISBbits.TRISB4 = 0; // Pin 32 (RB4) is a digital output (SPI Clock)
    SPI_CLK_LOW;

    TRISAbits.TRISA8 = 0; // Pin 31 (RA8) is a digital output (SPI Data In)
    SPI_DIN_LOW;
    
    TRISGbits.TRISG6 = 0; // Register Select Output for LCD.

    // Initializing Main Loop
    InitSystemClock133(); // Make sure this matches in the config.h (FOSC 133333332LL)
    //InitSystemClock140(); // Make sure this matches in the config.h (FOSC 140000000LL)
    _NSTDIS = 0;
    GenPurpTimer32();
    InitNoTriggerWatchdogTimer();
    InitC4TriggerTimer();
    InitTrigger();
    CaptureFrontTimer();
    
    InitPWM();
    initPMP();
    initLCD();
    InitADC1();
    clearLCD();
    
    WritePGA(PGA_gain); // Initializes both PGAs
    //homeScreen();
    WriteServo(90,90); // Initialize servo positions (whole number degrees from 0 to 180))
    
    while(1) 
    {
    	// Infinite Loop:
        WriteServo(90,90);
        delay_ms(1000);
        WriteServo(90+35,90);
        delay_ms(1000);
        WriteServo(90,90);
        delay_ms(1000);
        WriteServo(90-35,90);
        delay_ms(1000);
    }
}