Home
Getting Started with the CodeVisionAVR Extension for Atmel Studio
Contents
1. lh CodeWizardAVR untitled cwp File Program Edit Help e Ld kd ic k E CodewizardAVR untitled cp Project Information Program Preview ee 1 Project Information Chip Project Hame Moving LED demo P External Interrupts e Version 1 0 Date 14 03 2013 ii Watchdog Timer Author Pavel Haiduc z T Analog Comparator Company HP InfoTech A ne Analog to Digital Converter IBF Serial Peripheral Interface Ju Two Wire Interface This is a simple prograre HA Bit Banged 120 Bus Interface gita 1 Wire Bus Interface ii Bit Banged Peripherals A Alphanumeric LCD I Graphic Display Comments 2012 2013 HP InfoTech S R L Page 11 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Using the Program Generate menu or clicking on the E toolbar button will create the C program which can be previewed in the Program Preview window Program Preview 1 include c mega32B8p h Z 3 Declare your global variables here 4 5 Timerl output compare A interrupt service routine 6 interrupt TIM1 COMPA void timerl compa isr void 7 1 B8 Place your code here ajl 10 11 1 void main void 13 14 Declare your local variables here 15 16 Crystal Oscillator division factor 1 17 pragma optsize 18 CLEPR 1 lt lt CLEBCE 19 CLKPR O CLEPCE O lt CLEPS3 O lt lt CLEPS2 O CLEPSI 0 lt lt CLEPSO 20 ifdet OPTIMI
2. Target AVA Chip Type w ATSU ATtiny AT mega 2 SMEGA Ex Select the AT90 ATtiny ATmega option and click on the OK button The CodeWizardAVR will be launched and the following window will be displayed d CodeWizardAVR untitled cwp File Program Edit Help di CadewizardAVH untitled cwp Chip Settings Program Preview Project Information i Chip Chip amp Tmega3oBP Clock 15 000000 BI MHz Crystal Oscillator Divider 1 Check Reset Source M Analog Comparator P RUE Analog to Digital Converter be de Serial Penpheral Interface Program Type Tur Two Wire Interface Application OOOO o r ete Bit Banged 120 Bus Interface sity 1 Wire Bus Interface c Bit Banged Peripherals 3 2 a Alphanumeric LED E Graphic Display In the Chip Settings panel select the Chip type ATmega328P and Clock frequency 16 MHZ 2012 2013 HP InfoTech S R L Page 4 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 The next step is to configure the PORTD pins PDO to PD7 as outputs In order to achieve this click on the of Ports node of the CodeWizard s tree A new configuration panel for Port Settings will be displayed b CodeWizardAVR untitled cwp File Program Edit Help JE e Ed L odew izard amp VH untitled cwp Ports Settings Pragram Preview 1 Project Information E Chip Pot B Port Port D Data Direction Pull
3. Bir Out 1 Bit O Bit Out 1 Bit 1 Bit 2 Out 1 Bit Bits Out 1 Bit 3 Bir4 Out 1 Bit 4 Bik Out 1 Bit Bike Out 1 Bit Bit Out 1 Bit 2012 2013 HP InfoTech S R L Page 6 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 The next step is to configure a Timer Counter to generate an interrupt after each 200 ms Click on the Timers Counters node of the CodeWizard s tree A Timers Counters Settings panel will be displayed E CodeWizardAVR untitled cwp File Program Edit Help F ld kd i5 k E Codewizard amp VF untitled cwp Timers Caunters Settings Program Preview 4 Project Information Redi Chip equirements Period 0 000000 4 ms 2 DI Watchdog Timer E T Analog Comparator Apply nie Analog to Digital Converter du Serial Peripheral Interface fin Two Wire Interface Tap BitBanged 2L Bus Interface jx UND S Ice Clock Source System Clock A zm Bit Banged Peripherals Clock Value Timer 0 Stopped M E Alphanumeric LCD em Graphic Display Mode Normal top UxFF Out A Disconnected Out B Disconnected EF Overflow Interrupt F Compare Match amp Interrupt Compare Match B Interrupt Timer Value O h Compare O Compare B 0 2012 2013 HP InfoTech S R L Page 7 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Timer will be used so click on the corresponding tab 2012 2013 HP I
4. HP InfoTech Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Revision 2 10 2013 Copyright 2012 2013 Pavel Haiduc and HP InfoTech S R L All rights reserved No part of this document may be reproduced in any form except by written permission of the author All rights of translation reserved 2012 2013 HP InfoTech S R L Page 1 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Table of Contents Uie ei PT ET 3 2 HPO EM OUD AE E AEE EEE EE E 3 Oa Cheatilic AEW PrO e eere a T TE 4 A Editing the Source Code 16 5 Configuring the mios e RERO Tm 17 6 Building the Project and Programming the Chip cccccecccecseeeeeeceeeeeeeaeeeeseeeeeesseeeeeeeeeeeeseeeeesseseessaeeeees 20 FAN Depugging Me Fe gels Ec M RETE TOO 21 8 CONCUSSION eee TE 26 APETA Bg sire 16 le S0 6 0 RENTE oO ET 27 2012 2013 HP InfoTech S R L Page 2 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 1 Introduction The purpose of this document is to guide the user through the preparation building and debugging of an example C program using the CodeVisionAVR
5. B01 1 BO2 0 J B11 1 E12 0 4 Check Signature Check Erasure Preserve EEPROM Verify X Cancel i Help The following options must be set e Programmer AVRISP MKII e SCK Freq 125000 Hz e Program Fuse Bit s enabled e All fuse bits 0 not programmed state not checked except BODLEVEL1 0 which must be in programmed state checked Note If the AVRISP MkII is used for programming the Arduino UNO board the boot loader preprogrammed by the manufacturer in the ATmega328P chip will be erased This will prevent any future uploading using the virtual COM port on the USB bus unless the boot loader and fuse bits are reprogrammed correctly again 2012 2013 HP InfoTech S R L Page 19 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 The project configuration changes must be confirmed by clicking on the OK button 6 Building the Project and Programming the Chip The final step is compiling and linking our program using the Build Build ed demo menu command After a successful build the following Information window will be displayed Information Compiler Assembler Programmer Chip AT mega3z28P Clock frequency 15 000000 MHz Program type Application Memory model Small Optimize for Size s printf Features int width s scanf features int width Promote char to int Yes char is Unsigned Yes global co
6. O PORTC5 O PORTCA O PORTC3 O PORTC2 O lt lt PORTC1 PORTOCDO Port D initialization Function Bit7 0ut Bit6 0ut Bit5 0ut Bit4 0ut Bit3 Out Bit2 0ut Bitl Out Bit0 0ut DDRD 1 lt lt DDD7 1 lt lt DDD6 1 lt lt DDD5 1 lt lt DDD4 1 lt lt DDD3 1 lt lt DDD2 1 lt lt DDD1 1 lt lt DDDO State Bit7s1 Bit6 1 Bit5 1 Bit4 1 Bit3 1 Bit2 1 Bitl 1 Bit0 21 PORTD 1 lt lt PORTD7 1 lt lt PORTD6 1 lt lt PORTD5 1 lt lt PORTD4 1 lt lt PORTD3 1 lt lt PORTD2 1 lt lt PORTD1 1 lt lt PORTDO Timer Counter 0 initialization Clock source System Clock Clock value Timer 0 Stopped Mode Normal top 0xFF OCOA output Disconnected OCOB output Disconnected TCCROA 0 COMOA1 0 COMOAO 0 COMOB1 0 COMOBO O lt lt WGMO1 O0 WGMO0 TCCROB 0 WGMO2 0 CS02 0 CSO1 0 C3500 TCNTO 0x00 OCROA 0x00 OCROB 0x00 Timer Counter 1 initialization Clock source System Clock Clock value 250 000 kHz Mode CTC top OCR1A OC1A output Disconnected OC1B output Disconnected Noise Canceler Off Input Capture on Falling Edge Timer Period 0 2 s Timerl Overflow Interrupt Off Input Capture Interrupt Off Compare A Match Interrupt On Compare B Match Interrupt Off TCCR1A 0 COM1A1 0 COM1AO Q lt lt COM1B1 0 COMIBO
7. PCICR 0 lt lt PCIE2 0 lt lt PCIEl1 0 lt lt PCIEQ USART initialization USART disabled UCSROB 0 lt lt RXCIEO O TXCIEO O UDRIEO O RXENO O TXENO 0 UCSZ202 O RXB80 O TXB80 Analog Comparator initialization Analog Comparator Off The Analog Comparator s positive input is connected to the AINO pin The Analog Comparator s negative input is connected to the AINI pin ACSR 1 lt lt ACD O0 ACBG 0 ACO O lt lt ACI O ACIE O ACIC O lt lt ACIS1 O lt lt ACISO ADCSRB 0 lt lt ACME Digital input buffer on AINO On Digital input buffer on AIN1 On DIDR1 0 lt lt AINOD O lt lt AINID ADC initialization ADC disabled ADCSRA O ADEN O ADSC O ADATE O ADIF O ADIE O ADPS2 Q lt lt ADPS1 O ADPSO 2012 2013 HP InfoTech S R L Page 29 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 SPI initialization SPI disabled SPCR 0 lt lt SPIE O SPE O DORD O lt lt MSTR O CPOL O CPHA O SPR1 O SPRO JJ TWI initialization TWI disabled TWCR O TWEA O TWSTA O TWSTO O lt lt TWEN 0 lt lt TWIE Global enable interrupts asm Sei while 1 Place your code here 2012 2013 HP InfoTech S R L Page 30
8. SFD X Register Ox0900 Y Register Ox0 2FE Z Register x1802 Status Register 1 T HY 8 v M Cycle Counter 6412422 Frequency 16 000 MHz Stop Watch 400 776 38 us So the time interval between two Timer 1 output compare A interrupts will be 400776 38 us 200776 44 us 199999 94 us 199 99994 ms which is equal to the required 200 ms with a negligible error The following additional commands can be used when debugging e Debug Step Over F10 key or toolbar button to execute one instruction If the instruction contains a function call the function is executed as well e Debug Step Out Shift F11 keys or toolbar button to continue execution until the current function has completed e Debug Run To Cursor Ctrl F10 keys or 5 toolbar button to continue execution until the current cursor position in the source file or disassembly view is reached e Debug Reset ShifttF5 keys or toolbar button to restart program execution from the beginning e Debug Restart or l toolbar button to restart the debugger and reload the debugged program e Debug Toggle Breakpoint or F9 key to set a breakpoint at the current cursor position in the C source file or disassembly view e Debug New Breakpoint Break at Function to set a breakpoint at the beginning of a particular function e Debug Delete All Breakpoints or Ctrl Shift F9 keys to delete all the breakpoints that were set e Debug Disable All Breakpoints to temporarily disable all the breakpo
9. V3 07 or later C compiler extension for Atmel Studio 6 1 or later The example is a simple program for the Atmel ATmega328 microcontroller on an Arduino UNO board 2 Preparation Download and install Atmel Studio from www atmel com Install the CodeVisionAVR C Compiler by executing the CodeVisionAVR msi installer When prompted use the default installation directory suggested by the installer Please note that Administrator privileges are required under Windows for installing and using CodeVisionAVR Make the following hardware preparations e fit is not already installed solder a 6 pin header to the location marked ICSP on the Arduino UNO board e Connect the cathodes of 8 LEDs to the outputs marked DIGITAL 0 7 on the board These outputs correspond to PORTD pins PDO PD7 of the microcontroller e Connect each LED s anode using a 1k resistor to the pin marked 5V of the board s POWER connector header e Connect the USB connector of the Arduino board to an USB port of your computer This will provide power supply and communication to the board 2012 2013 HP InfoTech S R L Page 3 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 3 Creating a New Project Launch the Atmel Studio IDE Execute the File New Project Using the CodeWizardAVR menu command A dialog window will be displayed allowing selecting the AVR chip family for which the CodeWizardAVR will create the program E CodeWizardAVR
10. Declare your local variables here Crystal Oscillator division factor 1 pragma optsize ce CLKPR 1 CLKPCE CLKPR lt lt CLKPCE lt lt CLKPS3 lt lt CLKPS2 lt lt CLKPS1 lt lt CLKPS ifdef OPTIMIZE SIZE pragma optsize endit 100 al The line with the breakpoint will be highlighted After the breakpoint was set we can continue single stepping through our program using Debug Step Into menu command the F11 key or the toolbar button We can start executing our program until the breakpoint is reached by selecting the Debug Continue menu command pressing the F5 key or the p toolbar button 2012 2013 HP InfoTech S R L Page 23 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Important Note The Atmel Studio Simulator executes the program at a much lower speed than the real AVR chip so reaching the breakpoint set in the timer1 compa isr function doesn t occur in real time after 200 ms Depending on the host PC speed the simulator will appear to hang for 1 2 minutes but finally the program execution stops at the breakpoint led demo x z T TH 2 T FS gt Data Stack size 517 a lf include lt mega328p h gt Declare your global variables here Timerl output compare A interrupt service routine interrupt TIM1 COMPA void timerl compa isr void Place your code here Ier LE Mr ES DUE Dips DE One of the LEDs is already
11. MPA void timerl compa isr void Place your code here If all LEDs are off light the first one if PORTD OxFF PORTD OxFE One of the LEDs is already lighted turn it off and light the next one else PORTD PORTD lt lt 1 1 j void main void Declare your local variables here Crystal Oscillator division factor 1 pragma optsize CLKPR 1 lt lt CLKPCE CLKPRE CLKPCE O CLKPS3 O CLKRPSA2 0 lt lt CLKPS1 CLKPSO ifdef OPTIMIZE SIZE_ pragma optsizet endif 2012 2013 HP InfoTech S R L Page 27 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Input Output Ports initialization Port B initialization Function Bitv In Bit6sIn BitbseIn Bit4 In Bit3 In Bit2s5In Bitl In BitOsIn DDRB 0 DDB7 0 lt lt DDB6 0 lt lt DDB5 0 lt lt DDB4 O DDB3 O DDB2 O DDB1 O lt lt DDBO State Bit7 T Bit6sT Bit5sT Bit4sT Bit3sT Bit2sT BitleT BitOsT PORTB 0 PORTB7 0O PORTB6 0 PORTB5 O PORTBA4 O PORTB3 O PORTB2 O lt lt PORTB1 O PORTBO0 Port C initialization Function Bit6 In Bit5 In Bit4 In Bit3 In Bit2 In Bitl In Bit0 In DDRC 0 lt lt DDCG 0 lt lt DDC5 0 lt lt DDC4 0 lt lt DDC3 0 lt lt DDC2 0 lt lt DDC1 0 lt lt DDC0 7 State Bit6sT Bits T Bit4sT Bits T Bit 2 T Bitl T Bit0sT PORTC 0 lt lt PORTC6
12. Q lt lt WGM11 0 WGM10 TCCRIB 0 lt lt ICNC1 O ICES1 0 WGM13 1 WGM12 0 CS12 1 CS11 1 lt lt CS10 TCNT1H 0x00 TCNT1L 0x00 ICR1H 0x00 ICR1L 0x00 OCR1AH 0xC3 OCRIAL 0x4F 2012 2013 HP InfoTech S R L Page 28 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 OCRIBH 0x00 OCRIBL 0x00 Timer Counter 2 initialization Clock source System Clock Clock value Timer2 Stopped Mode Normal top OxFF OC2A output Disconnected OC2B output Disconnected ASSR 0 lt lt EXCLK 0 A82 TCCR2A 0 COM2A1 0 COM2AO 0 COM2B1 0 COM2BO 0 WGM21 0 WGM20 TCCR2B 2 0 WGM22 0 CS22 0 CS21 0 CS20 TCNT2 0x00 OCR2A 0x01 OCR2B 0x00 Timer Counter 0 Interrupt s initialization TIMSKO 0 lt lt OCIEOB O OCIEOA O TOIEO Timer Counter 1 Interrupt s initialization TIMSKIS OSCICIBLN 0O lt lt OCIE1B CL SOGIBELA 0 lt lt TOIE1 Timer Counter 2 Interrupt s initialization TIMSK2 0 lt lt OCIEZB O OCIEZ2A O TOIEZ2 External Interrupt s initialization Jd INTO Off ff INTL Orr Interrupt on any change on pins PCINTO 7 Off Interrupt on any change on pins PCINT8 14 Off Interrupt on any change on pins PCINT16 23 Off EICBAe US LSCLDP QOSSLSCIO q 0 150601 TOSSISCOU EIMSK O0 INT1 O INTO
13. R extension and will appear in the COM Port list if the Arduino UNO board is connected to the computer If your computer has several serial ports please make sure to select the correct one associated with the Arduino UNO board The serial port number can be identified using Windows Control Panel gt Hardware and Sound gt Device Manager gt Ports COM amp LPT gt Arduino UNO 2012 2013 HP InfoTech S R L Page 18 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Alternatively the chip can be also programmed using an Atmel AVRISP MkII USB programmer connected to the ISP header of the Arduino UNO board In this case the Action Program the Chip option must be selected E Configure Project led demo prj Files C Compiler Before Build After Build Acton Program the Chip Execute Program L Merge data from a ROM File for FLASH Pragramming Chip Pragramrming Options Programmer AVRISP MEI oo 4 Program Fuse Bits a CESELO 0 l H CESEL1 0 SCK Freq 125000 Hz z TE CKSEL3 0 FLASH Lock Bits suto o No Protection suT1 0 a C CKOUT 0 Programming disabled ckDIv8 n TP C BOOTRST 0 J Pragramming and Verification disabled C BBODTSzD D C BooTsz1 0 Boot Lock Bit 0 Boot Lock Bit 1 EESAVE 0 BOI 1802 1 B11 1B12 1 et ee 5 BO1 0 BO2 1 5 B11 0 B12 1 ME wl BO1 0 B02 0 5 B11 0 812 0 PEE un O
14. ZE SIZE 2 pragma optsizet 22 endif 23 24 f f Input Ontput Ports initialization 25 Port B initialization 26 Function Bit7 In Bit6 In Bit5 In Bit4s In Bitij in Bitz In Biti In BitO0 In 27 DDBB O DDB7 O0 DDB6 0 DDB5 O0 lt lt DDEB4 O0 DDB3 28 State Bit 7 T Bit6 T Bit5 T Bit4 T Bit3 T Bitz T Biti T Bit T 29 PORIB O PORIB7 O lt PORTBG O lt PORTBS O lt lt PORTB4 O PORIB3 30 31 Port C initialization 32 Function Bit6 In BitS In Bit In Bit3 In Bitz In Biti In Bitt In 33 DDRC 0 lt lt DDCe O0 DDC5 0 DDC4 O DDC3 O0 DDC2 34 State Bit6 T Bit5 T Bits T Bit3 T Bitz T Biti T Bit0o0 T 35 PORTC O lt lt PORTC6 O lt lt PORTCS O lt lt PORTC4 O lt lt PORTCS O0 PORICZ 4 rm Mm Oz lt PORTBRZ O lt lt DDCO O lt lt BORTC1 By clicking on a peripheral node in the CodeWizard s tree the cursor in the Program Preview window will be positioned at the corresponding initialization code sequence for that peripheral Note By default the CodeWizardAVR generates initialization code even for peripherals that are not in use disabled This is a safety measure to configure correctly the chip if a software reset occurred by jumping to address O In order to reduce generated program size this can be disabled by un checking the Program Generate Code for Disabled Peri
15. d all the code needed to initialize the peripherals for our application now we must add the part of code required to execute our task light sequentially with a 200 ms delay each of the 8 LEDs connected to PORTD In order to open the project s C source file in the editor we must double click on the led demo c node in the Solution Explorer Once the file is loaded in the Editor window we can apply changes to it 2 led demo AtmelStudio File Edit View VAssistX ASF Project Build Debug Tools Window Help d A 4 028 Bisxs sa35 9 cc i0 U EBg a Dd dw debug J Q 5 1 c 01 7 e iE HE D 1 80 dO Majo u ss SES He Gr 2i dal o WD Li S cm li wATmega228P T NoTool led demo c X demo X Solution Explorer Ix gt led demo c gt gt C Users Pavel Documents Atmel Studio 6 1 work led demo c ES T kkoko ooo OR OE UR GUERRE ORE OE OE UE OE UE OE OE OE OE OE OE a Solution led demo a project This program was created by the f 4 led demo CodeWizardAVR V3 3 UL Standard Dependencies Automatic Program Generator Copyright 1998 2013 Pavel Haiduc HP InfoTech s r l http www hpinfotech com Sa Output Files 3 Libraries c led demo c Project Moving LED demo Version 1 0 Date 14 03 2013 Author Pavel Haiduc Company HP InfoTech Comments This is a simple program EM Saisie Ci Solution Explorer Chip type ATmega328P Program t
16. e debugging session will be started for the first time the user will be prompted to select the tool that will be using for tracing the program execution Select Tool Please choose one of the tools below to start debugging Tools and Simulators Status AImega328P Support AVRISP mkll DOBODOODOUEC Caneca Yez Program only For our example we will select the Simulator and click on the OK button 2012 2013 HP InfoTech S R L Page 21 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 After the debugging tool was selected the debugging session actually starts led demo Debugging AtmelStudio File Edit View VAssistX ASF Project Build Debug Tools Window Help J A 02 id d 46 c3 08 9 9 E293 ES gt Wl Debug 99 MSS HP dox aiii alo u p a S i o ATmega328P Simulator lt j led demo c X x Processor a 5 Name Value mm Go e 0x0000006A Program Counter include mega328p h Stack Pointer 0x08FF X Register 0x0900 Y Register 0x0300 Timerl output compare A interrupt service routine Z Register 0x1808 interrupt TIM1 COMPA void timer1 compa isr void p Status Register 1 D 9 S V N 1 Cycle Counter 12386 Place your code here Frequency 1 000 MHz Stop Watch 12 386 00 us Declare your global variables here If all LEDs are off light the first one if PORTD xFF PORTD xFE One of the LEDs is already lighted turn it of
17. e peripheral configuration for other projects just by reloading the cwp file in the CodeWizardAVR Once all these files were saved Atmel Studio will prompt us if we wish to create a new solution for the led demo project Confirmation Do you wish to create a new solution for the project led demo xa 2012 2013 HP InfoTech S R L Page 14 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 We will click on the Yes button and will be prompted for the solution name Create Atmel Studio Solution Wolk p Atmel Studio 61 work Organize New folder T Favorites Name Date modified Downloads Recent Places NE Desktop No items match your search NE Desktop Libraries Documents al Music E Pictures BE Videos ed Homegroup B Pavel jE Computer ci Network File name led demo Save as type Atmel Studio solution files atsln Once this is done the new solution and project are loaded in Atmel Studio and the corresponding information is displayed in the Solution Explorer Solution Explorer ala r Solution led demo 1 project 4 3 led demo Sa Dependencies a Output Files aj Libraries ic led demo c B ASF Explorer e Solution Explorer 2012 2013 HP InfoTech S R L Page 15 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 4 Editing the Source Code The CodeWizardAVR has create
18. el the CodeWizardAVR will establish the required values for Timer 1 configuration registers TimersCounters Settings rf Status Period 200 000001 4 ms Hequirements Obtained Pernod 0 2 s LOU 2 error OO A error Clock Source vstem Clock Clock Value 25000DkHz Mode CTCtop 0CR1A st Out A Disconnected Disconnected Dut B Disconnected Input Capture Noise Cancel L Rising Edge Interrupt an Value O h np Capture 0 h Comp amp C34F hB h As can be seen in the above window the 16 MHz system clock will be divided by 64 in order to obtain a Timer 1 Clock Value of 250 kHz and the OCR1A register will be initialized with the value OxCS4F The obtained time period between two interrupts will be 0 2 seconds matching our requirement with a 0 error Note The automatic Timer configuration is disabled in the CodeVisionAVR Evaluation version Therefore an error message will be issued by the Evaluation version when the Apply button is clicked The user will have to manually select Clock Value 250 000 kHz and enter the value C34F in the Comp A field 2012 2013 HP InfoTech S R L Page 10 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 The next step before generating the actual program code is to specify some comments regarding our program by clicking on the CH Project Information node and completing the comments in the corresponding panel
19. f and light the next one 0x00 else PORTD PORTD lt lt 1 1 void main void i Declare your local variables here Crystal Oscillator division factor 1 pragma optsize CLKPR lt lt CLKPCE lt lt CLKPS3 lt lt CLKPS2 lt lt CLKPS1 lt lt CLKPS jtifdef _OPTIMIZE_SIZE_ pragma optsize endif Input Output Ports initialization 100 v 4 Watch 2 prog FLASH Oc 94 34 00 Oc 94 OO 00 Oc 94 00 BB Gc 94 OO 00 Oc 94 00 O0 Oc 94 BB GO Oc 94 G0 00 ec 94 00 Oc 94 OO GO Oc 94 0O GO Oc 94 00 00 Oc 94 Sa 00 Gc 94 00 0O Oc 94 BB OO i8 6c 94 00 00 Oc 94 OO 00 Oc 94 BB 00 Oc 94 x0046 090 00 Oc 94 00 OO Oc 94 GO OO Oc 94 00 OO 2x0054 0c 94 00 00 Oc 94 00 00 Oc 94 00 00 Oc 94 2x0062 00 00 Oc 94 00 00 f8 94 ee 27 ef bb f1 e 0 i i f Fa Autos RA Locals Watch1 Bl Watch 2 AESCEUeBIMCER Memory KREE B c A Bisnis MOT A Ad a MBA o M dM M dUES NE SE 60000600606 T B 5S O oO GOOG Oo gu 00 og OO OO OO Ou wD Q Stopped Chi INS The simulator first executes the low level startup initialization code which consists of filling all RAM locations with Os initializing the global variables data and hardware stack pointers Once these operations are finished the program execution is passed to the main function of the program The debugger stops the program execution at the first C source line of main allowing
20. ints that were set e Debug Enable All Breakpoints to re enable all the breakpoints that were set e Debug Break All Ctrl F5 keys or ll toolbar button to stop program execution e Debug Windows allow displaying specific windows for watching variables processor registers I O and peripheral registers memory contents code disassembly etc e Debug Stop Debugging Ctrl Shift F5 keys or 4 toolbar button stops the debugging session To obtain more information about using the debugger please consult the Atmel Studio Help Note The compiler applies some optimization techniques that may prevent correct debugging of the executable program Therefore it is recommended to select the Project Configure C Compiler Code generation Optimize for Speed option for code debugging If the program fits in the chip s FLASH this option must be left enabled for Release too as the program will execute faster this way 2012 2013 HP InfoTech S R L Page 25 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 8 Conclusion This document provides the necessary starting guidelines for rapid development and debugging of an application using the CodeVisionAVR extension for Atmel Studio CodeVisionAVR is supplied with a comprehensive Help and User Manual which must be extensively studied in order to take full advantage of all the features of the C compiler associated peripheral libraries CodeWizardAVR and LCD Vision font image editor co
21. lighted turn it off and light the next one else PORTD PORTD 1 1 void main void i Declare your local variables here Crystal Oscillator division factor 1 pragma optsize CLKPR 1 lt lt CLKPCE CLKEPR lt lt CLKPCE lt lt CLKPS3 lt lt CLKPS2 lt lt CLKPS1 8 CLKPS8 ifdef OPTIMIZE SIZE Bees ae ae 100956 As the program execution stopped inside the timer compa isr function we will note the Stop Watch value of 200776 44 us in the Processor window Stack Pointer Ox08FD X Register Ox0900 Y Register Ox02FE Z Register x1802 Status Register HEN Cycle Counter 3212423 Frequency 16 000 MHz Stop Watch 200 776 44 us This value is slightly larger than the 200 ms which we have specified as the Timer 1 output compare interrupt period The additional 776 44 us are required by the startup initialization code after chip reset and the moment the Timer 1 registers are first initialized and counting is started 2012 2013 HP InfoTech S R L Page 24 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 We will press the F5 key again to continue program execution The simulator will stop again at the breakpoint in timer1_compa_isr after 1 2 minutes depending on the host PC speed This time the Stop Watch value in the Processor window will be 400776 38 us Processor Name Value Program Counter Ox0000005D Stack Pointer x
22. nfoTech S R L Timers Counters Settings Requirements Period 0 000000 4 ms Clock Source System Clock Clock Value Timerl Stopped Mode Normal top OxF FFF Out Disconnected Out B Disconnected Input Capture L Noise Cancel C Rising Edge Interrupt an Timerl Overflow a Input Capture Value OU h inp Capture 0 Comp 4 D h B h Page 8 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 As we need a Timer 1 compare match interrupt after each 200 ms we must select the operating Mode as CTC top OCR1A specify the Period value 200 ms in the Requirements panel and check the Interrupt on Compare A Match check box Timers Counters Settings Period 200 000001 4 ms Clock Source System Clock gt Clock Value Timerl Stopped Mode CTC top O0CR14 Input Capture Noise Cancel Rising Edge Interrupt an I Compare 4 Match Value D h np Capture 0 Comp 4 0 hB h In this operating mode the Timer 1 will count pre scaled system clock pulses until the TCNT1 register will be equal with the value of the OCR1A register When this will occur the TCNT1 register will be automatically reset to 0 and a Timer 1 compare with OCR1A match interrupt will be generated 2012 2013 HP InfoTech S R L Page 9 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 By clicking on the Apply button in the Requirements pan
23. nst stored in FLASH Yes B bit enums Yes Enhanced function parameters passing res Automatic register allocation res Smart register allocation res Build 1 1030 line s compiled Mo errors Mo warnings Bit variables size 0 byte s Data Stack area 0x100 ta Ux2FF Data Stack size 512 byte s Estimated Data Stack usage U byte s HAM Global variables size 0 bute s Hardware Stack area Ox S00 to RSFF Hardware Stack size 1536 byte s Heap size byte s EEPROM usage 0 byte s 0 0 of EEPROM Program size 179 words 358 bytes 1 1 of FLASH 0 wards 0 bytes 0 02 reduced by Code Compression Clicking on the Program the chip button will transfer the compiled program to the chip s FLASH and program the fuse bits Once these operations are performed the program will start executing 2012 2013 HP InfoTech S R L Page 20 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 7 Debugging the Program Once the program was successfully built it can be debugged in source level form using the Atmel Studio s Simulator A debugging session can be started using the Debug Start Debugging and Break menu command the p toolbar button or by pressing the AIt F5 keys If the source files were modified since the last Build a Rebuild will be automatically performed before the debugging will be started Atmel Studio uses the cof object file produced by CodeVisionAVR for debugging When th
24. nverter for graphic displays The compiler is supplied with a large number of example programs covering e Alphanumeric LCD e Graphic LCD TFT and OLED displays e Resistive touch screen e SD Memory Cards e USART e TWI lC e SPI e ADC e Boot loaders e USB e Web Server e XMEGA EBI e XMEGA Quadrature Encoder e XMEGA DAC e DS1820 DS18B20 LM75 DS1621 temperature sensors These programs are located in the Examples and Examples ATxmega subdirectories of the CodeVisionAVR installation directory 2012 2013 HP InfoTech S R L Page 26 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Appendix A The Source Code KK RK kk kk Ck kk kk kk Ck Ck Ck Kk Kk Ck kk kk KC kk Ck kk ck ckck ck ck ck ck ck kk ck kk This program was created by the CodeWizardAVR V3 03 Standard Automatic Program Generator Copyright 1998 2013 Pavel Haiduc HP InfoTech S4Y l http www hpinfotech com Project Moving LED demo Version 1 0 Date 14 03 2013 Author Pavel Haiduc Company HP InfoTech Comments This is a simple program Chip type ATmega328P Program type Application AVR Core Clock frequency 16 000000 MHz Memory model Small External RAM size 2 0 Data Stack size ike HK OK I KK eK IK IK I kk I IK I k ck IK ck ck ck I KK I KK KK KK KK include lt mega328p h gt Declare your global variables here Timerl output compare A interrupt service routine interrupt TIM1 CO
25. onAVR Extension for Atmel Studio 6 1 5 Configuring the Project Once the required changes were made to the program s source code the next step is to configure the project s build options using the Project Configure menu The dialog window will be displayed E Configure Project led demo prj BEEN Before Build After Build Input Files E C Users Pavelk Documents atmel 5rudiasb 1 work led dema c We need to automatically program the chip after a successful Build 2012 2013 HP InfoTech S R L Page 17 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 This can be achieved by selecting the After Build tab and enabling the Action Upload to Arduino option fe Configure Project led demo prj Files C Compiler Before Build After Build Action Upload to Arduino Execute Program Arduino Upload Settings Arduino Board Type Arduino Uno amp Tmega328F COM Port COMI7 X cores ep In the Arduino Upload Settings the following options must be set e Arduino Board Type Arduino Uno ATmega328P e COM Port the serial port used for communication with the development board Note The serial communication port is virtual and provided by the FTDI USB driver when the Arduino UNO board is connected to the computer It will be detected by the CodeVisionAV
26. pherals menu option Once we are satisfied with the generated code we must save the new program by using the Program Generate Save and Exit menu or clicking on ke the toolbar button 2012 2013 HP InfoTech S R L Page 12 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 First we will be prompted for the name of the first c source file of the project Save C Compiler Source File Save in di work Go 2 EF ud I Name Date modified Type a Recent Places Desktop No items match your search um E Libraries File name Save as type Next we will have to specify the name of the Atmel Studio project Save Atmel Studio Project File Save in Jg work o Ei EP Fo Ii Name Date modified Type a Recent Places Desktop No items match your search 5 Libraries Dp File name led demo cpraj Save as type Atmel Studio project files cpraj 2012 2013 HP InfoTech S R L Page 13 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 And finally we must save the peripheral configuration for our project in a CodeWizardAVR project cwp file Save CodeWizardAVR Project untitled cwp As Save in n work a m Name DE d Recent Places Mo items match your search File name led demo cwp Save as type Code Wizard AVH project files cwp This will allow us to use the sam
27. the user to single step the program from there The AVR chip registers are displayed in the Processor window By default the simulator uses a clock frequency of 1 000MHz but in our example the chip is clocked at 16 000MHz so this must be modified by clicking on the Frequency field and entering the correct value there Value Program Counter Ox0000006A x Stack Pointer Ox08FF A Register 0x0900 Y Register 0x0300 Z Register x1808 Status Register 1 Cr 18 v N Ed Cycle Counter 12386 Frequency 16 000 MH Stop Watch 714 13 us and pressing Enter 2012 2013 HP InfoTech S R L Page 22 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 The next step in debugging our program is to set a breakpoint at the beginning of the Timer 1 output compare A interrupt service routine timer1 compa isr This is achieved by placing the cursor on the first line of code in the above mentioned function and selecting the Debug Toggle Breakpoint menu command or pressing the F9 key include lt mega328p h gt Declare your global variables here Timerl output compare A interrupt service routine Jinterrupt TIM1 COMPA void timerl compa isr void if Place your code here If all LEDs are off light the first one o Tt ee aa no ee a One of the LEDs is already lighted turn it off and light the next one else PORTD PORTD lt lt 1 1 j void main void i
28. up OQutput salue P External Interrupts BitO In T Bit CY Timers Counters Bit In Bit 1 ED Watchdog Timer B USART Bit2 ln Bit 2 m i Analog Comparator Bit 3 n Bit 3 Ec ane Analog to Digital Converter Bit4 dn Bit 4 a PI serial Peripheral Interface Bit In Bit 5 Hpg Two Wire Interface m Bit anged 120 Bus Interface et 6 In h j zi 1 wire Bus Interface Bit In Bit 7 zz Bit B anged Peripherals a Alphanumeric LED Bel aa Graphic Display Click on the Port D tab in order to select the PORTD configuration Ports Settings Bit 0 T Bra Bit 1 Bit 1 Bit 2 Bit 2 Bit 3 Bit 3 Bit 4 Bit 4 Bit 5 Bit 5 Bit B Bit 5 Bit 7 Bit 7 As can be seen the Port D Data Direction for all I O pins is set by default as inputs In 2012 2013 HP InfoTech S R L Page 5 Getting Started with the CodeVisionAVR Extension for Atmel Studio 6 1 Click on each Bit 0 to Bit 7 button in order to set the I O pins as outputs Ports Settings Pot B Partt Fort D Data Direction Pullup Uutput Value BitO Qut O Bir Bit Out 0 Bit 1 Bit 2 Out O Bie Bit 3 Out 0 Bits Bit 4 Out 0 Bit 4 Bit Out 0 Bir Bit amp Out 0 Bit B Bit Out 0 Bit As the LEDs must be OFF after chip reset the potential of their cathodes must be 5V so the Output Values for Port D Bit 0 to Bit 7 must be set to 1 by clicking on the corresponding buttons Ports Settings Part B Port E Part D Data Direction FPullupt Output Value
29. ype Application AVR Core Clock frequency 16 000000 MHz Memory model Small External RAM size Data Stack size aic e cie cic cic oic kc c cic cc cic cic cic cic cic kc cc cde cic cic cic cic cic clc oic clc cic cic cic cic cic cic cic cc cc cic kc cic cic cic cic cic aic cic cic cic cic cic cic cie cie oic cic oie oe Properties include lt mega328p h gt Declare your global variables here Timerl output compare A interrupt service routine interrupt TIM1 COMPA void timerl compa isr void Place your code here Show output from Build Iba gel gt Se al MESES E Output Build succeeded Ln 26 Coll Chi All the action of the program is performed by Timer 1 compare with OCR1A match interrupt service routine timer1 compa isr which is called every 200 ms The required code will be added there in bold text Timerl output compare A interrupt service routine interrupt TIMI COMPA void timerl compa isr void Place your code here If all LEDs are off light the first one if PORTD OxFF PORTD OxFE One of the LEDs is already lighted turn it off and light the next one else PORTD PORTD 1 1 Note As the LEDs anodes are connected to 5V by a resistor and the cathodes are connected to PORTD outputs in order for them to be lighted the corresponding output must be set to logic level 0 2012 2013 HP InfoTech S R L Page 16 Getting Started with the CodeVisi
Download Pdf Manuals
Related Search
Related Contents
User Manual for HD200 (Manual for 2115020) 2450 kg 2525 kg 90 kg 12,20 kN Raadpleeg uw dealer voor de max 1. Getting Started er Datasheet Safety Control Unit SG-EFS 104/4L Operating Instructions Perma2™ User Manual - Giatec Scientific Inc 取扱説明書(PDF/222KB) Manuel de l`utilisateur Oscilloscopes à phosphore numérique, série Targus Radius Pro Laptop Backpack Copyright © All rights reserved.
Failed to retrieve file