+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
.PHONY: all\r
all: build\r
\r
+PROJECT := serial_lcd\r
tester := tester/serial_lcd_tester\r
\r
tester-build: $(tester).exe\r
$(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
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
--- /dev/null
+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
--- /dev/null
+[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
+++ /dev/null
-[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
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
**\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
.extended = EFUSE_DEFAULT,\r
};\r
#endif\r
-\r
+ \r
// Number of PWM brightness levels supported\r
#define LED_BRIGHTNESS_LEVELS 8\r
\r
#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
#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
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
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
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
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
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
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
#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
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
// 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
} 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
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
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
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
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
\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
#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
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
\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
\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