From: Kevin Rosenberg Date: Wed, 19 Mar 2008 18:45:49 +0000 (-0600) Subject: 20080319 release: CV support X-Git-Url: http://git.kpe.io/?p=avr_serial_lcd.git;a=commitdiff_plain;h=8147823cf64e37f6f43838ffa9e056ea48e30c32 20080319 release: CV support --- diff --git a/ChangeLog b/ChangeLog index 8c13117..9dad81f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2008-03-18 Kevin Rosenberg + * Add Codevision port + 2008-03-15 Kevin Rosenberg * serial_lcd.c: Add 4-bit interface mode * serial_lcd.h: Move LCD control codes here with renaming. Use diff --git a/Makefile b/Makefile index 688d777..bbbb7ef 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ date := $(shell date +"%Y%m%d") .PHONY: all all: build +PROJECT := serial_lcd tester := tester/serial_lcd_tester tester-build: $(tester).exe @@ -45,6 +46,7 @@ clean: $(MAKE) -C iar_cpp_obj clean $(MAKE) -C iar_cpp_obj clean $(MAKE) -C icc_c clean + @rm -f *~ .PHONY: distclean distclean: diff --git a/README b/README index 1c15365..1db3974 100644 --- 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. -Code/Data Sizes (for 20080316 release) +Code/Data Sizes (for 20080318 release) ====================================== Compiler Code Data Notes --------- ---- ---- ----- -AVR-GCC C 718 48 -Os +AVR-GCC C 716 48 -Os AVR-GCC C++ 806 50 -Os AVR-GCC Obj 1574 72 -Os +CV 2.02.6 808 48 Maximum size optimization IAR C 622 48 Size optimization high (+ 64 bytes stack) IAR C++ 762 49 Size optimization high (+ 64 bytes stack) IAR Obj 1112 65 Size optimization high (+ 63 bytes stack) -ICC7 C 818 48 Full optimizations +ICC7 C Pro 812 48 Full optimizations (-O24) I would appreciate submissions of suggestions, improvements, or bug fixes. diff --git a/cv_c/Makefile b/cv_c/Makefile new file mode 100644 index 0000000..4c6d9e1 --- /dev/null +++ b/cv_c/Makefile @@ -0,0 +1,15 @@ +PROJECT := serial_lcd + +.PHONY: clean +clean: + @rm -rf $(PROJECT).str1 $(PROJECT).sym[0-9] $(PROJECT).cof \ + $(PROJECT).a $(PROJECT).o *~ Obj Linker +# Clean up Codevision files in source directory + @rm -f ../$(PROJECT).c@ ../$(PROJECT).c! ../$(PROJECT).h! \ + ../$(PROJECT).i ../$(PROJECT).inc ../$(PROJECT).sym \ + ../$(PROJECT).hdr $(PROJECT).txt *~ $(PROJECT).fct + +.PHONY: distclean +distclean: clean + @rm -rf $(PROJECT).map Exe List + diff --git a/cv_c/serial_lcd.prj b/cv_c/serial_lcd.prj new file mode 100644 index 0000000..78eab68 --- /dev/null +++ b/cv_c/serial_lcd.prj @@ -0,0 +1,251 @@ +[Project] +Toolset=AVR +FormatVersion=2 +Files=1 +OpenedFiles=0 +Top0=430 +Left0=711 +Height0=339 +Width0=497 +Active0=1 +State0=0 +OF1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c +Top1=257 +Left1=268 +Height1=339 +Width1=497 +Row1=0 +Collumn1=0 +Active1=0 +State1=0 +OF2=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.h +Top2=257 +Left2=268 +Height2=339 +Width2=497 +Row2=114 +Collumn2=21 +Active2=1 +State2=0 +OF3=c:\cvavreval\inc\tiny2313.h +Top3=197 +Left3=133 +Height3=339 +Width3=497 +Row3=84 +Collumn3=3 +Active3=1 +State3=0 +OutputListFilesDirectory=List +OutputObjectFilesDirectory=Obj +OutputExecutableFilesDirectory=Exe +OutputLinkerFilesDirectory=Linker +AllowDisplayFunctionCallTree=0 +F1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c +[Compiler] +Chip=ATtiny2313 +CPUClock=14745600 +MemoryModel=0 +OptimizeSize=1 +OptimizationLevel=2 +PrintfFeatures=1 +ScanfFeatures=0 +DataStackSize=64 +PgmMemSize=2048 +RAMStart=96 +RAMEnd=223 +XRAMSize=0 +XRAMWaitState=0 +HeapSize=0 +ExternalInterruptVectors=0 +InterruptVectorsNumber=19 +InterruptVectorJump=0 +ResetVector=0 +PromoteCharToInt=0 +CharIsUnsigned=1 +8BitEnums=1 +EnhancedCoreInstructions=1 +AutomaticRegisterAllocation=1 +SmartRegisterAllocation=1 +WordAlignFLASHStructMembers=0 +PreprocessorOutput=1 +ExternalStartupFile=0 +ExternalStartupFileWarning=0 +BitVariablesSize=24 +UseHiGPIORbit=0 +StackEndMarkers=0 +Warnings=1 +WarningConstantRange=0 +WarningPossibleLossOfPrecision=0 +WarningArrayIndex=1 +WarningGlobalVariableAddress=1 +WarningInterruptVector=1 +WarningUninitializedFLASH=1 +WarningUninitializedEEPROM=1 +WarningSuspiciousPointerConversion=1 +WarningRegisterAllocated=1 +WarningMacroRedefined=1 +WarningFunctionReturn=1 +WarningUnreferencedFunction=1 +WarningUnreferencedFunctionParameter=1 +WarningUnreferencedLocalVariable=1 +WarningUnreferencedGlobalVariable=1 +WarningUnreferencedLabel=1 +WarningEmptyLine=1 +WarningExpressionHasNoEffect=1 +WarningUnknownEscapeSequence=1 +WarningShiftResult0=1 +Warning8BitAdditionOverflow=1 +Warning8BitMultiplicationOverflow=1 +Warning16BitAdditionOverflow=1 +Warning16BitMultiplicationOverflow=1 +WarningPossiblyIncorrectAssignment=1 +WarningPointlessComparison=1 +WarningConstCtrlExpr=1 +WarningUndefinedSymbol=1 +WarningCantAllocVarToReg=1 +WarningDataStackUsage=1 +WarningDataStackRecursion=1 +WarningHardwareStackLow=1 +DebugBootLoader=0 +Build=4 +UseEEPROMLocation0=1 +IncludePath0= +IncludePath1= +IncludePath2= +IncludePath3= +IncludePath4= +IncludePath5= +IncludePath6= +IncludePath7= +IncludePath8= +IncludePath9= +IncludePath10= +IncludePath11= +IncludePath12= +IncludePath13= +IncludePath14= +IncludePath15= +IncludePath16= +IncludePath17= +IncludePath18= +IncludePath19= +IncludePath20= +IncludePath21= +IncludePath22= +IncludePath23= +IncludePath24= +IncludePath25= +IncludePath26= +IncludePath27= +IncludePath28= +IncludePath29= +IncludePath30= +IncludePath31= +LibraryPath0= +LibraryPath1= +LibraryPath2= +LibraryPath3= +LibraryPath4= +LibraryPath5= +LibraryPath6= +LibraryPath7= +LibraryPath8= +LibraryPath9= +LibraryPath10= +LibraryPath11= +LibraryPath12= +LibraryPath13= +LibraryPath14= +LibraryPath15= +LibraryPath16= +LibraryPath17= +LibraryPath18= +LibraryPath19= +LibraryPath20= +LibraryPath21= +LibraryPath22= +LibraryPath23= +LibraryPath24= +LibraryPath25= +LibraryPath26= +LibraryPath27= +LibraryPath28= +LibraryPath29= +LibraryPath30= +LibraryPath31= +RebuildAll=0 +LinkageInformationPresent=1 +GlobalConstInFlash=1 +ClearGlobalVarsStartup=0 +WarningFunctionParameterName=1 +WarningLocalVariableSetNotUsed=1 +WarningVariableUsedNotSet=1 +WarningTypeQualifierMeaningless=1 +WarningExplicitTypeMissing=1 +WarningEnumType=1 +WarningTypedefName=1 +WarningTypedefRedeclared=1 +WarningExtraBraces=1 +WarningIncompatibleAssignment=1 +WarningIncompatibleInit=1 +WarningIncompatibleOperandsTernary=1 +WarningIncompatibleFunctionArgument=1 +WarningIncompatibleFunctionReturn=1 +WarningMemoryAttributeIgnored=1 +WarningPragmaVector=1 +WarningCOFFArrayDim=1 +WarningCOFFDataComplex=1 +LinkerWarnings=1 +[DefinedSymbols] +Count=0 +[Assembler] +OutputFormat=1 +TerminalIO=0 +[AfterMake] +ProgrammChip=0 +MergeROMFile=0 +ROMFilePath= +SCKFrequency=230400 +LockBits=0 +BootLockBits0=0 +BootLockBits1=0 +ProgramFuseBits=1 +Fuse1=0 +Fuse2=0 +Fuse3=0 +Fuse4=0 +Fuse5=0 +Fuse6=0 +Fuse7=0 +Fuse8=0 +Fuse9=0 +Fuse10=0 +Fuse11=0 +Fuse12=0 +Fuse13=0 +Fuse14=0 +Fuse15=0 +Fuse16=0 +Fuse17=0 +Fuse18=0 +Fuse19=0 +Fuse20=0 +Fuse21=0 +Fuse22=0 +Fuse23=0 +Fuse24=0 +CheckSignature=1 +CheckErasure=1 +PreserveEEPROM=0 +VerifyProgramming=1 +ProgrammingCounter=0 +RunUserProg=0 +UserProgPath= +UserProgCmdLine= +UserProgWorkDir= +[BeforeMake] +RunUserProg=0 +UserProgPath= +UserProgCmdLine= +UserProgWorkDir= diff --git a/cv_c/serlcd_cv.prj b/cv_c/serlcd_cv.prj deleted file mode 100644 index 2a35dbe..0000000 --- a/cv_c/serlcd_cv.prj +++ /dev/null @@ -1,223 +0,0 @@ -[Project] -Toolset=AVR -FormatVersion=2 -Files=1 -OpenedFiles=3 -Top0=430 -Left0=711 -Height0=339 -Width0=497 -Active0=0 -State0=0 -OF1=c:\home\kevin\src\avr\serial_lcd\serial_lcd.c -Top1=151 -Left1=84 -Height1=509 -Width1=614 -Row1=135 -Collumn1=0 -Active1=0 -State1=0 -OF2=C:\home\kevin\src\avr\serial_lcd\serial_lcd.h -Top2=257 -Left2=268 -Height2=339 -Width2=497 -Row2=0 -Collumn2=0 -Active2=0 -State2=0 -F1=C:\home\kevin\src\avr\serial_lcd\serial_lcd.c -OF3=c:\cvavreval\inc\tiny2313.h -Top3=197 -Left3=133 -Height3=339 -Width3=497 -Row3=84 -Collumn3=3 -Active3=1 -State3=0 -[Compiler] -Chip=ATtiny2313 -CPUClock=14745600 -MemoryModel=0 -OptimizeSize=1 -OptimizationLevel=2 -PrintfFeatures=1 -ScanfFeatures=0 -DataStackSize=64 -PgmMemSize=2048 -RAMStart=96 -RAMEnd=223 -XRAMSize=0 -XRAMWaitState=0 -HeapSize=0 -ExternalInterruptVectors=0 -InterruptVectorsNumber=19 -InterruptVectorJump=0 -ResetVector=0 -PromoteCharToInt=0 -CharIsUnsigned=1 -8BitEnums=1 -EnhancedCoreInstructions=1 -AutomaticRegisterAllocation=1 -SmartRegisterAllocation=1 -WordAlignFLASHStructMembers=0 -PreprocessorOutput=1 -ExternalStartupFile=0 -ExternalStartupFileWarning=0 -BitVariablesSize=8 -UseHiGPIORbit=0 -StackEndMarkers=0 -Warnings=1 -WarningConstantRange=0 -WarningPossibleLossOfPrecision=0 -WarningArrayIndex=1 -WarningGlobalVariableAddress=1 -WarningInterruptVector=1 -WarningUninitializedFLASH=1 -WarningUninitializedEEPROM=1 -WarningSuspiciousPointerConversion=1 -WarningRegisterAllocated=1 -WarningMacroRedefined=1 -WarningFunctionReturn=1 -WarningUnreferencedFunction=1 -WarningUnreferencedFunctionParameter=1 -WarningUnreferencedLocalVariable=1 -WarningUnreferencedGlobalVariable=1 -WarningUnreferencedLabel=1 -WarningEmptyLine=1 -WarningExpressionHasNoEffect=1 -WarningUnknownEscapeSequence=1 -WarningShiftResult0=1 -Warning8BitAdditionOverflow=1 -Warning8BitMultiplicationOverflow=1 -Warning16BitAdditionOverflow=1 -Warning16BitMultiplicationOverflow=1 -WarningPossiblyIncorrectAssignment=1 -WarningPointlessComparison=1 -WarningConstCtrlExpr=1 -WarningUndefinedSymbol=1 -WarningCantAllocVarToReg=1 -WarningDataStackUsage=1 -WarningDataStackRecursion=1 -WarningHardwareStackLow=1 -DebugBootLoader=0 -Build=5 -UseEEPROMLocation0=1 -IncludePath0= -IncludePath1= -IncludePath2= -IncludePath3= -IncludePath4= -IncludePath5= -IncludePath6= -IncludePath7= -IncludePath8= -IncludePath9= -IncludePath10= -IncludePath11= -IncludePath12= -IncludePath13= -IncludePath14= -IncludePath15= -IncludePath16= -IncludePath17= -IncludePath18= -IncludePath19= -IncludePath20= -IncludePath21= -IncludePath22= -IncludePath23= -IncludePath24= -IncludePath25= -IncludePath26= -IncludePath27= -IncludePath28= -IncludePath29= -IncludePath30= -IncludePath31= -LibraryPath0= -LibraryPath1= -LibraryPath2= -LibraryPath3= -LibraryPath4= -LibraryPath5= -LibraryPath6= -LibraryPath7= -LibraryPath8= -LibraryPath9= -LibraryPath10= -LibraryPath11= -LibraryPath12= -LibraryPath13= -LibraryPath14= -LibraryPath15= -LibraryPath16= -LibraryPath17= -LibraryPath18= -LibraryPath19= -LibraryPath20= -LibraryPath21= -LibraryPath22= -LibraryPath23= -LibraryPath24= -LibraryPath25= -LibraryPath26= -LibraryPath27= -LibraryPath28= -LibraryPath29= -LibraryPath30= -LibraryPath31= -[DefinedSymbols] -Count=0 -[Assembler] -OutputFormat=1 -TerminalIO=0 -[AfterMake] -ProgrammChip=0 -MergeROMFile=0 -ROMFilePath= -SCKFrequency=230400 -LockBits=0 -BootLockBits0=0 -BootLockBits1=0 -ProgramFuseBits=1 -Fuse1=0 -Fuse2=0 -Fuse3=0 -Fuse4=0 -Fuse5=0 -Fuse6=0 -Fuse7=0 -Fuse8=0 -Fuse9=0 -Fuse10=0 -Fuse11=0 -Fuse12=0 -Fuse13=0 -Fuse14=0 -Fuse15=0 -Fuse16=0 -Fuse17=0 -Fuse18=0 -Fuse19=0 -Fuse20=0 -Fuse21=0 -Fuse22=0 -Fuse23=0 -Fuse24=0 -CheckSignature=1 -CheckErasure=1 -PreserveEEPROM=0 -VerifyProgramming=1 -ProgrammingCounter=0 -RunUserProg=0 -UserProgPath= -UserProgCmdLine= -UserProgWorkDir= -[BeforeMake] -RunUserProg=0 -UserProgPath= -UserProgCmdLine= -UserProgWorkDir= diff --git a/icc_c/Makefile b/icc_c/Makefile index 05bb2e1..cbdf209 100644 --- a/icc_c/Makefile +++ b/icc_c/Makefile @@ -9,7 +9,7 @@ CC = iccavr OBJECTS = $(PROJECT).o ## Compile options common for all C compilation units. -CFLAGS = -e -D__ICC_VERSION="7.16A" -DATtiny2313 -l -A -A -g -Wf-r20_23 +CFLAGS = -e -D__ICC_VERSION="7.16A" -DATtiny2313 -l -A -A -g -Wf-r20_23 -O24 ## Linker flags LDFLAGS = -g -e:0x0800 -bfunc_lit:0x26.0x800 -dram_end:0xdf -bdata:0x60.0xdf -dhwstk_size:30 -beeprom:0.128 -fihx_coff -S2 diff --git a/serial_lcd.c b/serial_lcd.c index 0c8bb10..1235c7b 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 @@ -30,7 +31,7 @@ FUSES = { .extended = EFUSE_DEFAULT, }; #endif - + // Number of PWM brightness levels supported #define LED_BRIGHTNESS_LEVELS 8 @@ -93,6 +94,12 @@ static FLASH_DECLARE(const unsigned char ledPwmPatterns[]) = #pragma global_register ledPwmCount:20 sUartRxHead:21 sUartRxTail:22 ledPwmCycling:23 unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling; +#elif defined(__CODEVISIONAVR__) +#pragma regalloc- +register unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling; +#pragma regalloc+ + +// Use avr_compat register variables #else REGISTER_VAR(unsigned char ledPwmCount, "r4", 15); REGISTER_VAR(unsigned char sUartRxHead, "r5", 14); @@ -101,8 +108,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 BACKLIGHT_STATUS() BIT_led_on +#define BACKLIGHT_OFF() BIT_led_on = 0 +#define BACKLIGHT_ON() BIT_led_on = 1 +#else +#define BACKLIGHT_STATUS() (GPIOR1 & 0x01) +#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01 +#define BACKLIGHT_ON() GPIOR1 |= 0x01 +#endif // Function declarations void LcdWriteCmd (unsigned char); @@ -110,8 +125,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 +183,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 (BACKLIGHT_STATUS()) { LedTimerStop(); LED_PORT |= (1<bit##bt #define FLASH_DECLARE(x) const x __attribute__((progmem)) #define NO_INIT_DECLARE(x) x __attribute__((section (".noinit"))) #define INLINE_FUNC_DECLARE(x) inline x __attribute__((always_inline)) #define PGM_READ_BYTE(x) pgm_read_byte(x) #define NOP() asm volatile("nop"); -#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)_SFR_MEM_ADDR(rg))->bit##bt #define REGISTER_VAR(V,GNU,IAR) register volatile V asm(GNU) #define NO_RETURN_FUNC(fn) fn __attribute__((noreturn)); \ fn @@ -104,22 +104,11 @@ typedef __flash unsigned int prog_uint32_t; // Below #include requires ICC v7.16+ #include -typedef struct { - unsigned bit0:1; - unsigned bit1:1; - unsigned bit2:1; - unsigned bit3:1; - unsigned bit4:1; - unsigned bit5:1; - unsigned bit6:1; - unsigned bit7:1; -} _io_reg; #define NOP() asm("nop"); // ImageCraft does not support inline functions #define inline #define INLINE_FUNC_DECLARE(x) x -#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)&rg)->bit##bt #define NO_RETURN_FUNC(fn) fn #define MAIN_FUNC() void main(void) #define MAIN_FUNC_LAST() @@ -136,44 +125,64 @@ typedef struct { // CodeVision Compiler #elif defined(__CODEVISIONAVR__) + +#if __CODEVISIONAVR__ >= 2 #include +#else +#include +#endif -typedef struct { - unsigned bit0:1; - unsigned bit1:1; - unsigned bit2:1; - unsigned bit3:1; - unsigned bit4:1; - unsigned bit5:1; - unsigned bit6:1; - unsigned bit7:1; -} _io_reg; +#if defined(_CHIP_ATTINY2313_) || defined(_CHIP_ATTINY2313V_) + #if !defined(WDTCSR) + #define WDTCSR WDTCR + #endif +// Below are bit position definitions for the ATtiny2313 + #define UCSZ0 1 + #define UCSZ1 2 + #define TXEN 3 + #define RXEN 4 + #define RXC 7 + #define RXCIE 7 + #define PD1 1 + #define PD2 2 + #define PD3 3 + #define PD4 4 + #define PD5 5 + #define PD6 6 + #define PB7 7 + #define CS02 2 + #define WGM01 1 + #define OCIE0A 0 + #define WDP0 0 + #define WDP1 1 + #define WDP2 2 + #define WDE 3 + #define WDCE 4 + #define WDP3 5 + #define WDRF 3 + #define SM0 4 + #define SM1 6 + #define SE 5 + #define sleep_enable() MCUCR |= (1<bit##bt #define NEAR_VAR(x) x #define NO_RETURN_FUNC(fn) fn -#define MAIN_FUNC(fn) fn #define MAIN_FUNC() void main(void) #define MAIN_FUNC_LAST() +#define PGM_READ_BYTE(x) (*(x)) -// 2007/11/29 - ImageCraft states they will support _Pragma() like IAR -// in a "few months". At that point, REGISTER_VAR and NO_INIT_DECLARE can -// be supported. REGISTER_VAR will need to be expanded with 4th variable to -// hold register number for ImageCraft. -// noinit for ImageCraft requires #pragma data:noinit -//#define NO_INIT_DECLARE(x) _Pragma(data:noinit); x; _Pragma(data:data); #define NO_INIT_DECLARE(x) x -//#define REGISTER_VAR(V,GNUR,IAR,ICC) _Pragma(global_register V ## : ## ICC) -#define REGISTER_VAR(V,GNUR,IAR) V +#define REGISTER_VAR(V,GNUR,IAR) register V -#define cli() asm("cli") -#define sei() asm("sei") -#define wdt_reset() asm("wdr") +#define ISR(vec) interrupt [ ## vec ## ] void vec ## _handler(void) #else #error Unsupported compiler