Example #1
0
void Init (void)
{
	PLL_SPEED(BUS_CLOCK_MHZ);

	// Modules that don't require interrupts to be enabled
	qs_init(0, MON12X_BR);

	asm cli;

	// Modules that do require interrupts to be enabled
	//qrf_Init();
	nrf_Init(PRX);

#ifdef USING_FJOY
#warning "Using fjoy"
	fjoy_Init();
	fjoy_CallOnUpdate(fjoy_Callback);

#endif

	lcd_Init(LCD_2004);
	printf("Init Done\n");

	return;
}
Example #2
0
void system_run(void)
{	
	// Inicjacja wyprowadzeñ
	DDR(LCD_CTRLPORT) = (1<<LCD_E | 1<<LCD_RW | 1<<LCD_RS | 1<<LCD_LED); 
	PORT(LCD_CTRLPORT) = ~(1<<LCD_E | 1<<LCD_LED); 
	PORT(SW_PORT) = 1<<SW1 | 1<<SW2;
	// Inicjacja wyœwietlacza
	lcd_Init();
	lcd_SetStatus(LCD_STATUS_DISP);
	// Inicjacja timera systemowego
	TCCR2 = 1<<WGM21 /*CTC*/ | 1<<CS22 | 1<<CS21 | 1<<CS20 /*clk:1024*/;
	OCR2 = 78; // oko³o 10ms
	
	// Przerwania
	TIMSK = 1<<OCIE2 /*porównania z timera 2*/;
	sei();

	// Wyœwietlenie zapytania o jêzyk
	fputs_P(PSTR("S1 - "), lcd_GetFile());
	fputs_P(langsys_GetLangName(0), lcd_GetFile());
	lcd_GoTo(0, 1);
	fputs_P(PSTR("S2 - "), lcd_GetFile());
	fputs_P(langsys_GetLangName(1), lcd_GetFile());
	lcd_Update();
	
	// Oczekiwanie na przycisk 
	
	
	// Wywo³anie aplikacji
	app_run();
}
Example #3
0
/*********************************************************************
*
*       LCD_X_DisplayDriver
*
* Purpose:
*   This function is called by the display driver for several purposes.
*   To support the according task the routine needs to be adapted to
*   the display controller. Please note that the commands marked with
*   'optional' are not cogently required and should only be adapted if
*   the display controller supports these features.
*
* Parameter:
*   LayerIndex - Index of layer to be configured
*   Cmd        - Please refer to the details in the switch statement below
*   pData      - Pointer to a LCD_X_DATA structure
*
* Return Value:
*   < -1 - Error
*     -1 - Command not handled
*      0 - Ok
*/
int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) 
{
   int r;
   (void) LayerIndex;
   (void) pData;

   switch (Cmd) 
   {
      //
      // Required
      //
      case LCD_X_INITCONTROLLER: 
      {
         //
         // Called during the initialization process in order to set up the
         // display controller and put it into operation. If the display
         // controller is not initialized by any external routine this needs
         // to be adapted by the customer...
         //
         // ...
         lcd_Init();
         return 0;
      }
      default:
         r = -1;
   }
   return r;
}
Example #4
0
/*----------------------------------------------------------------------------
  Main Program
 *----------------------------------------------------------------------------*/
int main (void) {
#ifdef __USE_LCD
  uint32_t i;
#endif
  uint32_t ad_avg = 0;
  uint16_t ad_val = 0, ad_val_ = 0xFFFF;

  LED_Init();                                /* LED Initialization            */
  SER_Init();                                /* UART Initialization           */
  ADC_Init();                                /* ADC Initialization            */

#ifdef __USE_LCD
  lcd_Init  ();
  lcd_WrStr("KEIL");
  for (i = 0; i < 10000000; i++);            /* Wait for initial display      */
#endif

  SysTick_Config(SystemCoreClock / 100);     /* Generate interrupt each 10 ms */

  while (1) {                                /* Loop forever                  */

    /* AD converter input                                                     */
    if (AD_done) {                           /* If conversion has finished    */
      AD_done = 0;

      ad_avg += AD_last << 8;                /* Add AD value to averaging     */
      ad_avg ++;
      if ((ad_avg & 0xFF) == 0x10) {         /* average over 16 values        */
        ad_val = (ad_avg >> 8) >> 4;         /* average devided by 16         */
        ad_avg = 0;
      }
    }

    if (ad_val ^ ad_val_) {                  /* AD value changed              */
      ad_val_ = ad_val;

      AD_DbgVal = ad_val;

      sprintf(text, "%04X", ad_val);       /* format text for print out     */
#ifdef __USE_LCD
      lcd_WrStr(text);                       /* write value to LCD            */
#endif
    }

    /* Print message with AD value every second                               */
    if (clock_1s) {
      clock_1s = 0;

      printf("AD value: 0x%s\r\n", text);
    }
  }
Example #5
0
/**
  * @brief  	Main program.
  * @param  	None
  * @retval 	None
  */
int main(void)
{
	/* Configure the system clocks */
	RCC_Configuration();	
	
	/* initialize LCD */
	lcd_Init();		

	lcd_Clear();
	/* print message on LCD */
	lcd_GotoXY(0,0);
	printf("Sharing Tech in");
	lcd_GotoXY(1,0);
	printf("=> ARM Viet Nam");

	while (1)
	{	
		/* Insert delay */
		Delay(100);	
	}
}
/*************************************************************************
 Writes a string or char to the Midas MCCOG21605B6W-SPTLYI LCD display

 Input:   String to display as "Hello World!"

 Return:

*************************************************************************/
void LCD_Write(const char *format, ...){

	va_list aptr;
	int len;
	Int16 ret;

	va_start(aptr, format);
	len = vsprintf(buffer, format, aptr);

	Uint16 startStop = ((CSL_I2C_START) | (CSL_I2C_STOP));
	CSL_Status  status;

	lcd_Init();

	int t;
	Uint16 ustr[sizeof(buffer)+1];
	ustr[0] = 0x40;
	for(t = 0; t < len; t++)
	{
		ustr[t+1] = (Uint16)buffer[t];
	}

	status = I2C_write(ustr, (len <= 16)?(len+1):17, I2C_DISPLAY_ADDRESS, TRUE, startStop, CSL_I2C_MAX_TIMEOUT);
	lcd_Delay();

	if(len > 16) {
		Uint16 l[] = {0x00, 0xC0};
		status = I2C_write(l, 2, I2C_DISPLAY_ADDRESS, TRUE, startStop, CSL_I2C_MAX_TIMEOUT);
		lcd_Delay();

		ustr[16] = 0x40;
		status = I2C_write(ustr+16, len-15, I2C_DISPLAY_ADDRESS, TRUE, startStop, CSL_I2C_MAX_TIMEOUT);
		lcd_Delay();
	}

}
Example #7
0
static void TaskWriteLCD(void *pvParameters) // Write to LCD
{
    (void) pvParameters;

    TickType_t xLastWakeTime;
	/* The xLastWakeTime variable needs to be initialised with the current tick
	count.  Note that this is the only time we access this variable.  From this
	point on xLastWakeTime is managed automatically by the vTaskDelayUntil()
	API function. */
	xLastWakeTime = xTaskGetTickCount();

	uint8_t temperature_print; // true if temperature can be displayed.

    eeprom_read_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray));
    eeprom_read_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray));

    lcd_Init();	// initialise LCD, move cursor to start of top line

    while(1)
    {
    	if(getDateTimeDS1307(&xCurrentTempTime.DateTime))
    	{
			if ( (xCurrentTempTime.Temperature = ReadADCSensors())) // if non 0 then a reading returned.
			{	// trigger a temperature reading

				temperature_print = true;
				xCurrentTempTime.Temperature -= 273.15; // Convert from Kelvin to Celcius

				if( (xCurrentTempTime.Temperature < 65) && (xCurrentTempTime.Temperature > xMaximumTempTime.Temperature)) // check for maximum temp
				// we don't expect the temperature sensor to work above 65C
				{
					xMaximumTempTime = xCurrentTempTime;

					// Now we commit the time and temperature to the EEPROM, forever...
					eeprom_update_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray));
				}

				if( (xCurrentTempTime.Temperature > (-30)) && (xCurrentTempTime.Temperature < xMinimumTempTime.Temperature)) // and check for minimum temp
				// we don't expect the temperature sensor to work below -30C
				{
					xMinimumTempTime = xCurrentTempTime;

					// Now we commit the time and temperature to the EEPROM, forever...
					eeprom_update_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray));
				}
			}
			else temperature_print = false;

			lcd_Locate(0, 0);  // go to the first character of the first LCD line
			switch( xCurrentTempTime.DateTime.tm_wday )
			{
				case SUNDAY:
					lcd_Print_P(PSTR("Sunday   "));
					break;
				case MONDAY:
					lcd_Print_P(PSTR("Monday   "));
					break;
				case TUESDAY:
					lcd_Print_P(PSTR("Tuesday  "));
					break;
				case WEDNESDAY:
					lcd_Print_P(PSTR("Wednesday"));
					break;
				case THURSDAY:
					lcd_Print_P(PSTR("Thursday "));
					break;
				case FRIDAY:
					lcd_Print_P(PSTR("Friday   "));
					break;
				case SATURDAY:
					lcd_Print_P(PSTR("Saturday "));
					break;
				default:
					lcd_Print_P(PSTR("NotMyDay "));
					break;
			}

			// display Day Date/Month/Year
			lcd_Locate(0, 10);              // go to the eleventh character of the first LCD line
			lcd_Printf_P( PSTR("%2u/%2u/%4u"), xCurrentTempTime.DateTime.tm_mday, xCurrentTempTime.DateTime.tm_mon, (xCurrentTempTime.DateTime.tm_year + 1900) );

			// display the current temperature
			lcd_Locate(1, 1);			// LCD cursor to third character of the second LCD line
			if ( temperature_print )	// print the temperature if you got it
				lcd_Printf_P( PSTR("%6.2f"), xCurrentTempTime.Temperature); // print Celcius temperature

			// display the current time
			lcd_Locate(1, 9);             // go to the ninth character of the second LCD line
			lcd_Printf_P(PSTR("%2u:%02u:%02u"),xCurrentTempTime.DateTime.tm_hour, xCurrentTempTime.DateTime.tm_min, xCurrentTempTime.DateTime.tm_sec);

			// display the maximum temperature, time and date
			lcd_Locate(2, 0);          // go to the first character of the third LCD line
			lcd_Printf_P(PSTR("Max%5.1f"),xMaximumTempTime.Temperature);			// print the maximum temperature value

			lcd_Locate(2, 9);          // go to the ninth character of the third LCD line
			lcd_Printf_P(PSTR("%2u:%02u %2u/%2u"),xMaximumTempTime.DateTime.tm_hour, xMaximumTempTime.DateTime.tm_min, xMaximumTempTime.DateTime.tm_mday, xMaximumTempTime.DateTime.tm_mon );

			// display the m temperature, time and date
			lcd_Locate(3, 0);          // go to the first character of the forth LCD line
			lcd_Printf_P(PSTR("Min%5.1f"),xMinimumTempTime.Temperature);			// print the minimum temperature value

			lcd_Locate(3, 9);          // go to the ninth character of the fourth LCD line
			lcd_Printf_P(PSTR("%2u:%02u %2u/%2u"),xMinimumTempTime.DateTime.tm_hour, xMinimumTempTime.DateTime.tm_min, xMinimumTempTime.DateTime.tm_mday, xMinimumTempTime.DateTime.tm_mon );

			if(xCurrentTempTime.DateTime.tm_sec == 0)
			// resume the xTaskWriteRTCRetrograde() task, now that we need to write the analogue hands.
				vTaskResume( xTaskWriteRTCRetrograde );
    	}
//		xSerialPrintf_P(PSTR("LCD: Stack HighWater @ %u\r\n"), uxTaskGetStackHighWaterMark(NULL));
        vTaskDelayUntil( &xLastWakeTime, ( 200 / portTICK_PERIOD_MS ) );
	}
}
Example #8
0
//
//-----------------------------------------------------------------------------------------
// 			Setup Ports, timers, start the works and never return, unless reset
//								by the watchdog timer
//						then - do everything, all over again
//-----------------------------------------------------------------------------------------
//
int main(void)
{
	MCUSR &= ~(1 << WDRF);							// Disable watchdog if enabled by bootloader/fuses
	wdt_disable();

	clock_prescale_set(clock_div_1); 				// with 16MHz crystal this means CLK=16000000

	//------------------------------------------
	// 16-bit Timer1 Initialization
	TCCR1A = 0; //start the timer
	TCCR1B = (1 << CS12); // prescale Timer1 by CLK/256
	// 16000000 Hz / 256 = 62500 ticks per second
	// 16-bit = 2^16 = 65536 maximum ticks for Timer1
	// 65536 / 62500 = ~1.05 seconds
	// so Timer1 will overflow back to 0 about every 1 seconds
	// Timer1val = TCNT1; // get current Timer1 value

	//------------------------------------------
	// Init and set output for LEDS
	LED_DDR = LED;
	LED_PORT = 0;
	
	EXTLED_DDR = EXT_G_LED | EXT_R_LED;				// Init Green and Red LEDs
	EXTLED_PORT = 0;
	
	//------------------------------------------
	// Init Pushbutton input
	ENC_PUSHB_DDR = ENC_PUSHB_DDR & ~ENC_PUSHB_PIN;	// Set pin for input
	ENC_PUSHB_PORT= ENC_PUSHB_PORT | ENC_PUSHB_PIN;	// Set pull up

	//------------------------------------------
	// Set run time parameters to Factory default under certain conditions
	//
	// Enforce "Factory default settings" when firmware is run for the very first time after
	// a fresh firmware installation with a new "serial number" in the COLDSTART_REF #define
	// This may be necessary if there is garbage in the EEPROM, preventing startup
	// To activate, roll "COLDSTART_REF" Serial Number in the PM.h file
	if (eeprom_read_byte(&E.EEPROM_init_check) != R.EEPROM_init_check)
	{
		eeprom_write_block(&R, &E, sizeof(E));		// Initialize eeprom to "factory defaults".
	}
	else
	{
		eeprom_read_block(&R, &E, sizeof(E));		// Load the persistent data from eeprom
	}

   	uint8_t i2c_status = I2C_Init();				// Initialize I2C comms
   	
	lcd_Init();										// Init the LCD

	// Initialize the LCD bargraph, load the bargraph custom characters
	lcd_bargraph_Init();

	//------------------------------------------
	// LCD Print Version and I2C information (6 seconds in total during startup)
	lcdClear();
	lcdGotoXY(0,0);
	lcdPrintData(STARTUPDISPLAY1,strlen(STARTUPDISPLAY1));
	lcdGotoXY(0,1);
	lcdPrintData(STARTUPDISPLAY2,strlen(STARTUPDISPLAY2));
	_delay_ms(300);
	lcdGotoXY(20-strlen(STARTUPDISPLAY3),1);
	lcdPrintData(STARTUPDISPLAY3,strlen(STARTUPDISPLAY3));
	_delay_ms(200);
	lcdGotoXY(20-strlen(STARTUPDISPLAY4),2);
	lcdPrintData(STARTUPDISPLAY4,strlen(STARTUPDISPLAY4));
	_delay_ms(2500);

	lcdGotoXY(0,3);
	lcdPrintData(STARTUPDISPLAY5,strlen(STARTUPDISPLAY5));
	sprintf(lcd_buf,"V%s", VERSION);
	lcdGotoXY(20-strlen(lcd_buf),3);
	lcdPrintData(lcd_buf, strlen(lcd_buf));
	_delay_ms(2000);

	lcdGotoXY(0,3);
	if (i2c_status==1) lcdPrintData("AD7991-0 detected   ",20);
	else if (i2c_status==2) lcdPrintData("AD7991-1 detected   ",20);
	else lcdPrintData("Using built-in A/D  ",20);	// No I2C device detected, 
													// we will be using the builtin 10 bit ADs
													
	if (R.USB_data)									// Enumerate USB serial port, if USB Serial Data enabled
	{
		usb_init();									// Initialize USB communications
		Status&=~USB_AVAILABLE;						// Disable USB communications until checked if actually available
	}
	
	_delay_ms(1000);	
		
	//wdt_enable(WDTO_1S);							// Start the Watchdog Timer, 1 second
	
	encoder_Init();									// Init Rotary encoder

	Menu_Mode = DEFAULT_MODE;						// Power Meter Mode is normal default
	
	Status |= MODE_CHANGE | MODE_DISPLAY;			// Force a Display of Mode Intro when starting up
	
	// Start the works, we're in business
	while (1)
	{
		maintask();									// Do useful stuff
		
		if (R.USB_data)								// Do the below if USB Port has been enabled
		{
			// If USB port is available and not busy, then use it - otherwise mark it as blocked.
			if (usb_configured() && (usb_serial_get_control() & USB_SERIAL_DTR))
			{
				Status |= USB_AVAILABLE;			// Enable USB communications
				EXTLED_PORT |= EXT_G_LED;			// Turn Green LED On
				usb_read_serial();
			}
			else
			{
				Status&=~USB_AVAILABLE;				// Clear USB Available Flag to disable USB communications
				EXTLED_PORT &= ~EXT_G_LED;			// Turn Green LED off, if previously on
			}			
		}
	}
}
/*************************************************************************
 Clear the Midas MCCOG21605B6W-SPTLYI LCD display

 Input:

 Return:

*************************************************************************/
void LCD_Clear() {
	lcd_Init();
}