X-Git-Url: http://git.kpe.io/?p=avr_serial_lcd.git;a=blobdiff_plain;f=serial_lcd.c;h=bef0e8c463f004adf5e54eed0adaaca9be901741;hp=0c8bb10aa85dd36c288d89cb41e623a00e9a65bb;hb=HEAD;hpb=90c5c097702cec99a4e16e2f390325469bb7bf0a diff --git a/serial_lcd.c b/serial_lcd.c index 0c8bb10..bef0e8c 100644 --- a/serial_lcd.c +++ b/serial_lcd.c @@ -11,8 +11,9 @@ ** ** Compilers supported: ** - WinAVR-20071221 (includes avr-libc 1.6 required for proper _delay_us) -** - IAR AVR 4.30 -** - Imagecraft AVR 7 +** - IAR AVR 4.30 and 5.10 +** - Imagecraft AVR 7.16 +** - Codevision AVR 2.02.06 ** ** LICENSE ** See accompaning LICENSE file @@ -24,11 +25,11 @@ #include "serial_lcd.h" #if defined(__GNUC__) -FUSES = { - .low = SUT1, - .high = (unsigned char) (DWEN & WDTON & RSTDISBL & BODLEVEL1 & BODLEVEL2), - .extended = EFUSE_DEFAULT, -}; +//FUSES = { +// .low = SUT1, + // .high = (unsigned char) (DWEN & WDTON & RSTDISBL & BODLEVEL1 & BODLEVEL2), + // .extended = EFUSE_DEFAULT, + //}; #endif // Number of PWM brightness levels supported @@ -39,20 +40,20 @@ FUSES = { #define LCD_ON 0x0C // Clear display command #define LCD_CLR 0x01 -// Set 4 data bits -#define LCD_4_Bit 0x20 -// Set 8 data bits -#define LCD_8_Bit 0x30 -// Set number of lines -#define LCD_4_Line 0x08 +// Set 4 data bits +#define LCD_4_Bit 0x20 +// Set 8 data bits +#define LCD_8_Bit 0x30 +// Set number of lines +#define LCD_4_Line 0x08 // Set 8 data bits #define DATA_8 0x30 -// Set character font -#define LCD_Font 0x04 -// Turn the cursor on -#define LCD_CURSOR_ON 0x02 -// Turn on cursor blink -#define LCD_CURSOR_BLINK 0x01 +// Set character font +#define LCD_Font 0x04 +// Turn the cursor on +#define LCD_CURSOR_ON 0x02 +// Turn on cursor blink +#define LCD_CURSOR_BLINK 0x01 ////// Serial command codes /////// // ASCII control code to set brightness level @@ -93,6 +94,7 @@ static FLASH_DECLARE(const unsigned char ledPwmPatterns[]) = #pragma global_register ledPwmCount:20 sUartRxHead:21 sUartRxTail:22 ledPwmCycling:23 unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling; +// Use avr_compat register variables #else REGISTER_VAR(unsigned char ledPwmCount, "r4", 15); REGISTER_VAR(unsigned char sUartRxHead, "r5", 14); @@ -101,8 +103,16 @@ REGISTER_VAR(unsigned char ledPwmCycling, "r7", 12); #endif #define ledPwmPattern GPIOR0 -#define ledStatus GPIOR1 +#if defined(REGISTER_BIT) #define BIT_led_on REGISTER_BIT(GPIOR1,0) +#define IS_BACKLIGHT_ON() BIT_led_on +#define BACKLIGHT_OFF() BIT_led_on = 0 +#define BACKLIGHT_ON() BIT_led_on = 1 +#else +#define IS_BACKLIGHT_ON() (GPIOR1 & 0x01) +#define BACKLIGHT_OFF() GPIOR1 &= ~0x01 +#define BACKLIGHT_ON() GPIOR1 |= 0x01 +#endif // Function declarations void LcdWriteCmd (unsigned char); @@ -110,8 +120,8 @@ void LcdWriteData (unsigned char); unsigned char LcdBusyWait (void); static unsigned char WaitRxChar (void); -// ImageCraft doesn't support inline functions, so use preprocessor -#if defined(__IMAGECRAFT__) +// ImageCraft/Codevision don't support inline functions, so use preprocessor +#if defined(__IMAGECRAFT__) || defined(__CODEVISIONAVR__) #define LedTimerStop() TCCR0B = 0 // Start with 256 prescaler #define LedTimerStart() TCCR0B = (1<> 8; + ledPwmPos = (brightness * (LED_BRIGHTNESS_LEVELS-1) + (unsigned int) 127) >> 8; // Below is probably not required, but ensures we don't exceed array if (ledPwmPos > LED_BRIGHTNESS_LEVELS - 1) ledPwmPos = LED_BRIGHTNESS_LEVELS - 1; @@ -168,12 +178,12 @@ static inline void LedPwmSetBrightness (unsigned char brightness) { ledPwmCycling = ledPwmPattern; if (ledPwmPos >= LED_BRIGHTNESS_LEVELS-1) { // maximum brightness // don't need PWM for continuously on - if (BIT_led_on) { + if (IS_BACKLIGHT_ON()) { LedTimerStop(); LED_PORT |= (1<