//----------------------------------------------------------------- int main(void) { // initialise le LCD lcdInit(); lcdLoadCustomChar((u08*)LcdCustomChar,LCDCHAR_FORWARDARROW,7); lcdClear() ; lcdHome() ; // affiche les textes statiques lcdPrintData(MSG1, strlen(MSG1)) ; while(1) ; }
// //----------------------------------------------------------------------------------------- // 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 } } } }