Beispiel #1
0
/*____________________________________________________________________________*/
int main (void)
{
    /*** LOCAL VARIABLES ***/    

    /*** CONFIGURE OSCILLATOR ***/
    SET_FreqOsc( FRCDIV_1MHZ );                         //Set frequency of 1 MHZ
    
    /*** CONFIGURE HARDWARE ****/
    Hardware_INIT();                                    //Initialise Hardware functions
    Hardware.ConfigPins_Default();                      //Configure Default Hardware for ELB

    /*** INITIALIZE PERIPHERAL ***/
    TIMER23_INIT(100, TMR_INT_PRI1);                    //Proivde timer period in millisecond
    UART1_INIT( M_9600Hz , M_BRGH_High , TX_INT_PRI0);  //Initialise UART1
    I2C1_INIT(400000, MI2C_INT_PRI0 );                  //Inilialize I2C1

    /*** APPLICATION CODE BEGINS ***/ 
    AMGP_INIT(READ_HEADER1,SEND_UART1USB);              //Select Header to mount sensor card and...
                                                        //...UART port to send data out (To be implemented, Modify this in AMGPSensor.h)
    AMGP.Config(Acc|Mag|Gyro|Pres);                        //Select the sensors to work with eg.(Acc|Mag|Pres)
    /*** ENTER ETERNITY ***/
    while(1)
    {
        /*** READ SENSOR DATA AFTER TIMER PERIOD ELAPSED ***/
        if(V_T23IntFlag_U8)                             // Timer period defined in the Timer init function...
        {                                               // ...the timer interrupt flag is set in ELB_ISR.c
            V_T23IntFlag_U8 = 0;                        // Clear the TIMER Interrupt flag variable
            AMGP.Read(Acc|Mag|Gyro|Pres|TempPres);      // Read selected Sensors Data
            AMGP.Send(Acc|Mag|Gyro|Pres|TempPres);      // Send sensors data Packet through selected UART

            V_Pitch_F32 = atan(AMGP.Data.AccY/AMGP.Data.AccZ); // Use sensors Data perfrom calcualtions
        }
    }
}
/*
--------------------------------------------------------------------------------
[NAME]  	 : ConfigPins_Default
[TYPE]		 : Internal Function & accessible publically through structure
[INPUT] 	 : None
[RETURN]	 : None
[DESCRIPTION]: This function Configueres the pins of ELB to Default Hardware config.
--------------------------------------------------------------------------------
*/
void ConfigPins_Default(void)
{
    __builtin_write_OSCCONL(OSCCON & 0xbf);
    Hardware.ConfigPins_ADC(USE1|USE2|USE3|USE4);
    Hardware.ConfigPins_LED(USE1|USE2|USE3);
    Hardware.ConfigPins_Motor(USE1|USE2);
    Hardware.ConfigPins_PWM(USE1|USE2|USE3|USE4);
    Hardware.ConfigPins_PB(USE1|USE2|USE3);

    Hardware.ConfigPins_UART1();
    Hardware.ConfigPins_UART2();
    Hardware.ConfigPins_SPI1();
    Hardware.ConfigPins_SPI2();

    Hardware.ConfigPins_DTMF();
    __builtin_write_OSCCONL(OSCCON | 0x40);
}
Beispiel #3
0
int main(void)
{
    /*** LOCAL VARIABLES ***/

    /*** CONFIGURE OSCILLATOR ***/
    SET_FreqOsc( FRCDIV_8MHZ );                     //Set Frequency of Oscillator

    /*** CONFIGURE HARDWARE ****/
    Hardware_INIT();                                //Intialize Hardware
    Hardware.ConfigPins_Default();                  //Configure Hardware

    //NOTE: PPS Unlock & Lock Sequence not required when Using  Hardware.ConfigPins_Default()
     __builtin_write_OSCCONL(OSCCON & 0xbf);        //UNLCOK PPS
        Hardware.ConfigPins_PWM(USE2);              //Configure the PWM Pins to use
     __builtin_write_OSCCONL(OSCCON | 0x40);        //LOCK PPS

//      __builtin_write_OSCCONL(OSCCON & 0xbf);        //UNLCOK PPS
//    Hardware.ConfigPins_Motor(USE1|USE2);
//    __builtin_write_OSCCONL(OSCCON | 0x40);        //LOCK PPS

    MotA1 = C_ON; // Set state to OFF
    MotA2 = C_OFF; // Set state to OFF
    
    /*** INITIALIZE PERIPHERAL ***/
    CLKDIVbits.RCDIV0=0;     //clock divider to 0
    PWM2_INIT(PWMsrc_FOSC, 10);
//
    PWM2_SET_PulseWidth(5);                        //Set PWM1 Dutycycle Time 5 mSec
     //To Test, Probe the Pin1 of PWM connector J7

    LCD_INIT();                                     //Initialize LCD
//    LED1_DIR = DIR_OUT;                    // Set LED1 as Output
//    LED1 = C_OFF;                      	// Set state to OFF
//    RE5_IN;


    

    // AN0 input pin is analog

    AD1CON1 = 0x2202; // Configure sample clock source
    // and conversion trigger mode.
    // Unsigned Fraction format (FORM<1:0>=10),
    // Manual conversion trigger (SSRC<2:0>=000),
    // Manual start of sampling (ASAM=0),
    // No operation in Idle mode (ADSIDL=1),
    // S/H in Sample (SAMP = 1)
    AD1CON2 = 0; // Configure A/D voltage reference
    // and buffer fill modes.
    // Vr+ and Vr- from AVdd and AVss (VCFG<2:0>=000),
    // Inputs are not scanned,
    // Interrupt after every sample
    AD1CON3 = 0x0100; // Configure sample time = 1Tad,
    // A/D conversion clock as Tcy
    AD1CHS = 1; // Configure input channels,
    // S/H+ input is AN1,
    // S/H- input is Vr- (AVss).
    AD1CSSL = 0; // No inputs are scanned.
    IFS0bits.AD1IF = 0; // Clear A/D conversion interrupt.
    // Configure A/D interrupt priority bits (AD1IP<2:0>) here, if
    // required. Default priority level is 4.
//    IEC0bits.AD1IE = 1; // Enable A/D conversion interrupt
    AD1CON1bits.ADON = 1; // Turn on A/D
    AD1CON1bits.SAMP = 1; // Start sampling the input   

    //this just gives us a little delay between measurements
    U32 i = 0xFFFFF; //sets i to 1048575
    while (i--); //delay function

    AD1CON1bits.SAMP = 0; // End A/D sampling and start conversion
    // Example code for A/D ISR:


    
    
    
    
//    sensor_read = LATE;

    /*8** APPLICATION CODE BEGINS ***/
    v_PrintData_U16= 2013;                          // Store some Value to print


    /*** ENTER ETERNITY ***/
    while(1)
    {
//        MotA1 = C_ON; // Set state to OFF
//        MotA2 = C_OFF; // Set state to OFF

        
        /*** RECURRING CODE HERE***/
//        sprintf(A_Str_U8,"%d ", v_PrintData_U16);       // Print variable to string
//        LCD_WriteString(1, 0, A_Str_U8);                //print varible on Line1

//        sprintf(A_Str_U8,"BRIGOSHA TECH.");            // Print variable to string
//        LCD_WriteString(2, 2, A_Str_U8);               //print string on second line second column
        //Use TIMER Interrupts to perform time based tasks at fixed interval.
        //Use Peripheral Interrupts to perform event based tasks
        v_PrintData_U16++;

        AD1CON1bits.SAMP = 1; // start sampling...

        U32 i = 0xFFFF; //sets i to 1048575
        while (i--); //delay function

        AD1CON1bits.SAMP = 0; // start converting
        while (!AD1CON1bits.DONE){}; // conversion done?
        ADCValue = ADC1BUF0; // yes then get ADC value

        LCD_Clear();
        sprintf(A_Str_U8,"%u ", ADCValue);       // Print variable to string
        LCD_WriteString(2, 2, A_Str_U8);                //print varible on Line1
        //
    }

}