Beispiel #1
0
/*
    Initializes the OLED for debugging purposes
*/
void beginMyOled(){
   DelayInit();
   OledInit();

   OledSetCursor(0, 0);
   OledClearBuffer();
   OledUpdate();
}
Beispiel #2
0
//---------------------------------------------------------------------------
void SysInit(void)
{
	power_timer2_disable();
	power_adc_disable();
	power_twi_disable();
	power_usart0_disable();
	power_usart1_disable();

	OledInit();
	FrameInit();
	SndInit();
	EepInit();
	KeyInit();
	MathInit();
	RndInit();
	DebugInit();
}
Beispiel #3
0
//----------------------------------------------------------------------------------------
// Display on   Datasheet Rev.2.1 Page 29: "8.9 Power ON and OFF sequence"
//----------------------------------------------------------------------------------------
void DisplayOn(void)
{
  DDRC  = 0b00000110;
  DDRB  = 0b00000110;

  OLED_RES_LO;               // Reset
  _delay_us(10);
  OLED_RES_HI;

  OledInit();

  OLED_LOAD_HI;              // 100 Ohm to GND
  OLED_12V_HI;               // Vcc 12V on
  _delay_ms(40);             // wait until VCC stable
  OLED_LOAD_LO;              // disconnect 100 Ohm to GND
  write_cmd(0xAF);           // Set Display ON
  DisplayOnOff = 1;
}
Beispiel #4
0
int main(void)
{
    BOARD_Init();

    // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer
    // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer.
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, BOARD_GetPBClock() / 16 / 100);

    // Set up the timer interrupt with a medium priority of 4.
    INTClearFlag(INT_T2);
    INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_T2, INT_ENABLED);

    /******************************************************************************
     * Your code goes in between this comment and the following one with asterisks.
     *****************************************************************************/
    OledInit();
    MorseInit();
    while (1) {
        if (mflag) {
            if (mevent == MORSE_EVENT_DOT) {
                MorseDecode(MORSE_CHAR_DOT);
            } else if (mevent == MORSE_EVENT_DASH) {
                MorseDecode(MORSE_CHAR_DASH);
            } else if (mevent == MORSE_EVENT_INTER_LETTER) {
                templet[0] = MorseDecode(MORSE_CHAR_END_OF_CHAR);
            } else if (mevent == MORSE_EVENT_INTER_WORD) {
                MorseDecode(MORSE_CHAR_DECODE_RESET);
            }
            updateScreen();
            mevent = 0;
            mflag = 0;
        }
    }


    /******************************************************************************
     * Your code goes in between this comment and the preceding one with asterisks.
     *****************************************************************************/
    while (1);
}
Beispiel #5
0
int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();


    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }
    extern void T1Setup();
    extern void T1Stop();
    extern void T1Start();

    // Enable LED outputs 0-7 by setting TRISE register
    TRISECLR = 0x00FF;
    // Initialize the PORTE to 0
    PORTECLR = 0x00FF;
    // Set the lowest bit
    PORTESET = 1;

    OledInit();
    OledDisplayOn();
    printf("Starting Timer Set-up\n");
    T1Setup();

    int stopped = 0, reset = 0;

    extern volatile int milliseconds;
    int temp = 0;
    int count = 0;
    printTime(0, 0);
    while(1) {
        // Display the least significant part of the time for debugging
       int x = PORTD & 0xfff;
       if(x == 272) {
           if(stopped) {
               stopped = 0;
               T1Start();
           }
           if(reset)
               reset = 0;
        if(milliseconds - temp >= 1000) {
            count++;
            int minutes = count/60;
            int seconds = count % 60;
            printTime(minutes,seconds);
            temp = milliseconds;
        }
       }
       else if(x == 784 || x == 528) {
           if(reset != 1) {
             printTime(0, 0);
             T1Stop();
             stopped = 1;
             reset = 1;
             count = 0;
          }

       }
       else {
           stopped = 1;
           continue;
       }

    }

}
Beispiel #6
0
/***	void IOShieldOledClass::begin(void)
**
**	Parameters:
**		none
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		Initialize the OLED display controller and turn the display on.
*/
void IOShieldOledClass::begin(void)
{
	OledInit();
}
Beispiel #7
0
int main(void)
{   port_init();
	OledInit ();
	timer1_init();
	adc_init();
	USART_Init(0x08);
	_delay_ms(10);
	
    while(1)
    { 
		USART_Receive();//读取串口数据
		Battery_voltage=adc_read(6)/102.40;
		if (RX_Flag==1) //如果有新数据
		{   RX_Flag=0;
			TX_Data=RX_Data;
			
			bb++;
		    USART_Transmit(TX_Data);	//发送串口数据
		}
		
	rest(RX_Data);
	if ((RX_Data==0x00)||(Battery_voltage<7.0))	
	{ off_servo();
	  if (Battery_voltage<7.0){DisplayChar_16X08(36,2,"~(zzz)~") ;}
	  else{DisplayChar_16X08(36,2,"~(@o@)~") ;	 }
	}
	
if ((Battery_voltage>8.0)&&(!(RX_Data==0x00)))
	{DisplayChar_16X08(36,2,"~(^o^)~") ;	 
	}
else if ((Battery_voltage>7.0)&&(!(RX_Data==0x00)))
{DisplayChar_16X08(36,2,"~(=o=)~") ;	
}
		
			
	if (RX_Data==0x01)//站立
	{ open_servo();
	  robot_stand(0,-90);
	}
	if (RX_Data==0x02)//左转
	{robot_move(0,0,40,-90,90,100);}
	if (RX_Data==0x03)//右转
	{ robot_move(0,0,-40,-90,90,100);}	
	if (RX_Data==0x04)//前进
	{ robot_move(0,40,0,-90,90,100);}	
    if (RX_Data==0x05)//后退
	{robot_move(0,-40,0,-90,90,100);}
	 if (RX_Data==0x06)//
	 {robot_Sur_Place(1,-90,90,100);}
	 if (RX_Data==0x07)//
	 {robot_move(40,0,0,-90,90,100);}
	 if (RX_Data==0x08)//
	 {robot_move(40,0,0,-90,90,100);}
	 if (RX_Data==0x09)//
	 {robot_move(20,20,0,-90,90,100);}
		
		
		//DisplayChar_16X08(36,2,"~(@o@)~") ;	 	 
	
     Cache_MDigit5(RX_Data,6,0,1 );Cache_MDigit5(Battery_voltage*100,6,88,1 );
		
		// OledDispPicture(0,32,64,512,Expression1);//爱心
	 //   OledDispPicture(0,26,75,600,Expression2);//笑脸
        //TODO:: Please write your application code
		//time_seve++; 
    }
}
Beispiel #8
0
int main() {

    char t[2];
    char pos[2];
    DelayInit();                             //initializations and state resets
    OledInit();
    Timer2Init();
    initLEDs();
    initButtons();
    initRotary();
    setLEDstate(0);
    unsigned int time = 0;

    OledClearBuffer();                        //the OLED is cleared
    OledSetCursor(0, 0);                      //OLED cursor reset to first line
    OledPutString("ECE 2534 Lab 2");          //message displayed
    OledSetCursor(0, 1);                      //cursor moves to second line
    OledPutString("Thomas Yu");               //message displayed
    OledSetCursor(0, 2);                      //cursor moves to third
    OledPutString("LOCKED");                  //message displayed
    OledSetCursor(0, 3);                      //cursor moves to third
    OledPutString("0");                       //message displayed
    OledUpdate();

    while (1)
    {
        OledSetCursor(0, 3);                      //cursor moves to third
        sprintf(pos, "%-2d", state);              //state(int) converted to string
        OledPutString(pos);                       //message displayed
        OledUpdate();

        if (go == 1)
        {
            sec1000 = 0;                          //time reset
            while (sec1000 < 15000)               //increments for 15000 ms, or 15 secs
            {
                OledSetCursor(0, 3);                      //cursor moves to third
                sprintf(pos, "%-2d", state);
                OledPutString(pos);                       //current state updated
                OledUpdate();

                OledSetCursor(14,3);                        //the countdown is updated
                sprintf(t, "%-2u", (15 - (sec1000/1000)));  //the current time left in seconds is the
                OledPutString(t);                           //elapsed ms subtracted from 15000
                OledUpdate();

                if (unlocked == 1)
                {
                    setLEDstate(1);                         //if unlocked then the led is turned on
                    OledSetCursor(14,3);
                    OledPutString("  ");                    //the countdown is cleared
                    OledSetCursor(0,2);
                    OledPutString("OPEN  ");                //open is displayed
                    OledUpdate();

                    while (!getButtonState())               //this runs until button1 is pressed
                    {
                        OledSetCursor(0, 3);                // this block of code continues to update
                        sprintf(pos, "%-2d", state);        //the rotary position as it is moved
                        OledPutString(pos);                       
                        OledUpdate();
                    }

                    OledSetCursor(0,2);                     //after button1 is pressed, the lock is reset
                    OledPutString("LOCKED");
                    setLEDstate(0);
                    go = 0;
                    unlocked = 0;
                    r1 = 0;
                    lock = 0;
                }
            }

            if ( go != 0)                             //if go was never set back to zero, then the
            {                                         //correct combination was never entered
                unsigned int a = sec1000;             //and the timer ran out
                while (sec1000 < a + 1000)            //this while loop runs for 1 second
                {
                    OledSetCursor(7,3);               //Time Out! is displayed for the duration
                    OledPutString("Time Out!");
                    OledUpdate();
                }
                OledSetCursor(7,3);                   //Time Out! is cleared and the lock is reset
                OledPutString("         ");
                OledUpdate();
                go = 0;
                r1 = 0;
                lock = 0;
            }
            
        }
    }


   return 0;
}
Beispiel #9
0
int main()
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(F_SYS, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(F_SYS);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4th the CPU frequency, so 20MHz.
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer
    // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer.
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, F_PB / 16 / 100);

    // Set up the timer interrupt with a medium priority of 4.
    INTClearFlag(INT_T2);
    INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_T2, INT_ENABLED);

/******************************** Your custom code goes below here ********************************/
    int check;
    OledInit();
    AdcInit();
    LEDS_INIT();
    check = GameInit();

    if(check == STANDARD_ERROR) {
        FATAL_ERROR();
    }
    float currPage;
    float binSize;
    float titleSize;
    float descSize;
    float numPages;
    uint8_t roomExit;
    uint16_t adcValue = 0;

    while(1) {
        roomExit = GameGetCurrentRoomExits();
        LEDS_SET(roomExit);
        while(buttonEvents == 0) {
            descSize = GameGetCurrentRoomDescription(roomData.description);
            titleSize = GameGetCurrentRoomTitle(roomData.title);

            numPages = ((titleSize + descSize) / MAX_OLED_PIXELS);
            binSize = (ADC_MAX_VALUE / numPages);

            if(AdcChanged()) {
                adcValue = AdcRead();
            }

            currPage = (adcValue / binSize);
            if(currPage < 1) {
                char titleArray[TITLE_OLED_SPACE] = {0};
                char descriptionBuffer[FIRST_PG_DESCRIPTION_OLED_SPACE] = {0};

                strncpy(descriptionBuffer, roomData.description, DESCRIPTION_COPY);
                sprintf(titleArray, "%s\n%s", roomData.title, descriptionBuffer);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(titleArray);
            } else {
                char buffer[MAX_OLED_PIXELS] = {0};
                int buffIndex;
                buffIndex = (int)currPage * MAX_OLED_PIXELS;
                strncpy(buffer, (roomData.description + buffIndex - OFFSET), MAX_OLED_PIXELS);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(buffer);
            }
            OledUpdate();
        }

        if((buttonEvents & BUTTON_EVENT_4UP) && (roomExit & GAME_ROOM_EXIT_NORTH_EXISTS)) {
            GameGoNorth();
        } else if((buttonEvents & BUTTON_EVENT_3UP) && (roomExit & GAME_ROOM_EXIT_EAST_EXISTS)) {
            GameGoEast();
        } else if((buttonEvents & BUTTON_EVENT_2UP) && (roomExit & GAME_ROOM_EXIT_SOUTH_EXISTS)) {
            GameGoSouth();
        } else if((buttonEvents & BUTTON_EVENT_1UP) && (roomExit & GAME_ROOM_EXIT_WEST_EXISTS)) {
            GameGoWest();
        }
        buttonEvents = BUTTON_EVENT_NONE;
    }



/**************************************************************************************************/
    while (1);
}