/* NAME: | LCD_Init PURPOSE: | Initializes the Butterfly's LCD for correct operation, ready to display data ARGUMENTS: | None RETURNS: | None */ void LCD_Init(void) { // Set the initial contrast level to maximum: LCD_CONTRAST_LEVEL(0x0F); // Select asynchronous clock source, enable all COM pins and enable all segment pins: LCDCRB = (1<<LCDCS) | (3<<LCDMUX0) | (7<<LCDPM0); // Set LCD prescaler to give a framerate of 64Hz: LCDFRR = (0<<LCDPS0) | (3<<LCDCD0); // Enable LCD and set low power waveform, enable start of frame interrupt: LCDCRA = (1<<LCDEN) | (1<<LCDAB) | (1<<LCDIE); }
/* NAME: | SET_SetContrast (static) PURPOSE: | Changes the LCD's contrast to the user's preference ARGUMENTS: | None RETURNS: | None */ void SET_SetContrast(void) { uint8_t Contrast = (eeprom_read_byte(&EEPROMVars.LCDContrast) & 0x0F); // Ranges from 0-15 so mask retuns 15 (darkest) on blank EEPROM (0xFF) char Buffer[6]; JoyStatus = JOY_INVALID; // Use an invalid joystick value to force the program to write the // name of the default command onto the LCD for (;;) { if (JoyStatus) { if (JoyStatus & JOY_UP) { if (Contrast < 15) Contrast++; } else if (JoyStatus & JOY_DOWN) { if (Contrast > 1) // Zero is non-visible, so 1 is the minimum Contrast--; } else if (JoyStatus & JOY_LEFT) { eeprom_write_byte(&EEPROMVars.LCDContrast, Contrast); return; } Buffer[0] = 'C'; Buffer[1] = 'T'; Buffer[2] = ' '; MAIN_IntToStr((uint16_t)Contrast, &Buffer[3]); LCD_PutStr(Buffer); LCD_CONTRAST_LEVEL(Contrast); MAIN_WaitForJoyRelease(); } MAIN_MenuSleep(); } }