コード例 #1
0
ファイル: main.c プロジェクト: ritwik1993/me433_homework
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
 
    char message[100];
    SYS_Initialize ( NULL );
    //set up accelerometer
    acc_setup();
   //set up display
    display_init();
    display_clear();
    sprintf(message,"System Initialised!");
    write_string(message,0,0);
    display_draw();    
    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
        

    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}
コード例 #2
0
ファイル: app.c プロジェクト: pg8/ME433
void APP_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;
    
    appData.deviceHandle  = USB_DEVICE_HANDLE_INVALID;
    appData.isConfigured = false;
    appData.emulateMouse = true;
    appData.hidInstance = 0;
    appData.isMouseReportSendBusy = false;
    appData.isSwitchPressed = false;
    appData.ignoreSwitchPress = false;
    acc_setup();
}
コード例 #3
0
ファイル: system_init.c プロジェクト: aerogelcube/HW7
void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_DEVCON_JTAGDisable();

    /* Board Support Package Initialization */
    BSP_Initialize();

    /* System Services Initialization */    
    SYS_INT_Initialize();  
    SYS_PORTS_Initialize();

    /* Initialize Drivers */

    /* Initialize System Services */


    /* Initialize Middleware */
    /* Set priority of USB interrupt source */
    SYS_INT_VectorPrioritySet(INT_VECTOR_USB1, INT_PRIORITY_LEVEL4);

    /* Set Sub-priority of USB interrupt source */
    SYS_INT_VectorSubprioritySet(INT_VECTOR_USB1, INT_SUBPRIORITY_LEVEL0);


    /* Initialize the USB device layer */
    sysObj.usbDevObject0 = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 , ( SYS_MODULE_INIT* ) & usbDevInitData);

    /* display_init();Enable Global Interrupts */
    SYS_INT_Enable();

    /*Initialize accelerometer*/
    acc_setup();
    
    /* Initialize the Application */
    APP_Initialize();

    
    
}
コード例 #4
0
ファイル: main.c プロジェクト: guiklink/ME433
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
    SYS_Initialize ( NULL );

    /* Initialize Accel Registers */
    acc_setup();

    /* Initialize Display Registers */
    //display_init();

    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );

    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}
コード例 #5
0
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
    SYS_Initialize ( NULL );
    // string used for OLED
    char str[200];

    ANSELBbits.ANSB13 = 0; // make analog input digital
    U1RXRbits.U1RXR = 0b0000; // set U1RX to pin A2
    RPB15Rbits.RPB15R = 0b0101; // set B15 to U1TX

    TRISBbits.TRISB13 = 1;     // set up USER pin as input
    TRISBbits.TRISB7 = 0;    // set up LED1 pin as a digital output

    APP_USBDeviceEventHandler();
    
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

     // set up accelerometer
    acc_setup();

    __builtin_enable_interrupts();

    short accels[3];    // accelerations for the 3 axes
    short mags[3];      // magnetometer readings for the 3 axes
    short temp;         // temperature

    display_init();

    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
                // read the accelerometer from all three axes
        // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)
        // the accelerations are 16-bit twos compliment numbers, the same as a short
        acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
        // need to read all 6 bytes in one transaction to get an update.
        acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);

        // read the temperature data. Its a right justified 12 bit two's compliment number
        acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);


        display_clear();
//      sprintf(str, "Hello world %d!", accels);

        int x_acc = accels[0]*64/16000;
        int y_acc = accels[1]*32/16000;
        int xxx,yyy;

        if (x_acc>=0){
            if(x_acc>64) x_acc=64;
            for (xxx=0;xxx<x_acc;xxx++){
                display_pixel_set(31,64-xxx,1);
                display_pixel_set(32,64-xxx,1);
                display_pixel_set(33,64-xxx,1);
            }
        }
        else{
            if(x_acc<-64) x_acc=-64;
            for (xxx=0;xxx>x_acc;xxx--){
                display_pixel_set(31,64-xxx,1);
                display_pixel_set(32,64-xxx,1);
                display_pixel_set(33,64-xxx,1);
            }
        }

        if (y_acc>=0){
            if(y_acc>32) y_acc=32;
            for (yyy=0;yyy<y_acc;yyy++){
                display_pixel_set(32-yyy,63,1);
                display_pixel_set(32-yyy,64,1);
                display_pixel_set(32-yyy,65,1);
            }
        }
        else{
            if(y_acc<-32) y_acc=-32;
            for (yyy=0;yyy>y_acc;yyy--){
                display_pixel_set(32-yyy,63,1);
                display_pixel_set(32-yyy,64,1);
                display_pixel_set(32-yyy,65,1);
            }
        }

        display_draw();

        SYS_Tasks ( );

    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}
コード例 #6
0
ファイル: HW5.c プロジェクト: shn1988110/HW5
int main ()
{
    
    __builtin_disable_interrupts();

// set the CP0 CONFIG register to indicate that
// kseg0 is cacheable (0x3) or uncacheable (0x2)
// see Chapter 2 "CPU for Devices with M4K Core"
// of the PIC32 reference manual
__builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

// no cache on this chip!

// 0 data RAM access wait states
BMXCONbits.BMXWSDRM = 0x0;

// enable multi vector interrupts
INTCONbits.MVEC = 0x1;

// disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
DDPCONbits.JTAGEN = 0;

__builtin_enable_interrupts();


TRISBbits.TRISB7 = 0;       // set up LED1 pin as a digital output
//    int i,a;
//    display_init();
//    for (i = 0; i<10; ++i)
//    {
//        a = 30+i;
//        display_pixel_set(15,a,1);
//        display_draw();
//    }
    char input[100]; 
    int i=0;
    short accels[3]; // accelerations for the 3 axes
    short mags[3]; // magnetometer readings for the 3 axes
    short temp; 
    
    acc_setup();    //initialize accelerometer
	display_init(); //initialize LED screen
    

    
    float xg, yg, zg;

    
    while(1)
    {
    start_position[0] = 0;
    start_position[1] = 0;
    center_position[0] = 32;
    center_position[1] = 64;
    acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
    acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);
    acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);
    
    xg = (float) accels[0]/16000;
    yg = (float) accels[1]/16000;
    zg = (float) accels[2]/16000;
    
    sprintf(input,"x: %.2f y: %.2f z: %.2f ", xg,yg,zg);
    display_reset();
    display_draw();
    display_ggraph(xg,yg);
    while(input[i])
    {

        display_message(input[i]);
        i++;
        start_position[1] = start_position[1]+5;
//        if(start_position[1]+5>128)
//        {start_position[0]+1;}
//        else
//        {start_position[1] = start_position[1]+5;}
    }
    i = 0;
    display_draw();
    _CP0_SET_COUNT(0);
    while(_CP0_GET_COUNT()<5000000)
    {;}
    
    }
	return (0);
}
コード例 #7
0
ファイル: setup.c プロジェクト: erelias/433
void setup(){
    // DEVCFGs here

// DEVCFG0
#pragma config DEBUG = OFF // no debugging
#pragma config JTAGEN = OFF // no jtag
#pragma config ICESEL = ICS_PGx1 // use PGED1 and PGEC1
#pragma config PWP = OFF // no write protect
#pragma config BWP = OFF // not boot write protect
#pragma config CP = OFF // no code protect

// DEVCFG1
#pragma config FNOSC = PRIPLL // use primary oscillator with pll
#pragma config FSOSCEN = OFF // turn off secondary oscillator
#pragma config IESO = OFF // no switching clocks
#pragma config POSCMOD = HS // high speed crystal mode
#pragma config OSCIOFNC = OFF // free up secondary osc pins
#pragma config FPBDIV = DIV_1 // divide CPU freq by 1 for peripheral bus clock
#pragma config FCKSM = CSDCMD // do not enable clock switch
#pragma config WDTPS = PS1 // slowest wdt
#pragma config WINDIS = OFF // no wdt window
#pragma config FWDTEN = OFF // wdt off by default
#pragma config FWDTWINSZ = WINSZ_25 // wdt window at 25%

// DEVCFG2 - get the CPU clock to 40MHz
#pragma config FPLLIDIV = DIV_2 // divide input clock to be in range 4-5MHz
#pragma config FPLLMUL = MUL_20 // multiply clock after FPLLIDIV
#pragma config UPLLIDIV = DIV_1 // divide clock after FPLLMUL
#pragma config UPLLEN = ON // USB clock on
#pragma config FPLLODIV = DIV_2 // divide clock by 1 to output on pin

// DEVCFG3
#pragma config USERID = 0 // some 16bit userid
#pragma config PMDL1WAY = ON // not multiple reconfiguration, check this
#pragma config IOL1WAY = ON // not multimple reconfiguration, check this
#pragma config FUSBIDIO = ON // USB pins controlled by USB module
#pragma config FVBUSONIO = ON // controlled by USB module
    
     // startup
    __builtin_disable_interrupts();
    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);
    // no cache on this chip!
    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;
    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;
    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;
    __builtin_enable_interrupts();

    // set up USER pin as input
    ANSELBbits.ANSB13 = 0;
    
    // set up LED1 pin as a digital output - 
    ANSELBbits.ANSB15 = 0;
    TRISBbits.TRISB15 = 0;
    _CP0_SET_COUNT(0);
    while(_CP0_GET_COUNT()<4000000);
    LATBbits.LATB15 = 1;


   
    // set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;
    
    
  
   
    
    
    display_init();
    acc_setup();
}
コード例 #8
0
ファイル: ME433_HW5_main.c プロジェクト: DerekOung/ME433
int main(void) {
    
//Startup
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

    __builtin_enable_interrupts();

ANSELBbits.ANSB13 = 0; // 0 for digital, 1 for analog
ANSELBbits.ANSB15 = 0; // 0 for digital, 1 for analog

    T2CONbits.TCKPS = 0;	//Setting prescaler to 1 (0 corresponds to 1)
    PR2 = 39999;            //Setting PR for timer 2 to 39999
    TMR2 = 0;				//Setting Timer 2 to 0
    OC1CONbits.OCTSEL = 0;	//Telling OC1 to use timer 2
    OC1CONbits.OCM = 0b110;	//Telling OC1 to use PWM without the fault
    OC1RS = 20000;			//Setting initial duty cycle to 20000/(39999+1)*100% = 50%
    OC1R = 20000;			//Updating duty cycles to 20000/(39999+1)*100% = 50%
    T2CONbits.ON = 1;		//turn on timer
    OC1CONbits.ON = 1;		//turn on OC code

// set up USER pin as input
    TRISBbits.TRISB13 = 1; // set pin B13 to be digital INPUT
    // U1RXRbits.U1RXR = 0b0011; // set U1RX to pin B13 (Input pin from User button)

// set up LED1 pin as a digital output
    TRISBbits.TRISB7 = 0; // set pin B7 to be digital OUTPUT
    // LATBbits.LATB7 = 1;
    // RPB7Rbits.RPB7R = 0b0001; //set B7 to U1TX (Output pin for LED1)
    
// set up LED2 as OC1 using Timer2 at 1kHz
    // TRISBbits.TRISB15 = 0; // set B15 to digital OUTPUT
    RPB15Rbits.RPB15R = 0b0101; // set B15 to U1TX (Output pin for OC1)

// set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;
    
// Accelerometer
    acc_setup();
    short accels[3]; // accelerations for the 3 axes
    short mags[3]; // magnetometer readings for the 3 axes
    short temp;

// Display
    display_init();
    
    /*int number = 1337;
    sprintf(buffer,"Hello World %d!", number);
    display_write(28,32,buffer);
    */
    /*                           
    for (ii = 0; ii < 128; ii++){       // Draw a line from position (x,y) = (0,15) to (127,15)
    display_pixel_set(15,ii,1);
    display_draw();
    }*/
    
    
    while (1){
     // invert pin every 0.5s, set PWM duty cycle % to the pot voltage output %
        
        _CP0_SET_COUNT(0);
        LATBINV = 0b10000000;
        
            while(_CP0_GET_COUNT()<10000000){
                OC1RS = readADC()*(PR2+1)/1023; // delay for 10M core ticks, 0.5s
                if (PORTBbits.RB13 == 1){
                    ;// nothing
                }
                else{
                    LATBINV = 0b10000000;
                }
            }
        // read the accelerometer from all three axes
        // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)
        // the accelerations are 16-bit twos compliment numbers, the same as a short
        acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
        // need to read all 6 bytes in one transaction to get an update.
        acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);
        // read the temperature data. Its a right justified 12 bit two's compliment number
        acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);
        
        display_clear();
        
        sprintf(buffer1, "(ax, ay, az)");
        display_write(0, 0, buffer1);
        sprintf(buffer2, "(%d, %d, %d)", accels[0], accels[1], accels[2]);
        display_write(0, 48, buffer2);
        sprintf(buffer, "Derek Oung");
        display_write(0, 56, buffer);
        
        
        
        if (accels[0]>0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
            /*
            while (i<x_line_point){
                display_pixel_set(32,i,1);
                i++;
            }
            */
                
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }
                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]>0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        display_pixel_set(31,63,1);
        display_pixel_set(31,64,1);
        display_pixel_set(31,65,1);
        display_pixel_set(32,63,1);
        display_pixel_set(32,64,1);
        display_pixel_set(32,65,1);
        display_pixel_set(33,63,1);
        display_pixel_set(33,64,1);
        display_pixel_set(33,65,1);
        display_draw();
        
        
        }

}
コード例 #9
0
ファイル: pic_code.c プロジェクト: pg8/ME433
int main() {

    int potValue;
    int timerResets=0;
    // startup
    startup();


T2CONbits.TCKPS = 2; // Timer2 prescaler N=4 (1:4)
PR2 = 19999; // period = (PR2+1) * N * 12.5 ns = 100 us, 10 kHz
TMR2 = 0; // initial TMR2 count is 0
OC1CONbits.OCM = 0b110; // PWM mode without fault pin; other OC1CON bits are defaults
OC1RS = 5000; // duty cycle = OC1RS/(PR2+1) = 25%
OC1R = 5000; // initialize before turning OC1 on; afterward it is read-only
T2CONbits.ON = 1; // turn on Timer2
OC1CONbits.ON = 1; // turn on OC1


    // set up USER pin as input
ANSELBbits.ANSB13 = 0; // 0 for digital, 1 for analog

    // set up LED1 pin as a digital output
ANSELBbits.ANSB15 = 0; // 0 for digital, 1 for analog

TRISBbits.TRISB15 = 0;

    // set up LED2 as OC1 using Timer2 at 1kHz
//RPB7Rbits.RPB7R = 0b0101; // set B15 to OC1
TRISBbits.TRISB7 = 0;
LATBbits.LATB7=0;

//LATBbits.LATB15=1;

    // set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;

    int counter = 0;
    int user = 1;


/* /////////Testing section, old code///////////
    display_init();
    drawChar(72-0x20,45,50);
    drawChar(73-0x20,50,50);
    display_draw();
*/


 /*   /////// Write to LCD
    display_init();
    int k=0;
    int L=0;
    int charCurrent;
    int xIndex = 28;
    int yIndex = 32;
    char message[50];
    sprintf(message,"Hello world 1337!");

    while(L==0){
        charCurrent = (int)message[k];
        if(charCurrent==0){
            L=1;
        }
        else{
            drawChar(charCurrent - 0x20,xIndex, yIndex);
            xIndex+=6;
            k+=1;
        }
    }
    display_draw();

*/




    int a;
    int b;
    int aa;
    int bb;
    int c;
    int d;

    // set up power supply to LCD as digital output
    _CP0_SET_COUNT(0);
    while(_CP0_GET_COUNT()<4000000){

    }
    LATBbits.LATB15=1;

    display_init();


    int charCurrent;


    acc_setup();



    while (1) {

        display_clear();

    int xIndex = 10;
    int yIndex = 32;

        int k=0;
        int L=0;

    char message[500];


    short accels[3]; // accelerations for the 3 axes

    short mags[3]; // magnetometer readings for the 3 axes

    short temp;

    // read the accelerometer from all three axes

    // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)

    // the accelerations are 16-bit twos compliment numbers, the same as a short

    acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);

    // need to read all 6 bytes in one transaction to get an update.

    acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);

    // read the temperature data. Its a right justified 12 bit two's compliment number

    acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);

    /*
    /////// Write to LCD
    sprintf(message,"%d %d %d                   ",accels[0], accels[1],accels[2]);
    L=0;
    
    while(message[k]){
            drawChar(message[k] - 0x20,xIndex, yIndex);
            xIndex+=6;
            k+=1;
        //}
    } */

    a=accels[0]/500;
    b=accels[1]/1000;
    display_pixel_set(31,64,1);
    display_pixel_set(32,64,1);
    display_pixel_set(33,64,1);
    display_pixel_set(32,63,1);
    display_pixel_set(32,65,1);
    if(a<0){
        c=-a;
        for(aa=0;aa<c;aa++){
            display_pixel_set(31,64-aa,1);
            display_pixel_set(32,64-aa,1);
            display_pixel_set(33,64-aa,1);
        }
    }
    if(a>=0){
        for(aa=0;aa<a;aa++){
            display_pixel_set(31,aa+64,1);
            display_pixel_set(32,aa+64,1);
            display_pixel_set(33,aa+64,1);
        }
    }
    if(b<0){
        d=-b;
        for(bb=0;bb<d;bb++){
            display_pixel_set(32-bb,63,1);
            display_pixel_set(32-bb,64,1);
            display_pixel_set(32-bb,65,1);
        }
    }
    if(b>=0){
        for(bb=0;bb<b;bb++){
            display_pixel_set(32+bb,63,1);
            display_pixel_set(32+bb,64,1);
            display_pixel_set(32+bb,65,1);
        }
    }




    display_draw();
    }
}
コード例 #10
0
ファイル: main.c プロジェクト: DerekOung/ME433
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
    SYS_Initialize ( NULL );

    //Startup
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

    __builtin_enable_interrupts();

ANSELBbits.ANSB13 = 0; // 0 for digital, 1 for analog
ANSELBbits.ANSB15 = 0; // 0 for digital, 1 for analog

    T2CONbits.TCKPS = 0;	//Setting prescaler to 1 (0 corresponds to 1)
    PR2 = 39999;            //Setting PR for timer 2 to 39999
    TMR2 = 0;				//Setting Timer 2 to 0
    OC1CONbits.OCTSEL = 0;	//Telling OC1 to use timer 2
    OC1CONbits.OCM = 0b110;	//Telling OC1 to use PWM without the fault
    OC1RS = 20000;			//Setting initial duty cycle to 20000/(39999+1)*100% = 50%
    OC1R = 20000;			//Updating duty cycles to 20000/(39999+1)*100% = 50%
    T2CONbits.ON = 1;		//turn on timer
    OC1CONbits.ON = 1;		//turn on OC code

// set up USER pin as input
    TRISBbits.TRISB13 = 1; // set pin B13 to be digital INPUT
    // U1RXRbits.U1RXR = 0b0011; // set U1RX to pin B13 (Input pin from User button)

// set up LED1 pin as a digital output
    TRISBbits.TRISB7 = 0; // set pin B7 to be digital OUTPUT
    // LATBbits.LATB7 = 1;
    // RPB7Rbits.RPB7R = 0b0001; //set B7 to U1TX (Output pin for LED1)
    
// set up LED2 as OC1 using Timer2 at 1kHz
    // TRISBbits.TRISB15 = 0; // set B15 to digital OUTPUT
    // RPB15Rbits.RPB15R = 0b0101; // set B15 to U1TX (Output pin for OC1)

// set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;
    
// Accelerometer
    acc_setup();
    volatile short accels[3]; // accelerations for the 3 axes
    volatile short mags[3]; // magnetometer readings for the 3 axes
    volatile short temp;

// Display
    display_init();
    
    while (1){
     // invert pin every 0.5s, set PWM duty cycle % to the pot voltage output %
        SYS_Tasks ( );
        /*
        if (accels[0]>0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
  
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }
                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]>0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        
        display_pixel_set(31,63,1);
        display_pixel_set(31,64,1);
        display_pixel_set(31,65,1);
        display_pixel_set(32,63,1);
        display_pixel_set(32,64,1);
        display_pixel_set(32,65,1);
        display_pixel_set(33,63,1);
        display_pixel_set(33,64,1);
        display_pixel_set(33,65,1);
        display_draw();
         * */
        
        }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}