Пример #1
0
//Main für LCD-Test
int main(void)
{
//u08 a=0;

	// initialize our libraries
	// initialize the UART (serial port)
//	uartInit();
	// make all rprintf statements use uart for output
//	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	//a2dInit();
	// initialize the timer system
	timerInit();
	// print a little intro message so we know things are working
//	rprintf("\r\nWelcome to AVRlib!\r\n");
	
	timer1SetPrescaler(4);
	timerAttach(TIMER1OVERFLOW_INT, lcdPrepare);

	// initialize LCD
	//lcdInit();
	// direct printf output to LCD
//	rprintfInit(lcdDataWrite);

	// print message on LCD
	//rprintf("Welcome to AVRlib!");

	//DDRC = 0x00;
	//PORTC = 0x00;

	// display a bargraph of the analog voltages on a2d channels 0,1
	
	while(1)
	{
	//	lcdGotoXY(0,0);
	//	lcdProgressBar(a2dConvert8bit(0), 255, 20);
	//	rprintf(" X: %d", a2dConvert8bit(0));
	//	rprintf(" Sample: %d", a++);
	//	lcdGotoXY(0,1);
	//	lcdProgressBar(a2dConvert8bit(1), 255, 20);
	//	rprintf(" Y: %d", a2dConvert8bit(1));

		if(lcdPrepared){
			lcdClear();
			lcdGotoXY(0,0);
			rprintf("0. Zeile");
			lcdGotoXY(1,1);
			rprintf("1. Zeile %d",'ü');
			lcdGotoXY(2,2);
			rprintf("2. Zeile");
			lcdGotoXY(3,3);
			rprintf("3. Zeile");
		}
	}

	return 0;
}
Пример #2
0
void initializeCzechAbc()
{
  lcdSetCGRAM(0,uscarkou);
  lcdSetCGRAM(1,rshackem);
  lcdSetCGRAM(2,eshackem);
  lcdSetCGRAM(3,cshackem);
  lcdSetCGRAM(4,iscarkou);
  lcdSetCGRAM(5,ascarkou);
  lcdGotoXY(0,0);
}
Пример #3
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	uint8_t a=0;

	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	a2dInit();
	// initialize the timer system
	timerInit();
	// print a little intro message so we know things are working
	rprintf("\r\nWelcome to AVRlib!\r\n");
	
	// initialize LCD
	lcdInit();
	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print message on LCD
	rprintf("Welcome to AVRlib!");

	DDRA = 0x00;
	PORTA = 0x00;

	// display a bargraph of the analog voltages on a2d channels 0,1
	while(1)
	{
		lcdGotoXY(0,0);
		lcdProgressBar(a2dConvert8bit(0), 255, 20);
		rprintf(" X: %d", a2dConvert8bit(0));
		rprintf(" Sample: %d", a++);
		lcdGotoXY(0,1);
		lcdProgressBar(a2dConvert8bit(1), 255, 20);
		rprintf(" Y: %d", a2dConvert8bit(1));
	}

	return 0;
}
Пример #4
0
void LCDWriteChar(const char data)
{
	if (++lcd_px > LCD_SIZEW) {
		lcd_px = 0;
		if (++lcd_py > LCD_SIZEH) {
			lcd_py = 0;
		}
		lcdGotoXY(lcd_py,lcd_px);
	}
	while (lcdIsBusy()) ;
	lcdRawSendByte(data,LCD_DATA);
}
Пример #5
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	
	// init a few string variables:
	char *welcome_msg1 = "  LC Meter III  ";
	char *welcome_msg2 = "dansworkshop.com";
	char *cal_message1 = "Switch to Cal/C ";
	char *cal_message2 = "for calibration.";
	char *cal_message3 = "calibrating...  ";
	char *blank_lcd_line = "                ";	

	
	// initialize LCD
	lcdInit();


	// init timers and I/O:
	init();
	sei();  // enable global interrupts
	

	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print vanity message on LCD for a second:
	rprintfStr(welcome_msg1);
	lcdGotoXY(0,1);
	rprintfStr(welcome_msg2);
	_delay_ms(1000);
	
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// print a little intro message so we know things are working
	rprintfStr(welcome_msg1);
	rprintf("\r\nhttp://www.");
	rprintfStr(welcome_msg2);
	rprintf("\r\n");


	// instruct about setting mode switch to C for calibration
	if(bit_is_clear(PIND, 4)) {
		rprintfInit(lcdDataWrite);
		lcdGotoXY(0,0);
		rprintfStr(cal_message1);
		lcdGotoXY(0,1);
		rprintfStr(cal_message2);
		
		rprintfInit(uartSendByte);
		rprintfStr(cal_message1);
		rprintfStr(cal_message2);
		rprintf("\r\n");
	}
	while(bit_is_clear(PIND, 4)) {
		// wait for user to switch mode to C
	}
	
	// send out the calibration message:
	rprintfStr(cal_message3);
	rprintf("\r\n");
	rprintfInit(lcdDataWrite);
	lcdGotoXY(0,0);
	rprintfStr(cal_message3);
	lcdGotoXY(0,1);
	rprintfStr(blank_lcd_line);

	rprintfInit(uartSendByte);

	_delay_ms(1600);
	F1 = running;			// get open frequency
	rprintfNum(10, 10, 0, ' ', F1 * 5);
	rprintf("\r\n");
	sbi(PORTD, PD3); 		// energize relay
	_delay_ms(1000);			// stabilize
	F2 = running;			// get test frequency
	rprintfNum(10, 10, 0, ' ', F2 * 5);
	rprintf("\r\n");
	cbi(PORTD, PD3);		// turn off relay
		
	// do some floating point:
	Cs = square(F2 * 5) * (.00000000092 / (square(F1 * 5) - square(F2 * 5))); // this should fit in a 64-bit value
	Ls = 1 / (4 * square(M_PI) * square(F1 * 5) * Cs);
	
	// everything out of the lcd for now:
	rprintfInit(lcdDataWrite);
	

	// enable  PC5 as output
	sbi(DDRC, PC5);
	while (1) {
		_delay_ms(200);
		lcdGotoXY(0,0);
		if(bit_is_clear(PIND, 4)) { // inductance measurement mode
			if(running < 3) {
				rprintf("Not an inductor                 \r");
			} else {
				Lt = (square(F1 * 5) / (square(running * 5)) - 1) * Ls;
				rprintf("Lx: ");
				if(Lt > .0001) {
					rprintfFloat(4, Lt * 1000);
					rprintf("mH");
				}
				
				else if(Lt > .0000001) {
					rprintfFloat(4, Lt * 1000000);
					rprintf("uH");
				}
					
				else {
					rprintfFloat(4, Lt * 1000000000);
					rprintf("nH");
				}
					
				rprintf("             \r");
			}
		} else {					// capacitance measurement mode
			if(running < 300) {
				rprintf("Not a capacitor                 \r");
			} else {
				Ct = (square(F1 * 5) / (square(running * 5)) - 1) * Cs;
				rprintf("Cx: ");
				if(Ct > .0001) {
					rprintfFloat(4, Ct * 1000);
					rprintf("mF");
				}
				
				else if(Ct > .0000001) {
					rprintfFloat(4, Ct * 1000000);
					rprintf("uF");
				}
					
				else if(Ct > .0000000001){
					rprintfFloat(4, Ct * 1000000000);
					rprintf("nF");
				}

				else {
					rprintfFloat(4, Ct * 1000000000000);
					rprintf("pF");
				}
					
				rprintf("             \r");
			}
		}

		if(bit_is_clear(PIND, 7)) {
			lcdGotoXY(0,0);
			rprintf("zeroed                \r");
			lcdGotoXY(0,1);
			rprintfStr(blank_lcd_line);
			lcdGotoXY(0,0);
			F1 = running;
		}

		while(bit_is_clear(PIND, 7)) {
			// do nothing till the user lets go of the zero button
		}

		// display the 
		lcdGotoXY(0,1);
		rprintfNum(10, 6, 0, ' ', running * 5);
		rprintf("Hz        ");

	}


	return 0;
}
Пример #6
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
			}			
		}
	}
}
Пример #7
0
int main(void)
{
  // VARIABLES
  int16_t dsValue; // value actualy get from sensor

  char lcdText[2][17];
  int32_t actualTemp;
  int32_t lastTemp; // value after filtering, without dividing, for trend derminination
  int16_t sampleCounter; // counts samples, for tren derminination
  uint8_t trend;

  // INITIALIZATIONS

  usartInitialization(9600);
  log("Usart initialized\n");

  lcdInitialize();
  log("Lcd initialized\n");

  lcdDisplayOn();
  log("Lcd display on\n");

  dsInitialize(&PORTB,1<<PB2);
  log("Ds initialized\n");

  dsSetResolution(NULL,bit12);
  log("Ds resolution is set\n");

  dsInitializeMovingAverageFilter();
  log("dsInitializeMovingAverageFilter\n");

  sampleCounter = 0;
  trend = DS_TREND_UNDEFINED;


  while(1)
    {
      // start conversion
      if(FALSE==dsStartConversion(NULL))
        {
          errorLcdlog;
        }

      // wait until sample ready
      if( dsWaitForConversionEnd() == FALSE)
        {
          errorLcdlog;
        }

      // read temperature
      if(dsReadTemperature(NULL,&dsValue)==FALSE)
        {
          errorLcdlog;
        }

      // filter value
      actualTemp = dsInsertSample(dsValue);

      // increase sample counter for trend determining
      sampleCounter++;

      if(sampleCounter==DS_TREND_PERIOD)
        {
          sampleCounter = 0;

          // determine trend
          if(lastTemp == -200)
            {
              lastTemp = actualTemp;
            }
          else if(lastTemp<actualTemp)
            {
              trend = DS_TREND_RISING;
            }
          else if(lastTemp>actualTemp)
            {
              trend = DS_TREND_FALLING;
            }
          else
            {
              //trend = DS_TREND_STAGNATING;
            }

            lastTemp = actualTemp;
        }

      // write temperature to th firsth row, other places fill with gap
      //temperatureToString(lcdText[0],actualTemp);
      sprintf(lcdText[0],"Temp: %d",actualTemp/16/25);
      memset(lcdText[strlen(lcdText[0])],' ',16-strlen(lcdText[0]));
      lcdText[0][16] = 0;

      // fill second row with trend
      switch(trend)
        {
        case DS_TREND_FALLING:
          strcpy(lcdText[1],"Trend: falling  ");
          break;

        case DS_TREND_RISING:
          strcpy(lcdText[1],"Trend: rising   ");
          break;

        case DS_TREND_STAGNATING:
          strcpy(lcdText[1],"Trend: no change");
          break;

        case DS_TREND_UNDEFINED:
          strcpy(lcdText[1],"                ");
          break;

        default:
          errorLcdlog;
        }

      // write lcd
      lcdGotoXY(0,0);
      lcdWrite(lcdText[0]);
      lcdGotoXY(0,1);
      lcdWrite(lcdText[1]);

      log(lcdText[0]);
      log(lcdText[1]);

    }

  return 0;
}