void system_init()
{
    // OLED Init
    OLED_Init();
    OLED_FillScreen(OLED_COLOR_BLACK);

    // GPIO Init
    R_LED = 1;
    G_LED = 1;
    B_LED = 1;
    GPIO_Digital_Output(&PTC_PDOR, _GPIO_PINMASK_8);
    GPIO_Digital_Output(&PTD_PDOR, _GPIO_PINMASK_0);
    GPIO_Digital_Output(&PTC_PDOR, _GPIO_PINMASK_9);
    GPIO_Analog_Input(&PTB_PDIR, _GPIO_PINMASK_6);    // AN
    GPIO_Analog_Input(&PTB_PDIR, _GPIO_PINMASK_7);    // INT
    GPIO_Digital_Output(&PTA_PDOR, _GPIO_PINMASK_4);  // PWM
    GPIO_Digital_Output(&PTB_PDOR, _GPIO_PINMASK_9);  // Vibration PIN
    PTB_PDOR = 0;

    // PWM Init
    current_duty = 0;
    pwm_period = PWM_FTM0_Init(200,
                               _PWM_EDGE_ALIGNED_PWM,
                                _PWM_CHANNEL_1, 
                                &_GPIO_Module_PWM0_PTA4);
    PWM_FTM0_Set_Duty(0, _PWM_NON_INVERTED, _PWM_CHANNEL_1);   // Set duty ratio
    PWM_FTM0_Start(_PWM_CHANNEL_1);

    Delay_ms(100);

    // Display text
    OLED_DrawBox(0, 0, 96, 15, OLED_COLOR_BLUE);
    OLED_DrawBox(0, 80, 96, 15, OLED_COLOR_BLUE);
    OLED_SetFont(guiFont_Exo_2_Condensed10x16_Regular, OLED_COLOR_WHITE, 0);
    OLED_WriteText("BRUSHLESS", 20, 0);
    OLED_WriteText("Period:", 5, 30);
    OLED_WriteText("Duty:", 5, 50);
    OLED_WriteText("DEC", 15, 80);
    OLED_WriteText("INC", 63, 80);
    WordToStr(pwm_period, txt_value);
    OLED_WriteText(txt_value, 50, 30);
    WordToStr(current_duty, txt_value);
    OLED_WriteText(txt_value, 50, 50);

    hexiwear_uart_messaging_init();              // Init UART messaging
    MOTOR_DIR = CCW;                             // Setting motor direction 
                                                 //  to counter-clock-wise
}
void doIMU() {
  // Accel (degrees)
  IntToStr((int)(MPU9150A.out_accel.x * 90.0f),txt);
  updateLabel(&accelX, ltrim(txt));
  IntToStr((int)(MPU9150A.out_accel.y * 90.0f),txt);
  updateLabel(&accelY, ltrim(txt));
  IntToStr((int)(MPU9150A.out_accel.z * 90.0f),txt);
  updateLabel(&accelZ, ltrim(txt));
  // Gyro (degrees/second)
  IntToStr((int)(MPU9150A.out_gyro.x * 1000.0f / MPU9150A.gdt),txt);
  updateLabel(&gyroX, ltrim(txt));
  IntToStr((int)(MPU9150A.out_gyro.y * 1000.0f / MPU9150A.gdt),txt);
  updateLabel(&gyroY, ltrim(txt));
  IntToStr((int)(MPU9150A.out_gyro.z * 1000.0f / MPU9150A.gdt),txt);
  updateLabel(&gyroZ, ltrim(txt));
  // Mag
  WordToStr((int)(MPU9150A.mag.x),txt);
  updateLabel(&magX, ltrim(txt));
  IntToStr((int)(MPU9150A.mag.y),txt);
  updateLabel(&magY, ltrim(txt));
  IntToStr((int)(MPU9150A.mag.z),txt);
  updateLabel(&magZ, ltrim(txt));
  //temperature (celsius)
  sprintf(txt, "%.2f", MPU9150A.temp);
  strcat (txt, " °C");
  updateLabel(&lblTemp, ltrim(txt));
}
Beispiel #3
0
void GetEntriesStr(unsigned char *out) {
	unsigned char b[4];
	int n;
	n = EEPROM_Read(0);
	strcpy(out, "Entries: ");
	WordToStr(n, b);
	strcat(out, b);
}
Beispiel #4
0
void DisplayAirQValue( uint16_t value )
{
    if (value_old != value)
    {
        // clear the previous value
        OLED_SetFont( guiFont_Tahoma_8_Regular, OLED_COLOR_WHITE, 0 );
        OLED_WriteText( text, 50, 75 );

        WordToStr(value, text);

        OLED_SetFont( guiFont_Tahoma_8_Regular, OLED_COLOR_BLACK, 0 );
        OLED_WriteText( text, 50, 75 );
    }
    value_old = value;
}
Beispiel #5
0
void DisplayMethaneValue( uint16_t value )
{
    if (value_old != value)                              // If old value and current value are not equal
    {
        // clear the previous value
        OLED_SetFont( guiFont_Tahoma_8_Regular, OLED_COLOR_WHITE, 0 );
        OLED_WriteText( text, 50, 75 );

        WordToStr(value, text);

        OLED_SetFont( guiFont_Tahoma_8_Regular, OLED_COLOR_BLACK, 0 );
        OLED_WriteText( text, 50, 75 );
    }
    value_old = value;
}
// On button right pressed
static void button_right(void)
{
    
    G_LED = 0;                                   // Turn on Green diode
    R_LED = 1;                                   // Turn off Red diode
    PTB_PDOR.B9 = 1;                             // Turn on Vibration
    current_duty = current_duty + STEP;          // Increment current_duty
    if (current_duty > MAX_PWM_VALUE)            // If we increase current_duty greater 
                                                 //  then possible MAX_PWM_VALUE value
    {
        current_duty = MAX_PWM_VALUE;            // Reset current_duty value 
                                                 //  to MAX_PWM_VALUE
    }
    
    // Set newly acquired duty ratio
    PWM_FTM0_Set_Duty(current_duty, _PWM_NON_INVERTED, _PWM_CHANNEL_1);  
    OLED_DrawBox(50, 50, 25, 20, OLED_COLOR_BLACK);
    WordToStr(current_duty, txt_value);          
    OLED_WriteText(txt_value, 50, 50);           // Write text value on screen
    Delay_ms(50);
    PTB_PDOR.B9 = 0;                             // Turn off vibration 
}
// On button left pressed
static void button_left(void)
{

    R_LED = 0;                                   // Turn on Red diode
    G_LED = 1;                                   // Turn off Green diode
    PTB_PDOR.B9 = 1;                             // Turn on vibration
    current_duty = current_duty - STEP;          // Decrement current_duty
    if (current_duty > MAX_PWM_VALUE)            // If we decrease current_duty 
                                                 //  greater then possible
                                                 //  MAX_PWM_VALUE value (overflow)
    {
        current_duty = 0;                        // Set current_duty to 0
    }

    // Set newly acquired duty ratio
    PWM_FTM0_Set_Duty(current_duty, _PWM_NON_INVERTED, _PWM_CHANNEL_1);  
    OLED_DrawBox(50, 50, 25, 20, OLED_COLOR_BLACK);
    WordToStr(current_duty, txt_value);
    OLED_WriteText(txt_value, 50, 50);           // Write text value on screen
    Delay_ms(50);
    PTB_PDOR.B9 = 0;                             // Turn off vibration 
}
Beispiel #8
0
void main(){

Lcd_init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
I2C1_Init(100000);
TRISB.F0=0;
TRISB.F1=0;

while(1){

   Read_Compass();
   WordToStr(angle,to_LCD);
   Lcd_Out(1,1,to_LCD);
   straight();
   // delay_ms(500);
  // Lcd_Out(1,1,"Piyumal");
   //delay_ms(1000);
   
}



}
Beispiel #9
0
//=============================================================================
//  MAIN
//=============================================================================
void main()
{
  //-------------------------------------------------------
  // setup PIC 18F8527 for SmartGLCD pins
  CMCON = 0x07;        // turn off comparators (make all pins digital)
  ADCON0 = 0b00000001;  // ADC module on
  ADCON1 = 0b00001101;  // AN0,AN1 are adc inputs, 0v-5v range
  ADCON2 = 0b00110010;  // ADC result left justified (0-255 range)

  LATA =  0b00000000;
  TRISA = 0b00000011;   // RA0,RA1 analog inputs (TP)
  LATC =  0b00000110;   // LEDs off at start
  TRISC = 0b00000000;   // C1, C2 backlight LED
  LATG =  0b00000001;   // LED off at start
  TRISG = 0b00000000;   // G0 backlight LED
  
  LATJ  = 0b01000000;   // RJ6=FS (1=font6 0=font8), RJ5=MD
  TRISJ = 0b00000000;   // GLCD control port

  BacklightRed    = 1;     // control the GLCD backlight leds; 0=on, 1=off
  BacklightGreen  = 0;     // green ON
  BacklightBlue   = 1;

  T1CON = 0b10110001;   // TMR1 on 16bit, 1:8 prescaler, used for time testing

  //-------------------------------------------------------
  // Initialize T6963C GLCD
  T6963C_init(240, 128, 6);   // init for MikroC PRO version
  //T6963C_init(240, 128, 6, &PORTH, &PORTJ, 2, 1, 0, 4); // init for MikroC version
  T6963C_graphics(1);       // graphics mode = on
  T6963C_text(1);           // text mode = on (now both are on)
  T6963C_cursor(0);         // cursor = off

  Delay_mS(300);

  //-------------------------------------------------------
  // draw stuff on GLCD.
  //-------------------------------------------------------
  
  // do a time test of the MikroE horiz line, this draws a line
  // across the screen and times it in exact uS.
  T6963C_Write_Text("Line drawn with MikroE Line() function", 0, 0, T6963C_ROM_MODE_OR); 

  TMR1H=0;
  TMR1L=0;              // clear TMR1 here
  T6963C_line(0,16,239,16,T6963C_WHITE);    // Draw a MikroE line
  etime = TMR1L;        // read TMR1 here
  etime += (TMR1H << 8);

  WordToStr(etime,txt);    // get the time as text
  T6963C_Write_Text("Time:       uS", 0, 4, T6963C_ROM_MODE_OR);   // display time in uS
  T6963C_Write_Text(txt, 6, 4, T6963C_ROM_MODE_OR);   // display time in uS

  //-------------------------------------------------------
  // now do a time test using my line bytes system, this is a "best case"
  // where all it does is draw bytes (each byte is 6 black pixels)
  // across the screen to make a horizontal line. This is horrible code but
  // it is about as fast as this GLCD can ever get, which is the test.

  T6963C_Write_Text("Line drawn with my functions", 0, 10, T6963C_ROM_MODE_OR); 

  TMR1H=0;
  TMR1L=0;          // clear TMR1 here

  // set first graphic byte to write to (each pixel row across is 40 bytes)
  // y = 40*8*textline = 40*8*12 = 0x0F00
  // this should be put in a function later! RomanSG_Set_Address(address)
  RSG_byte = 0x00;        // low address in graphic ram
  RomanSG_Send_Data();
  RSG_byte = 0x0F;        // hi address in graphic ram
  RomanSG_Send_Data();
  RSG_byte = 0x24;        // command to set ram address pointer
  RomanSG_Send_Command();

  // now loop and draw 40 bytes into graphic ram
  for(i=0; i<40; i++)
  {
    RSG_byte = 0x3F;        // 0b00111111 (6 black pixels to write to graphic ram)
    RomanSG_Send_Data();
    RSG_byte = 0xC0;        // command to write byte to graphic ram and increment ram pointer
    RomanSG_Send_Command();
  }
  etime = TMR1L;        // read TMR1 here
  etime += (TMR1H << 8);
  
  WordToStr(etime,txt);      // get the time as text
  T6963C_Write_Text("Time:       uS", 0, 14, T6963C_ROM_MODE_OR);   // display time in uS
  T6963C_Write_Text(txt, 6, 14, T6963C_ROM_MODE_OR);

  //-------------------------------------------------------
  // delay between test pages
  Delay_mS(3000);
  
  // clear the screen
  T6963C_grFill(0);     // erase graphics
  T6963C_txtFill(0);    // erase text

  //-------------------------------------------------------
  
  
  // do a time test of the MikroE vertical line
  T6963C_Write_Text("Vert line with MikroE Line() function", 0, 0, T6963C_ROM_MODE_OR); 

  TMR1H=0;
  TMR1L=0;              // clear TMR1 here
  T6963C_line(29,0,29,127,T6963C_WHITE);    // Draw a MikroE line
  etime = TMR1L;        // read TMR1 here
  etime += (TMR1H << 8);

  WordToStr(etime,txt);    // get the time as text
  T6963C_Write_Text("Time:       uS", 0, 4, T6963C_ROM_MODE_OR);   // display time in uS
  T6963C_Write_Text(txt, 6, 4, T6963C_ROM_MODE_OR);   // display time in uS

  //-------------------------------------------------------
  
  // and test manual writing of a vertical line by drawing to graphcis ram...
  
  T6963C_Write_Text("Vert line with my functions", 0, 10, T6963C_ROM_MODE_OR); 
  TMR1H=0;
  TMR1L=0;          // clear TMR1 here

  add_lo = 31;
  add_hi = 0;

  // now loop and draw 120 vertical pixels, top down
  for(i=0; i<128; i++)
  {
    // set graphics ram address for this byte
    RSG_byte = add_lo;      // low address in graphic ram
    RomanSG_Send_Data();
    RSG_byte = add_hi;      // hi address in graphic ram
    RomanSG_Send_Data();
    RSG_byte = 0x24;        // command to set ram address pointer
    RomanSG_Send_Command();

    // and make a single black pixel bit in that byte (bit 3 011)
    RSG_byte = 0b11111011;   // command to set a pixel; 1111 colour ppp
    RomanSG_Send_Command();
    
    /*
    T6963C_writeData(add_lo);   // MikroC command functions were twice as slow
    T6963C_writeData(add_hi);
    T6963C_writeCommand(0x24);
    
    T6963C_writeCommand(0b11111011);
    */

    // manually calc the address of the next byte below, is +=40 bytes.
    // manually handle the 16bit address for speed (messy!)
    if(add_lo >= (256-40)) add_hi ++; 
    add_lo += 40;   // is a 16bit +=40
  }
  etime = TMR1L;        // read TMR1 here
  etime += (TMR1H << 8);
  
  WordToStr(etime,txt);      // get the time as text
  T6963C_Write_Text("Time:       uS", 0, 14, T6963C_ROM_MODE_OR);   // display time in uS
  T6963C_Write_Text(txt, 6, 14, T6963C_ROM_MODE_OR);
  
  
  //-------------------------------------------------------
  while(1)
  {
    // just loop and do nothing
  }
}