20080319 release: CV support
authorKevin Rosenberg <kevin@rosenberg.net>
Wed, 19 Mar 2008 18:45:49 +0000 (12:45 -0600)
committerKevin Rosenberg <kevin@rosenberg.net>
Wed, 19 Mar 2008 18:45:49 +0000 (12:45 -0600)
ChangeLog
Makefile
README
cv_c/Makefile [new file with mode: 0644]
cv_c/serial_lcd.prj [new file with mode: 0644]
cv_c/serlcd_cv.prj [deleted file]
icc_c/Makefile
serial_lcd.c
serial_lcd.h

index 8c13117de624b3782120f55224cd36cb340dc119..9dad81f761e89fbc0d198e6118a5f0845edb14e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2008-03-18  Kevin Rosenberg <kevin@rosenberg.net>\r
+       * Add Codevision port \r
+\r
 2008-03-15  Kevin Rosenberg <kevin@rosenberg.net>\r
        * serial_lcd.c: Add 4-bit interface mode\r
        * serial_lcd.h: Move LCD control codes here with renaming.  Use\r
index 688d777152fb66c000d46380bbdaa0ec2a604d35..bbbb7ef6fd53b4aadecc0389f29baea6afe3f3c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ date := $(shell date +"%Y%m%d")
 .PHONY: all\r
 all: build\r
 \r
+PROJECT := serial_lcd\r
 tester := tester/serial_lcd_tester\r
 \r
 tester-build: $(tester).exe\r
@@ -45,6 +46,7 @@ clean:
        $(MAKE) -C iar_cpp_obj clean\r
        $(MAKE) -C iar_cpp_obj clean\r
        $(MAKE) -C icc_c clean\r
+       @rm -f *~\r
 \r
 .PHONY: distclean\r
 distclean: \r
diff --git a/README b/README
index 1c15365d1b6e1125b599a8dcbf60a0e029aedab2..1db3974609827208acd7a36aa1396454f123e2ab 100644 (file)
--- a/README
+++ b/README
@@ -38,18 +38,19 @@ The code can be modified and redistributed as governed by the terms of
 the accompaning LICENSE file.\r
 \r
 \r
-Code/Data Sizes (for 20080316 release)\r
+Code/Data Sizes (for 20080318 release)\r
 ======================================\r
 \r
 Compiler    Code  Data  Notes\r
 ---------   ----  ----  -----\r
-AVR-GCC C    718    48  -Os\r
+AVR-GCC C    716    48  -Os\r
 AVR-GCC C++  806    50  -Os\r
 AVR-GCC Obj 1574    72  -Os\r
+CV 2.02.6    808    48  Maximum size optimization\r
 IAR C        622    48  Size optimization high (+ 64 bytes stack)\r
 IAR C++      762    49  Size optimization high (+ 64 bytes stack)\r
 IAR Obj     1112    65  Size optimization high (+ 63 bytes stack)\r
-ICC7 C       818    48  Full optimizations\r
+ICC7 C Pro   812    48  Full optimizations (-O24)\r
 \r
 I would appreciate submissions of suggestions, improvements, or bug\r
 fixes.\r
diff --git a/cv_c/Makefile b/cv_c/Makefile
new file mode 100644 (file)
index 0000000..4c6d9e1
--- /dev/null
@@ -0,0 +1,15 @@
+PROJECT := serial_lcd\r
+\r
+.PHONY: clean\r
+clean:\r
+       @rm -rf $(PROJECT).str1 $(PROJECT).sym[0-9] $(PROJECT).cof \\r
+       $(PROJECT).a $(PROJECT).o *~ Obj Linker\r
+# Clean up Codevision files in source directory\r
+       @rm -f ../$(PROJECT).c@ ../$(PROJECT).c! ../$(PROJECT).h! \\r
+       ../$(PROJECT).i ../$(PROJECT).inc ../$(PROJECT).sym \\r
+       ../$(PROJECT).hdr $(PROJECT).txt *~ $(PROJECT).fct\r
+\r
+.PHONY: distclean\r
+distclean: clean\r
+       @rm -rf $(PROJECT).map Exe List\r
+\r
diff --git a/cv_c/serial_lcd.prj b/cv_c/serial_lcd.prj
new file mode 100644 (file)
index 0000000..78eab68
--- /dev/null
@@ -0,0 +1,251 @@
+[Project]\r
+Toolset=AVR\r
+FormatVersion=2\r
+Files=1\r
+OpenedFiles=0\r
+Top0=430\r
+Left0=711\r
+Height0=339\r
+Width0=497\r
+Active0=1\r
+State0=0\r
+OF1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c\r
+Top1=257\r
+Left1=268\r
+Height1=339\r
+Width1=497\r
+Row1=0\r
+Collumn1=0\r
+Active1=0\r
+State1=0\r
+OF2=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.h\r
+Top2=257\r
+Left2=268\r
+Height2=339\r
+Width2=497\r
+Row2=114\r
+Collumn2=21\r
+Active2=1\r
+State2=0\r
+OF3=c:\cvavreval\inc\tiny2313.h\r
+Top3=197\r
+Left3=133\r
+Height3=339\r
+Width3=497\r
+Row3=84\r
+Collumn3=3\r
+Active3=1\r
+State3=0\r
+OutputListFilesDirectory=List\r
+OutputObjectFilesDirectory=Obj\r
+OutputExecutableFilesDirectory=Exe\r
+OutputLinkerFilesDirectory=Linker\r
+AllowDisplayFunctionCallTree=0\r
+F1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c\r
+[Compiler]\r
+Chip=ATtiny2313\r
+CPUClock=14745600\r
+MemoryModel=0\r
+OptimizeSize=1\r
+OptimizationLevel=2\r
+PrintfFeatures=1\r
+ScanfFeatures=0\r
+DataStackSize=64\r
+PgmMemSize=2048\r
+RAMStart=96\r
+RAMEnd=223\r
+XRAMSize=0\r
+XRAMWaitState=0\r
+HeapSize=0\r
+ExternalInterruptVectors=0\r
+InterruptVectorsNumber=19\r
+InterruptVectorJump=0\r
+ResetVector=0\r
+PromoteCharToInt=0\r
+CharIsUnsigned=1\r
+8BitEnums=1\r
+EnhancedCoreInstructions=1\r
+AutomaticRegisterAllocation=1\r
+SmartRegisterAllocation=1\r
+WordAlignFLASHStructMembers=0\r
+PreprocessorOutput=1\r
+ExternalStartupFile=0\r
+ExternalStartupFileWarning=0\r
+BitVariablesSize=24\r
+UseHiGPIORbit=0\r
+StackEndMarkers=0\r
+Warnings=1\r
+WarningConstantRange=0\r
+WarningPossibleLossOfPrecision=0\r
+WarningArrayIndex=1\r
+WarningGlobalVariableAddress=1\r
+WarningInterruptVector=1\r
+WarningUninitializedFLASH=1\r
+WarningUninitializedEEPROM=1\r
+WarningSuspiciousPointerConversion=1\r
+WarningRegisterAllocated=1\r
+WarningMacroRedefined=1\r
+WarningFunctionReturn=1\r
+WarningUnreferencedFunction=1\r
+WarningUnreferencedFunctionParameter=1\r
+WarningUnreferencedLocalVariable=1\r
+WarningUnreferencedGlobalVariable=1\r
+WarningUnreferencedLabel=1\r
+WarningEmptyLine=1\r
+WarningExpressionHasNoEffect=1\r
+WarningUnknownEscapeSequence=1\r
+WarningShiftResult0=1\r
+Warning8BitAdditionOverflow=1\r
+Warning8BitMultiplicationOverflow=1\r
+Warning16BitAdditionOverflow=1\r
+Warning16BitMultiplicationOverflow=1\r
+WarningPossiblyIncorrectAssignment=1\r
+WarningPointlessComparison=1\r
+WarningConstCtrlExpr=1\r
+WarningUndefinedSymbol=1\r
+WarningCantAllocVarToReg=1\r
+WarningDataStackUsage=1\r
+WarningDataStackRecursion=1\r
+WarningHardwareStackLow=1\r
+DebugBootLoader=0\r
+Build=4\r
+UseEEPROMLocation0=1\r
+IncludePath0=\r
+IncludePath1=\r
+IncludePath2=\r
+IncludePath3=\r
+IncludePath4=\r
+IncludePath5=\r
+IncludePath6=\r
+IncludePath7=\r
+IncludePath8=\r
+IncludePath9=\r
+IncludePath10=\r
+IncludePath11=\r
+IncludePath12=\r
+IncludePath13=\r
+IncludePath14=\r
+IncludePath15=\r
+IncludePath16=\r
+IncludePath17=\r
+IncludePath18=\r
+IncludePath19=\r
+IncludePath20=\r
+IncludePath21=\r
+IncludePath22=\r
+IncludePath23=\r
+IncludePath24=\r
+IncludePath25=\r
+IncludePath26=\r
+IncludePath27=\r
+IncludePath28=\r
+IncludePath29=\r
+IncludePath30=\r
+IncludePath31=\r
+LibraryPath0=\r
+LibraryPath1=\r
+LibraryPath2=\r
+LibraryPath3=\r
+LibraryPath4=\r
+LibraryPath5=\r
+LibraryPath6=\r
+LibraryPath7=\r
+LibraryPath8=\r
+LibraryPath9=\r
+LibraryPath10=\r
+LibraryPath11=\r
+LibraryPath12=\r
+LibraryPath13=\r
+LibraryPath14=\r
+LibraryPath15=\r
+LibraryPath16=\r
+LibraryPath17=\r
+LibraryPath18=\r
+LibraryPath19=\r
+LibraryPath20=\r
+LibraryPath21=\r
+LibraryPath22=\r
+LibraryPath23=\r
+LibraryPath24=\r
+LibraryPath25=\r
+LibraryPath26=\r
+LibraryPath27=\r
+LibraryPath28=\r
+LibraryPath29=\r
+LibraryPath30=\r
+LibraryPath31=\r
+RebuildAll=0\r
+LinkageInformationPresent=1\r
+GlobalConstInFlash=1\r
+ClearGlobalVarsStartup=0\r
+WarningFunctionParameterName=1\r
+WarningLocalVariableSetNotUsed=1\r
+WarningVariableUsedNotSet=1\r
+WarningTypeQualifierMeaningless=1\r
+WarningExplicitTypeMissing=1\r
+WarningEnumType=1\r
+WarningTypedefName=1\r
+WarningTypedefRedeclared=1\r
+WarningExtraBraces=1\r
+WarningIncompatibleAssignment=1\r
+WarningIncompatibleInit=1\r
+WarningIncompatibleOperandsTernary=1\r
+WarningIncompatibleFunctionArgument=1\r
+WarningIncompatibleFunctionReturn=1\r
+WarningMemoryAttributeIgnored=1\r
+WarningPragmaVector=1\r
+WarningCOFFArrayDim=1\r
+WarningCOFFDataComplex=1\r
+LinkerWarnings=1\r
+[DefinedSymbols]\r
+Count=0\r
+[Assembler]\r
+OutputFormat=1\r
+TerminalIO=0\r
+[AfterMake]\r
+ProgrammChip=0\r
+MergeROMFile=0\r
+ROMFilePath=\r
+SCKFrequency=230400\r
+LockBits=0\r
+BootLockBits0=0\r
+BootLockBits1=0\r
+ProgramFuseBits=1\r
+Fuse1=0\r
+Fuse2=0\r
+Fuse3=0\r
+Fuse4=0\r
+Fuse5=0\r
+Fuse6=0\r
+Fuse7=0\r
+Fuse8=0\r
+Fuse9=0\r
+Fuse10=0\r
+Fuse11=0\r
+Fuse12=0\r
+Fuse13=0\r
+Fuse14=0\r
+Fuse15=0\r
+Fuse16=0\r
+Fuse17=0\r
+Fuse18=0\r
+Fuse19=0\r
+Fuse20=0\r
+Fuse21=0\r
+Fuse22=0\r
+Fuse23=0\r
+Fuse24=0\r
+CheckSignature=1\r
+CheckErasure=1\r
+PreserveEEPROM=0\r
+VerifyProgramming=1\r
+ProgrammingCounter=0\r
+RunUserProg=0\r
+UserProgPath=\r
+UserProgCmdLine=\r
+UserProgWorkDir=\r
+[BeforeMake]\r
+RunUserProg=0\r
+UserProgPath=\r
+UserProgCmdLine=\r
+UserProgWorkDir=\r
diff --git a/cv_c/serlcd_cv.prj b/cv_c/serlcd_cv.prj
deleted file mode 100644 (file)
index 2a35dbe..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-[Project]\r
-Toolset=AVR\r
-FormatVersion=2\r
-Files=1\r
-OpenedFiles=3\r
-Top0=430\r
-Left0=711\r
-Height0=339\r
-Width0=497\r
-Active0=0\r
-State0=0\r
-OF1=c:\home\kevin\src\avr\serial_lcd\serial_lcd.c\r
-Top1=151\r
-Left1=84\r
-Height1=509\r
-Width1=614\r
-Row1=135\r
-Collumn1=0\r
-Active1=0\r
-State1=0\r
-OF2=C:\home\kevin\src\avr\serial_lcd\serial_lcd.h\r
-Top2=257\r
-Left2=268\r
-Height2=339\r
-Width2=497\r
-Row2=0\r
-Collumn2=0\r
-Active2=0\r
-State2=0\r
-F1=C:\home\kevin\src\avr\serial_lcd\serial_lcd.c\r
-OF3=c:\cvavreval\inc\tiny2313.h\r
-Top3=197\r
-Left3=133\r
-Height3=339\r
-Width3=497\r
-Row3=84\r
-Collumn3=3\r
-Active3=1\r
-State3=0\r
-[Compiler]\r
-Chip=ATtiny2313\r
-CPUClock=14745600\r
-MemoryModel=0\r
-OptimizeSize=1\r
-OptimizationLevel=2\r
-PrintfFeatures=1\r
-ScanfFeatures=0\r
-DataStackSize=64\r
-PgmMemSize=2048\r
-RAMStart=96\r
-RAMEnd=223\r
-XRAMSize=0\r
-XRAMWaitState=0\r
-HeapSize=0\r
-ExternalInterruptVectors=0\r
-InterruptVectorsNumber=19\r
-InterruptVectorJump=0\r
-ResetVector=0\r
-PromoteCharToInt=0\r
-CharIsUnsigned=1\r
-8BitEnums=1\r
-EnhancedCoreInstructions=1\r
-AutomaticRegisterAllocation=1\r
-SmartRegisterAllocation=1\r
-WordAlignFLASHStructMembers=0\r
-PreprocessorOutput=1\r
-ExternalStartupFile=0\r
-ExternalStartupFileWarning=0\r
-BitVariablesSize=8\r
-UseHiGPIORbit=0\r
-StackEndMarkers=0\r
-Warnings=1\r
-WarningConstantRange=0\r
-WarningPossibleLossOfPrecision=0\r
-WarningArrayIndex=1\r
-WarningGlobalVariableAddress=1\r
-WarningInterruptVector=1\r
-WarningUninitializedFLASH=1\r
-WarningUninitializedEEPROM=1\r
-WarningSuspiciousPointerConversion=1\r
-WarningRegisterAllocated=1\r
-WarningMacroRedefined=1\r
-WarningFunctionReturn=1\r
-WarningUnreferencedFunction=1\r
-WarningUnreferencedFunctionParameter=1\r
-WarningUnreferencedLocalVariable=1\r
-WarningUnreferencedGlobalVariable=1\r
-WarningUnreferencedLabel=1\r
-WarningEmptyLine=1\r
-WarningExpressionHasNoEffect=1\r
-WarningUnknownEscapeSequence=1\r
-WarningShiftResult0=1\r
-Warning8BitAdditionOverflow=1\r
-Warning8BitMultiplicationOverflow=1\r
-Warning16BitAdditionOverflow=1\r
-Warning16BitMultiplicationOverflow=1\r
-WarningPossiblyIncorrectAssignment=1\r
-WarningPointlessComparison=1\r
-WarningConstCtrlExpr=1\r
-WarningUndefinedSymbol=1\r
-WarningCantAllocVarToReg=1\r
-WarningDataStackUsage=1\r
-WarningDataStackRecursion=1\r
-WarningHardwareStackLow=1\r
-DebugBootLoader=0\r
-Build=5\r
-UseEEPROMLocation0=1\r
-IncludePath0=\r
-IncludePath1=\r
-IncludePath2=\r
-IncludePath3=\r
-IncludePath4=\r
-IncludePath5=\r
-IncludePath6=\r
-IncludePath7=\r
-IncludePath8=\r
-IncludePath9=\r
-IncludePath10=\r
-IncludePath11=\r
-IncludePath12=\r
-IncludePath13=\r
-IncludePath14=\r
-IncludePath15=\r
-IncludePath16=\r
-IncludePath17=\r
-IncludePath18=\r
-IncludePath19=\r
-IncludePath20=\r
-IncludePath21=\r
-IncludePath22=\r
-IncludePath23=\r
-IncludePath24=\r
-IncludePath25=\r
-IncludePath26=\r
-IncludePath27=\r
-IncludePath28=\r
-IncludePath29=\r
-IncludePath30=\r
-IncludePath31=\r
-LibraryPath0=\r
-LibraryPath1=\r
-LibraryPath2=\r
-LibraryPath3=\r
-LibraryPath4=\r
-LibraryPath5=\r
-LibraryPath6=\r
-LibraryPath7=\r
-LibraryPath8=\r
-LibraryPath9=\r
-LibraryPath10=\r
-LibraryPath11=\r
-LibraryPath12=\r
-LibraryPath13=\r
-LibraryPath14=\r
-LibraryPath15=\r
-LibraryPath16=\r
-LibraryPath17=\r
-LibraryPath18=\r
-LibraryPath19=\r
-LibraryPath20=\r
-LibraryPath21=\r
-LibraryPath22=\r
-LibraryPath23=\r
-LibraryPath24=\r
-LibraryPath25=\r
-LibraryPath26=\r
-LibraryPath27=\r
-LibraryPath28=\r
-LibraryPath29=\r
-LibraryPath30=\r
-LibraryPath31=\r
-[DefinedSymbols]\r
-Count=0\r
-[Assembler]\r
-OutputFormat=1\r
-TerminalIO=0\r
-[AfterMake]\r
-ProgrammChip=0\r
-MergeROMFile=0\r
-ROMFilePath=\r
-SCKFrequency=230400\r
-LockBits=0\r
-BootLockBits0=0\r
-BootLockBits1=0\r
-ProgramFuseBits=1\r
-Fuse1=0\r
-Fuse2=0\r
-Fuse3=0\r
-Fuse4=0\r
-Fuse5=0\r
-Fuse6=0\r
-Fuse7=0\r
-Fuse8=0\r
-Fuse9=0\r
-Fuse10=0\r
-Fuse11=0\r
-Fuse12=0\r
-Fuse13=0\r
-Fuse14=0\r
-Fuse15=0\r
-Fuse16=0\r
-Fuse17=0\r
-Fuse18=0\r
-Fuse19=0\r
-Fuse20=0\r
-Fuse21=0\r
-Fuse22=0\r
-Fuse23=0\r
-Fuse24=0\r
-CheckSignature=1\r
-CheckErasure=1\r
-PreserveEEPROM=0\r
-VerifyProgramming=1\r
-ProgrammingCounter=0\r
-RunUserProg=0\r
-UserProgPath=\r
-UserProgCmdLine=\r
-UserProgWorkDir=\r
-[BeforeMake]\r
-RunUserProg=0\r
-UserProgPath=\r
-UserProgCmdLine=\r
-UserProgWorkDir=\r
index 05bb2e11d7b31f9adf247a89c1d61dd7d4d3744d..cbdf209c069914899c4471850eb93e28de9b5bea 100644 (file)
@@ -9,7 +9,7 @@ CC = iccavr
 OBJECTS = $(PROJECT).o\r
 \r
 ## Compile options common for all C compilation units.\r
-CFLAGS =  -e -D__ICC_VERSION="7.16A" -DATtiny2313  -l -A -A -g -Wf-r20_23 \r
+CFLAGS =  -e -D__ICC_VERSION="7.16A" -DATtiny2313  -l -A -A -g -Wf-r20_23  -O24\r
 \r
 ## Linker flags\r
 LDFLAGS = -g -e:0x0800 -bfunc_lit:0x26.0x800 -dram_end:0xdf -bdata:0x60.0xdf -dhwstk_size:30 -beeprom:0.128 -fihx_coff -S2\r
index 0c8bb10aa85dd36c288d89cb41e623a00e9a65bb..1235c7ba0c527653ba7284c3a149a9c977940bd5 100644 (file)
@@ -11,8 +11,9 @@
 **\r
 ** Compilers supported:\r
 **   - WinAVR-20071221 (includes avr-libc 1.6 required for proper _delay_us)\r
-**   - IAR AVR 4.30\r
-**   - Imagecraft AVR 7\r
+**   - IAR AVR 4.30 and 5.10\r
+**   - Imagecraft AVR 7.16\r
+**   - Codevision AVR 2.02.06\r
 **\r
 ** LICENSE\r
 **   See accompaning LICENSE file\r
@@ -30,7 +31,7 @@ FUSES = {
   .extended = EFUSE_DEFAULT,\r
 };\r
 #endif\r
-\r
+  \r
 // Number of PWM brightness levels supported\r
 #define LED_BRIGHTNESS_LEVELS 8\r
 \r
@@ -93,6 +94,12 @@ static FLASH_DECLARE(const unsigned char ledPwmPatterns[]) =
 #pragma global_register ledPwmCount:20 sUartRxHead:21 sUartRxTail:22 ledPwmCycling:23\r
 unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling;\r
 \r
+#elif defined(__CODEVISIONAVR__)\r
+#pragma regalloc-\r
+register unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling;\r
+#pragma regalloc+\r
+\r
+// Use avr_compat register variables\r
 #else\r
 REGISTER_VAR(unsigned char ledPwmCount, "r4", 15);\r
 REGISTER_VAR(unsigned char sUartRxHead, "r5", 14);\r
@@ -101,8 +108,16 @@ REGISTER_VAR(unsigned char ledPwmCycling, "r7", 12);
 #endif\r
 \r
 #define ledPwmPattern GPIOR0\r
-#define ledStatus GPIOR1\r
+#if defined(REGISTER_BIT)\r
 #define BIT_led_on REGISTER_BIT(GPIOR1,0)\r
+#define BACKLIGHT_STATUS() BIT_led_on\r
+#define BACKLIGHT_OFF() BIT_led_on = 0\r
+#define BACKLIGHT_ON() BIT_led_on = 1\r
+#else\r
+#define BACKLIGHT_STATUS() (GPIOR1 & 0x01)\r
+#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01\r
+#define BACKLIGHT_ON() GPIOR1 |= 0x01\r
+#endif\r
 \r
 // Function declarations\r
 void LcdWriteCmd (unsigned char);\r
@@ -110,8 +125,8 @@ void LcdWriteData (unsigned char);
 unsigned char LcdBusyWait (void);\r
 static unsigned char WaitRxChar (void);\r
 \r
-// ImageCraft doesn't support inline functions, so use preprocessor\r
-#if defined(__IMAGECRAFT__)\r
+// ImageCraft/Codevision don't support inline functions, so use preprocessor\r
+#if defined(__IMAGECRAFT__) || defined(__CODEVISIONAVR__)\r
 #define LedTimerStop() TCCR0B = 0\r
 // Start with 256 prescaler\r
 #define LedTimerStart() TCCR0B = (1<<CS02)\r
@@ -139,7 +154,7 @@ static inline void LedPwmInit (void) {
   TIMSK = (1<<OCIE0A);  // Turn on timer0 COMPA intr (all other timer intr off)\r
   LED_PORT &= ~(1<<LED_PIN); // Ensure LED is off during initialization\r
   LED_DIR |= (1<<LED_PIN);   // Ensure LED is output direction\r
-  BIT_led_on = 0;       // note that LED is off\r
+  BACKLIGHT_OFF();       // note that LED is off\r
   ledPwmPattern = 0xFF; // maximum brightness\r
 }\r
 \r
@@ -149,7 +164,7 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
   unsigned char ledPwmPos;\r
 \r
   if (brightness == 0) { // turn backlight off for 0 brightness\r
-    if (BIT_led_on) {\r
+    if (BACKLIGHT_STATUS()) {\r
       LedTimerStop();\r
       ledPwmPattern = 0;\r
       ledPwmCycling = 0;\r
@@ -158,7 +173,7 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
     return;\r
   }\r
 \r
-  ledPwmPos = (brightness * (LED_BRIGHTNESS_LEVELS-1) + 127) >> 8;\r
+  ledPwmPos = (brightness * (LED_BRIGHTNESS_LEVELS-1) + (unsigned int) 127) >> 8;\r
   // Below is probably not required, but ensures we don't exceed array\r
   if (ledPwmPos > LED_BRIGHTNESS_LEVELS - 1)\r
     ledPwmPos = LED_BRIGHTNESS_LEVELS - 1;\r
@@ -168,12 +183,12 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
   ledPwmCycling = ledPwmPattern;\r
   if (ledPwmPos >= LED_BRIGHTNESS_LEVELS-1) { // maximum brightness\r
     // don't need PWM for continuously on\r
-    if (BIT_led_on) {\r
+    if (BACKLIGHT_STATUS()) {\r
       LedTimerStop();\r
       LED_PORT |= (1<<LED_PIN);\r
     }\r
   } else {\r
-    if (BIT_led_on) {\r
+    if (BACKLIGHT_STATUS()) {\r
       LedTimerStart();\r
     }\r
   }\r
@@ -182,13 +197,13 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
 INLINE_FUNC_DECLARE(static void LedPwmSwitchOff (void));\r
 static inline void LedPwmSwitchOff (void) {\r
   LED_PORT &= ~(1<<LED_PIN);\r
-  BIT_led_on = 0;\r
+  BACKLIGHT_OFF();\r
   LedTimerStop();\r
 }\r
 \r
 INLINE_FUNC_DECLARE(static void LedPwmSwitchOn (void));\r
 static inline void LedPwmSwitchOn (void) {\r
-  BIT_led_on = 1;\r
+  BACKLIGHT_ON();\r
   if (ledPwmPattern == 0xFF) { // maximum brightness, no need for PWM\r
     LedTimerStop();\r
     LED_PORT |= (1<<LED_PIN); // keep LED on at all times\r
@@ -248,13 +263,17 @@ static inline void UsartInit(void) {
 #endif\r
 }\r
 \r
-#if defined(__IMAGECRAFT__)\r
+#if defined(__IMAGECRAFT__) || defined(__CODEVISIONAVR__)\r
 // Clock cycle = 67nS @ 14.7456MHz\r
 // Delay resolution ~ 1uS @ 14.7456MHz\r
 // So this function is only accurate at near above frequency\r
 void _delay_us (unsigned int d) {\r
   while (d-- != 0);\r
+#if defined(__IMAGECRAFT__)\r
   asm("nop");\r
+#elif defined(__CODEVISIONAVR__)\r
+  #asm("nop")\r
+#endif\r
 }\r
 #endif\r
 \r
@@ -293,7 +312,11 @@ static inline void LcdInit (void) {
 MAIN_FUNC() {\r
   MCUSR = 0; // clear all reset flags\r
 \r
-  wdt_reset();\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("wdr");\r
+#else\r
+      wdt_reset();\r
+#endif\r
   WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
   WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0); // 1024K cycles, 8.0sec\r
   MCUCR &= ~((1<<SM1)|(1<<SM0)); // use idle sleep mode\r
@@ -304,7 +327,11 @@ MAIN_FUNC() {
   // Initialize the AVR USART\r
   UsartInit ();\r
 \r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("sei");\r
+#else\r
   sei();\r
+#endif\r
   while (1) {\r
     unsigned char tail = sUartRxTail; // explicitly set order of volatile access\r
     if (tail != sUartRxHead) { // Check if UART RX buffer has a character\r
@@ -327,22 +354,50 @@ MAIN_FUNC() {
     } else {\r
       // No characters waiting in RX buffer\r
 \r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("cli");\r
+#else\r
       cli();\r
+#endif\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("wdr");\r
+#else\r
       wdt_reset();\r
+#endif\r
       MCUSR &= ~(1<<WDRF); // clear any watchdog interrupt flags\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDE); // watchdog timer off\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("sei");\r
+#else\r
       sei();\r
+#endif\r
 \r
       sleep_enable();\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("sleep");\r
+#else\r
       sleep_cpu();\r
+#endif\r
       sleep_disable();\r
 \r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("cli");\r
+#else\r
       cli();\r
+#endif\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("wdr");\r
+#else\r
       wdt_reset();\r
+#endif\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDCE);\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("sei");\r
+#else\r
       sei();\r
+#endif\r
     }\r
   }\r
   MAIN_FUNC_LAST();\r
@@ -351,11 +406,36 @@ MAIN_FUNC() {
 void LcdWriteCmd (unsigned char Cmd) {\r
   LcdBusyWait();\r
   LCD_DATA_PORT = Cmd;  // BusyWait leaves RS low in "Register mode"\r
-  NOP();\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("nop");\r
+#else\r
+   NOP();\r
+#endif\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
+#if defined(__CODEVISIONAVR__)\r
+  #if CONSERVATIVE_ENABLE_DURATION\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #else\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #endif\r
+#else\r
   ENABLE_WAIT();\r
+#endif\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
-  NOP();\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("nop");\r
+#else\r
+   NOP();\r
+#endif\r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character mode"\r
 }\r
 \r
@@ -363,9 +443,30 @@ void LcdWriteData (unsigned char c) {
   LcdBusyWait();\r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character Mode"\r
   LCD_DATA_PORT = c;\r
-  NOP();\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("nop");\r
+#else\r
+   NOP();\r
+#endif\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
+#if defined(__CODEVISIONAVR__)\r
+  #if CONSERVATIVE_ENABLE_DURATION\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #else\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #endif\r
+#else\r
   ENABLE_WAIT();\r
+#endif\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
 }\r
 \r
@@ -374,11 +475,36 @@ unsigned char LcdBusyWait (void) {
   LCD_DATA_DIR = 0x00; // Set LCD data port to inputs\r
   LCD_CONTROL_PORT &= ~(1<<LCD_RS); // Set display to "Register mode"\r
   LCD_CONTROL_PORT |= (1<<LCD_RW); // Put the display in the read mode\r
-  NOP();\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("nop");\r
+#else\r
+   NOP();\r
+#endif\r
   do {\r
-    wdt_reset();\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("wdr");\r
+#else\r
+      wdt_reset();\r
+#endif\r
     LCD_CONTROL_PORT |= (1<<LCD_E);\r
-    ENABLE_WAIT();\r
+#if defined(__CODEVISIONAVR__)\r
+  #if CONSERVATIVE_ENABLE_DURATION\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #else\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+    #asm("nop")\r
+  #endif\r
+#else\r
+  ENABLE_WAIT();\r
+#endif\r
     LCDStatus = LCD_DATA_PIN_REG;\r
     LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
   } while (LCDStatus & (1<<LCD_BUSY));\r
@@ -427,14 +553,22 @@ static unsigned char WaitRxChar (void) {
   unsigned char tail;\r
   do {\r
     tail = sUartRxTail; // explicitly set order of volatile variable access\r
-    wdt_reset();\r
+#if defined(__CODEVISIONAVR__)\r
+      #asm("wdr");\r
+#else\r
+      wdt_reset();\r
+#endif\r
   } while (sUartRxHead == tail); // while buffer is empty\r
 \r
 #if USE_CTS\r
   // turn off interrupts so that if UART char ready to be stored, then storage\r
   // will occur after CTS pin is set active. This allows UART ISR to set\r
   //  CTS inactive if byte fills buffer after we remove current byte\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("cli");\r
+#else\r
   cli();\r
+#endif\r
 #endif\r
 \r
   // increment tail position\r
@@ -445,7 +579,11 @@ static unsigned char WaitRxChar (void) {
 \r
 #if USE_CTS\r
   CTS_PORT |= (1<<CTS_PIN); // Ensure CTS is active since just removed a byte\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("sei");\r
+#else\r
   sei();   // Allow UART ISR to read character and change potentially change CTS\r
+#endif\r
 #endif\r
 \r
   return sUartRxBuf[sUartRxTail];\r
@@ -454,11 +592,17 @@ static unsigned char WaitRxChar (void) {
 #if defined(__IMAGECRAFT__)\r
 #pragma interrupt_handler timer0_compa_handler:iv_TIMER0_COMPA\r
 void timer0_compa_handler(void)\r
+#elif defined(__CODEVISIONAVR__)\r
+interrupt [TIM0_COMPA] void timer0_compa_handler(void)\r
 #else\r
   ISR(TIMER0_COMPA_vect)\r
 #endif\r
 {\r
+#if defined(__CODEVISIONAVR__)\r
+  #asm("sei");\r
+#else\r
   sei(); // Okay to allow USART interrupts while controlling LED PWM\r
+#endif\r
 \r
   // Set current LED state based on cycling variable\r
   if (ledPwmCycling & 0x01) {\r
index d02e589c13c8ba6e7ee3889d4bb67850f8907fd0..ad4bbc9bdda73f1172e8ea57dbc537e5051ed287 100644 (file)
@@ -43,13 +43,13 @@ typedef struct
   unsigned bit6:1;\r
   unsigned bit7:1;\r
 } _io_reg;\r
+#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)_SFR_MEM_ADDR(rg))->bit##bt\r
 \r
 #define FLASH_DECLARE(x) const x __attribute__((progmem))\r
 #define NO_INIT_DECLARE(x) x __attribute__((section (".noinit")))\r
 #define INLINE_FUNC_DECLARE(x) inline x __attribute__((always_inline))\r
 #define PGM_READ_BYTE(x) pgm_read_byte(x)\r
 #define NOP() asm volatile("nop");\r
-#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)_SFR_MEM_ADDR(rg))->bit##bt\r
 #define REGISTER_VAR(V,GNU,IAR) register volatile V asm(GNU)\r
 #define NO_RETURN_FUNC(fn) fn __attribute__((noreturn));        \\r
 fn\r
@@ -104,22 +104,11 @@ typedef __flash unsigned int prog_uint32_t;
 \r
 // Below #include requires ICC v7.16+\r
 #include <iccioavr.h>\r
-typedef struct {\r
-  unsigned bit0:1;\r
-  unsigned bit1:1;\r
-  unsigned bit2:1;\r
-  unsigned bit3:1;\r
-  unsigned bit4:1;\r
-  unsigned bit5:1;\r
-  unsigned bit6:1;\r
-  unsigned bit7:1;\r
-} _io_reg;\r
 \r
 #define NOP() asm("nop");\r
 // ImageCraft does not support inline functions\r
 #define inline\r
 #define INLINE_FUNC_DECLARE(x) x\r
-#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)&rg)->bit##bt\r
 #define NO_RETURN_FUNC(fn) fn\r
 #define MAIN_FUNC() void main(void)\r
 #define MAIN_FUNC_LAST()\r
@@ -136,44 +125,64 @@ typedef struct {
 \r
 // CodeVision Compiler\r
 #elif defined(__CODEVISIONAVR__)\r
+\r
+#if __CODEVISIONAVR__ >= 2\r
 #include <io.h>\r
+#else\r
+#include <tiny2313.h>\r
+#endif\r
 \r
-typedef struct {\r
-  unsigned bit0:1;\r
-  unsigned bit1:1;\r
-  unsigned bit2:1;\r
-  unsigned bit3:1;\r
-  unsigned bit4:1;\r
-  unsigned bit5:1;\r
-  unsigned bit6:1;\r
-  unsigned bit7:1;\r
-} _io_reg;\r
+#if defined(_CHIP_ATTINY2313_) || defined(_CHIP_ATTINY2313V_)\r
+  #if !defined(WDTCSR)\r
+    #define WDTCSR WDTCR\r
+  #endif\r
+// Below are bit position definitions for the ATtiny2313\r
+  #define UCSZ0   1\r
+  #define UCSZ1   2\r
+  #define TXEN    3\r
+  #define RXEN    4\r
+  #define RXC    7\r
+  #define RXCIE   7\r
+  #define PD1     1\r
+  #define PD2     2\r
+  #define PD3     3\r
+  #define PD4     4\r
+  #define PD5     5\r
+  #define PD6     6\r
+  #define PB7     7\r
+  #define CS02    2\r
+  #define WGM01   1\r
+  #define OCIE0A  0\r
+  #define WDP0    0\r
+  #define WDP1    1\r
+  #define WDP2    2\r
+  #define WDE     3\r
+  #define WDCE    4\r
+  #define WDP3    5\r
+  #define WDRF    3\r
+  #define SM0     4\r
+  #define SM1     6\r
+  #define SE      5\r
+  #define sleep_enable() MCUCR |= (1<<SE)\r
+  #define sleep_disable() MCUCR &= ~(1<<SE)\r
+  #define USART_RX_vect USART_RXC\r
+#endif\r
 \r
 #define FLASH_DECLARE(x) flash x\r
 #define ASM(a) asm(a)\r
 #define NOP() asm("nop");\r
 #define inline\r
 #define INLINE_FUNC_DECLARE(x) x\r
-#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)&rg)->bit##bt\r
 #define NEAR_VAR(x) x\r
 #define NO_RETURN_FUNC(fn) fn\r
-#define MAIN_FUNC(fn) fn\r
 #define MAIN_FUNC() void main(void)\r
 #define MAIN_FUNC_LAST()\r
+#define PGM_READ_BYTE(x) (*(x))\r
 \r
-// 2007/11/29 - ImageCraft states they will support _Pragma() like IAR\r
-// in a "few months". At that point, REGISTER_VAR and NO_INIT_DECLARE can\r
-// be supported. REGISTER_VAR will need to be expanded with 4th variable to\r
-// hold register number for ImageCraft.\r
-// noinit for ImageCraft requires #pragma data:noinit\r
-//#define NO_INIT_DECLARE(x) _Pragma(data:noinit); x; _Pragma(data:data);\r
 #define NO_INIT_DECLARE(x) x\r
-//#define REGISTER_VAR(V,GNUR,IAR,ICC) _Pragma(global_register V ## : ## ICC)\r
-#define REGISTER_VAR(V,GNUR,IAR) V\r
+#define REGISTER_VAR(V,GNUR,IAR) register V\r
 \r
-#define cli() asm("cli")\r
-#define sei() asm("sei")\r
-#define wdt_reset() asm("wdr")\r
+#define ISR(vec) interrupt [ ## vec ## ] void vec ## _handler(void)\r
 \r
 #else\r
 #error Unsupported compiler\r