Beispiel #1
0
void switch_init(){
	 __enable_interrupt();

	 Buttons_init(BUTTON_S1 );
	 Buttons_interruptEnable(BUTTON_S1 );

	 Buttons_init(BUTTON_S2 );
	 Buttons_interruptEnable(BUTTON_S2 );
}
Beispiel #2
0
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
    taskDISABLE_INTERRUPTS();

    /* Disable the watchdog. */
    WDTCTL = WDTPW + WDTHOLD;

    //halBoardInit();
    Board_init();

    // Set Vcore to accomodate for max. allowed system speed
    SetVCore(3);

    // Use 32.768kHz XTAL as reference
    LFXT_Start(XT1DRIVE_0);

    // Set system clock to max (25MHz)
    Init_FLL_Settle(25000, 762);

    SFRIFG1 = 0;
    SFRIE1 |= OFIE;

    //LFXT_Start( XT1DRIVE_0 );
    //hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );

    //halButtonsInit( BUTTON_ALL );
    Buttons_init(BUTTON_ALL);
    //halButtonsInterruptEnable( BUTTON_SELECT );
    Buttons_interruptEnable(BUTTON_S2);

    /* Initialise the LCD, but note that the backlight is not used as the
    library function uses timer A0 to modulate the backlight, and this file
    defines	vApplicationSetupTimerInterrupt() to also use timer A0 to generate
    the tick interrupt.  If the backlight is required, then change either the
    halLCD library or vApplicationSetupTimerInterrupt() to use a different
    timer.  Timer A1 is used for the run time stats time base6. */
    //halLcdInit();
    //halLcdSetContrast( 100 );
    //halLcdClearScreen();

    //halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );
}
//Plots adc values on pin 6.6 on LCD
void plot(){
	unsigned int sample1,sample2,i=0;

	 Buttons_init(BUTTON_S2);
	 Buttons_interruptEnable(BUTTON_S2);


	 Buttons_init(BUTTON_S1);
	 Buttons_interruptEnable(BUTTON_S1);

     buttonsPressed = 0;

    Dogs102x6_init();
    Dogs102x6_backlightInit();
    Dogs102x6_setBacklight(11);
    Dogs102x6_setContrast(11);
    Dogs102x6_clearScreen();

    int buffer[104];
    int j;
    for(j=0; j<102; j++){
        buffer[j] = 0;
    }

    Dogs102x6_stringDraw(7, 0, "S2=Esc S1=P/R", DOGS102x6_DRAW_NORMAL);
    while(1)
    {
    	if(buttonsPressed & BUTTON_S2){
    		  _delay_ms(200);
    	      buttonsPressed=0;
    	      lcd_init(); //initialise grlib
    	      break;
    	 }
          if(i == 101)
          {
              Dogs102x6_clearScreen();
              int j;
              for(j=0; j<102; j++){
            	  buffer[j] = 0;
              }
              Dogs102x6_stringDraw(7, 0, "S2=Esc S1=P/R",DOGS102x6_DRAW_NORMAL);
              i = 0;
           }
           ADC12CTL0 |= ADC12SC + ADC12ENC;
           // Start sampling/conversion
           while (ADC12CTL1 & ADC12BUSY) __no_operation();
           sample1 = ADC12MEM0 & 0x0FFF;
           buffer[i]=sample1;
           __delay_cycles(1000000);
           ADC12CTL0 |= ADC12SC + ADC12ENC;
           // Start sampling/conversion
           while (ADC12CTL1 & ADC12BUSY) __no_operation();
           sample2 = ADC12MEM0 & 0x0FFF;
           buffer[i+1]=sample2;
           Dogs102x6_lineDraw(i,56-sample1/86,i+1,56-sample2/86,0);

           //Pause the screen
           if(buttonsPressed & BUTTON_S1){
        	   _delay_ms(200);
               buttonsPressed = 0;

               while(!(buttonsPressed & BUTTON_S1)){
            	   Dogs102x6_clearScreen();
            	   int j;
            	   for(j=0; j<104; j++){
            	       Dogs102x6_lineDraw(j,56-buffer[j]/86,j+1,56-buffer[j+1]/86,0);
            	   }
            	   Wheel_init();
            	   int pos = Wheel_getValue();
            	   Dogs102x6_lineDraw(0,(int)(pos*48)/4096+8,104,(int)(pos*48)/4096+8,0);

            	   char c1[10], c2[10];
            	   int reverse_adc = 86*(48 - (pos*48)/4096);
            	   snprintf(c1, 10,"%d", reverse_adc);
            	   Dogs102x6_stringDraw(56, 0, c1, DOGS102x6_DRAW_NORMAL);
            	   int voltage = reverse_adc*3.7/4096.0 * 1000; //Voltage in mV
            	   snprintf(c2, 10,"%d", voltage);
            	   Dogs102x6_stringDraw(0, 0, c2, DOGS102x6_DRAW_NORMAL);
            	   Dogs102x6_stringDraw(0, 28, "mV", DOGS102x6_DRAW_NORMAL);

            	   _delay_ms(500);
               }
               _delay_ms(200);
               buttonsPressed = 0;
               Dogs102x6_clearScreen();
               adc_init(); //init required to use 6.6
           }

           ++ i;


      }
}