Пример #1
0
int main(int argc, char** argv) {
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);
    BMXCONbits.BMXWSDRM = 0x0;
    INTCONbits.MVEC = 0x1;
    DDPCONbits.JTAGEN = 0;
     // do your TRIS and LAT commands here
    ANSELA = 0; // A Analogic off
    ANSELB = 0; // B Analogic off

    TRISBbits.TRISB2 = 0; // A4 output
    TRISAbits.TRISA0 = 0; // A4 output

    TRISAbits.TRISA4 = 0; // A4 output
    TRISBbits.TRISB4 = 1; // B4 inuput
    
    __builtin_disable_interrupts();
    
    // starts the PINEX
    
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);
    BMXCONbits.BMXWSDRM = 0x0;
    INTCONbits.MVEC = 0x1;
    DDPCONbits.JTAGEN = 0;
    __builtin_enable_interrupts();
    uart_init();
    return 0;
    
    start_PWM();
    
    lcd_start();
    while(1)
    {
        LATAbits.LATA4 = 0;
        lcd_clearScreen(LCD_COLOR_BLACK);
        lcd_printf("hello\nworld!",LCD_COLOR_WHITE);
        //unsigned int t = timer_start();
        //while (!timer_timeout(t, 500 * TIMER_MILLISECOND));
        blink();
        LATAbits.LATA4 = 1;
        lcd_clearScreen(LCD_COLOR_WHITE);
        lcd_printf("hello!",LCD_COLOR_BLACK);
        //t = timer_start();
        //while (!timer_timeout(t, 500 * TIMER_MILLISECOND));
    }   
    return (EXIT_SUCCESS);
}
void touch_timer(){
  LCD_RECT timerRect; timerRect.left = 0; timerRect.right = 128; timerRect.top = 46; timerRect.bottom = 66;
  lcd_clearScreen(mblack);
  while (!(touch_get_cursor(&m_point))){
  //what timer mode?
    if (timermode == 0){ //stopped mode
    //TODO: print 00:00:00.00 to screen in bignum, centered
     while (!(touch_get_cursor(&m_point))){}
     while ((touch_get_cursor(&m_point))){} //debounce
        //if it is outside numbers go to next display mode
        if (!pointInRect(m_point,timerRect)){oil_temp_gauge();}
        //if it is on numbers go to mode 1
        if (pointInRect(m_point,timerRect)){
           //store millis of start time
           timerStartMillis = millis();
           timermode = 1;
        }
    }
    if (timermode == 1){ //running and screen mode
      while (!(touch_get_cursor(&m_point))){
       //TODO: display code for running timer goes here 
       //current timer value = millis() - timer start
      }
      while (touch_get_cursor(&m_point)){} //debounce
        //if it is on numbers go to mode 2
      if (pointInRect(m_point,timerRect)){
        timermode == 0;
        timerStoppedMillis = 0;
        touch_timer();
      }
    }
    //if it is outside go to next display mode
    if (!(pointInRect(m_point,timerRect))){
        oil_temp_gauge();
    }
  }
}
Пример #3
0
void lcd_start() 
{
    LCD_CS_TRIS = 0;
    LCD_OP_TRIS = 0;
    
    LCD_CS = 1;
    
    spi_init();
    unsigned int time = 0;
    
    lcd_command(LCD_CMD_SWRESET);//software reset
    time = timer_start();
    while (!timer_timeout(time,500 * TIMER_MILLISECOND)) {} //delay(500);

	lcd_command(LCD_CMD_SLPOUT);//exit sleep
    time = timer_start();
	while (!timer_timeout(time,5 * TIMER_MILLISECOND)) {} //delay(5);

	lcd_command(LCD_CMD_PIXFMT);//Set Color Format 16bit
	lcd_data(0x05);
    time = timer_start();
	while (!timer_timeout(time,5 * TIMER_MILLISECOND)) {} //delay(5);

	lcd_command(LCD_CMD_GAMMASET);//default gamma curve 3
	lcd_data(0x04);//0x04;
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_GAMRSEL);//Enable Gamma adj
	lcd_data(0x01);
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_NORML);

	lcd_command(LCD_CMD_DFUNCTR);
	lcd_data(0b11111111);
	lcd_data(0b00000110);

    int i = 0;
	lcd_command(LCD_CMD_PGAMMAC);//Positive Gamma Correction Setting
	for (i=0;i<15;i++){
		lcd_data(pGammaSet[i]);
	}

	lcd_command(LCD_CMD_NGAMMAC);//Negative Gamma Correction Setting
	for (i=0;i<15;i++){
		lcd_data(nGammaSet[i]);
	}

	lcd_command(LCD_CMD_FRMCTR1);//Frame Rate Control (In normal mode/Full colors)
	lcd_data(0x08);//0x0C//0x08
	lcd_data(0x02);//0x14//0x08
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_DINVCTR); //display inversion
	lcd_data(0x07);
	time = _CP0_GET_COUNT();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_PWCTR1);//Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD
	lcd_data(0x0A);//4.30 - 0x0A
	lcd_data(0x02);//0x05
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_PWCTR2);//Set BT[2:0] for AVDD & VCL & VGH & VGL
	lcd_data(0x02);
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_VCOMCTR1);//Set VMH[6:0] & VML[6:0] for VOMH & VCOML
	lcd_data(0x50);//0x50
	lcd_data(99);//0x5b
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_VCOMOFFS);
	lcd_data(0);//0x40
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_CLMADRS);//Set Column Address
	lcd_data16(0x00);
    lcd_data16(LCD_GRAMWIDTH);

	lcd_command(LCD_CMD_PGEADRS);//Set Page Address
	lcd_data16(0x00);
    lcd_data16(LCD_GRAMHEIGH);

	lcd_command(LCD_CMD_VSCLLDEF);
	lcd_data16(0); // __OFFSET
	lcd_data16(LCD_GRAMHEIGH); // _GRAMHEIGH - __OFFSET
	lcd_data16(0);

	lcd_command(LCD_CMD_MADCTL); // rotation
    lcd_data(0b00001000); // bit 3 0 for RGB, 1 for GBR, rotation: 0b00001000, 0b01101000, 0b11001000, 0b10101000

	lcd_command(LCD_CMD_DISPON);//display ON
    time = timer_start();
	while (!timer_timeout(time,TIMER_MILLISECOND)) {} //delay(1);

	lcd_command(LCD_CMD_RAMWR);//Memory Write
    
    lcd_clearScreen(LCD_COLOR_BLACK);
}
void oil_temp_gauge(){
 float endy, endx, o_endx, o_endy;
 float tangle;
 //display the oil temp gauge background
 bmp_draw("oilgaug",0,0);
 float oil_temp = 120, o_oil_temp = 120;
  while (!(touch_get_cursor(&m_point))){
   //get oil temp from arduino
   oil_temp++; //for testing
   //if warmed and not previously warmed then flash message
   if ( (oil_temp_startup == false) && (oil_temp >= oil_temp_warn) ){
      oil_temp_startup = true;
      lcd_clearScreen(mblack);
      lcd_puts("Engine Warmed!",10,30,gaugeRed,mblack); 
            lcd_puts("Engine Warmed!",20,40,gaugeRed,mblack); 
                  lcd_puts("Engine Warmed!",30,50,gaugeRed,mblack); 
                        lcd_puts("Engine Warmed!",40,60,gaugeRed,mblack); 
      delay (2000);
      lcd_clearScreen(mblack);
      bmp_draw("oilgaug",0,0);
   }
   //if the warn point is met flash the circle encompassing the gauge
   if (int(oil_temp) >= warnOilT){
    lcd_circle(11,10,9, gaugeRed, gaugeRed);
    delay(90);
    lcd_circle(11,10,9, gaugeRed, mblack);  
   }
   //draw a line to rep this
   //line is 40 pixels long ... this is always the hypotenuse
     //angle formula is ...
   if (oil_temp <= 120){ //ok
     endx = 64;
     endy = 94;
   }
   else if ((oil_temp > 120) && (oil_temp < 180)){ //not ok
     tangle = 1.5 * (oil_temp - 120); //1.5 is 90degrees/60degF or the scaling factor
     endx = 64.0 - (30.0 * lsin(tangle)); 
     endy = 64.0 + (30.0 * lcos(tangle));
   }
   else if ((oil_temp >= 180) && (oil_temp < 240)){ //ok
     tangle = 1.5 * (oil_temp - 180);
     endx = 64 - (30 * lcos(tangle));
     endy = 64 - (30 * lsin(tangle));
   }
   else if ((oil_temp >= 240) && (oil_temp < 300)){ //not ok
     tangle = 90 - 1.5 * (oil_temp - 240); //inverse...because we are actually looking for the angle down from 90 deg up
     endx = 64 + (30 * lcos(tangle));
     endy = 64 - (30 * lsin(tangle));
   }
   else if (oil_temp > 300){//ok
     endx = 94;
     endy = 64;
   }
   if (abs(o_oil_temp - oil_temp) > 2){
   stroke(224, 38, 41);
     line(64, 64, endx, endy);
     line(65, 64, endx, endy);
     line(63, 64, endx, endy);
     line(64, 65, endx, endy);
     line(64, 63, endx, endy);
   stroke(0,0,0);
     line(64, 63, o_endx, o_endy);
     line(64, 65, o_endx, o_endy);
     line(63, 64, o_endx, o_endy);
     line(65, 64, o_endx, o_endy);
     line(64, 64, o_endx, o_endy);
   }
   o_endx = endx;
   o_endy = endy;
   //for debugging --v
   /*char char_xy[7];
   fmtDouble(endx, 2, char_xy, 7);
   lcd_puts(char_xy, 10, 10, gaugeRed, black);
   fmtDouble(endy, 2, char_xy, 7);
   lcd_puts(char_xy, 20, 20, gaugeRed, black);*/
   //--^
   //print deg F
   //do conversion from int to string with decimal places
   char char_oil_temp[7];
   fmtDouble(oil_temp, 2, char_oil_temp, 7);
   lcd_puts(char_oil_temp, 80, 72, gaugeRed, mblack);
   //delay(500); //for testing
   //bmp_draw("oilgaug",0,0);
  }
  while (touch_get_cursor(&m_point)){} //debounce
  boost_gauge(); //next gauge
}