ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2202
Скачиваний: 0
CodeVisionAVR
5. CodeWizardAVR Automatic Program Generator
The CodeWizardAVR Automatic Program Generator allows you to easily write all the code needed for implementing the following functions:
•External memory access setup
•Chip reset source identification
•Input/Output Port initialization
•External Interrupts initialization
•Timers/Counters initialization
•Watchdog Timer initialization
•UART initialization and interrupt driven buffered serial communication
•Analog Comparator initialization
•ADC initialization
•SPI Interface initialization
•I2C Bus, LM75 Temperature Sensor, DS1621 Thermometer/Thermostat, PCF8563, PCF8583, DS1302 and DS1307 Real Time Clocks initialization
•1 Wire Bus and DS1820/DS18S20 Temperature Sensors initialization
•LCD module initialization.
The Automatic Program Generator is invoked using the Tools|CodeWizardAVR menu command or by pressing the CodeWizardAVR command bar button.
The File|New menu command allows creating a new CodeWizardAVR project. This project will be named by default untitled.cwp .
The File|Open menu command allows loading an existing CodeWizardAVR project:
© 1998-2007 HP InfoTech S.R.L. |
Page 177 |
CodeVisionAVR
The File|Save menu command allows saving the currently opened CodeWizardAVR project.
The File|Save As menu command allows saving the currently opened CodeWizardAVR project under a new name:
By selecting the File|Program Preview menu option, the code generated by CodeWizardAVR can be viewed in an editor window. This may be useful when applying changes to an existing project, as portions of code generated by the CodeWizardAVR can be copied to the clipboard and then pasted in the project's source files.
If the File|Generate, Save and Exit menu option is selected, CodeWizardAVR will generate the main
.C source and project .PRJ files, save the CodeWizardAVR project .CWP file and return to the CodeVisionAVR IDE.
Eventual pin function conflicts will be prompted to the user, allowing him to correct the errors.
In the course of program generation the user will be prompted for the name of the main C file:
© 1998-2007 HP InfoTech S.R.L. |
Page 178 |
CodeVisionAVR
and for the name of the project file:
Selecting the File|Exit menu option allows you to exit the CodeWizardAVR without generating any program files.
By selecting the Help menu option you can see the help topic that corresponds to the current CodeWizardAVR configuration menu.
© 1998-2007 HP InfoTech S.R.L. |
Page 179 |
CodeVisionAVR
5.1 Setting the AVR Chip Options
By selecting the Chip tab of the CodeWizardAVR, you can set the AVR chip options.
The chip type can be specified using the Chip list box.
The chip clock frequency in MHz can be specified using the Clock spinedit box.
For the AVR chips that contain a crystal oscillator divider, a supplementary Crystal Oscillator Divider Enabled check box is visible.
This check box allows you to enable or disable the crystal oscillator divider.
If the crystal oscillator is enabled, you can specify the division ratio using the Crystal Oscillator Divider spinedit box.
For the AVR chips that allow the identification of the reset source, a supplementary Check Reset Source check box is visible. If it's checked then the CodeWizardAVR will generate code that allows identification of the conditions that caused the chip reset.
© 1998-2007 HP InfoTech S.R.L. |
Page 180 |
CodeVisionAVR
For the AVR chips that allow self-programming, a supplementary Program Type list box is visible. It allows to select the type of the generated code:
•Application
•Boot Loader
© 1998-2007 HP InfoTech S.R.L. |
Page 181 |
CodeVisionAVR
5.2 Setting the External SRAM
For the AVR chips that allow connection of external SRAM, you can specify the size of this memory and wait state insertion by selecting the External SRAM tab.
The size of external SRAM can be specified using the External SRAM Size list box.
Additional wait states in accessing the external SRAM can be inserted by checking the External SRAM Wait State check box.
The MCUCR register in the startup initialization code is configured automatically according to these settings.
© 1998-2007 HP InfoTech S.R.L. |
Page 182 |
CodeVisionAVR
For devices, like the ATmega161, that allow splitting the external SRAM in two pages, the External SRAM configuration window will look like this:
The External SRAM page configuration list box allows selection of the splitting address for the two external SRAM pages .
The wait states that are inserted during external SRAM access, can be specified for the lower, respectively upper, memory pages using the Lower wait states, respectively Upper wait states list boxes.
The MCUCR and EMCUCR registers in the startup initialization code are configured automatically according to these settings.
© 1998-2007 HP InfoTech S.R.L. |
Page 183 |
CodeVisionAVR
5.3 Setting the Input/Output Ports
By selecting the Ports tab of the CodeWizardAVR, you can specify the input/output Ports configuration.
You can chose which port you want to configure by selecting the appropriate PORT x tab.
By clicking on the corresponding Data Direction bit you can set the chip pin to be output (Out) or input (In).
The DDRx register will be initialized according to these settings.
By clicking on the corresponding Pullup/Output Value bit you can set the following options:
•if the pin is an input, it can be tri-stated (T) or have an internal pull-up (P) resistor connected to the positive power supply.
•if the pin is an output, it's value can be initially set to 0 or 1.
The PORTx register will be initialized according to these settings.
© 1998-2007 HP InfoTech S.R.L. |
Page 184 |
CodeVisionAVR
5.4 Setting the External Interrupts
By selecting the External IRQ tab of the CodeWizardAVR, you can specify the external interrupt configuration.
Checking the appropriate INTx Enabled check box enables the corresponding external interrupt.
If the AVR chip supports this feature, you can select if the interrupt will be edge or level triggered using the corresponding Mode list box.
For each enabled external interrupt the CodeWizardAVR will define an ext_intx_isr interrupt service routine, where x is the number of the external interrupt.
© 1998-2007 HP InfoTech S.R.L. |
Page 185 |
CodeVisionAVR
For some devices, like the Atmega169V/L, the External IRQ tab may present the following options:
The Pin Change Interrupt Enable check boxes, if checked, will specify which of the PCINT I/O pins will trigger an external interrupt.
The interrupt service routines for these interrupts will be pin_change_isr0 for PCINT0-7 and pin_change_isr1 for PCINT8-15.
© 1998-2007 HP InfoTech S.R.L. |
Page 186 |
CodeVisionAVR
5.5 Setting the Timers/Counters
By selecting the Timers tab of the CodeWizardAVR, you can specify the timers/counters configuration.
A number of Timer tabs will be displayed according to the AVR chip type.
By selecting the Timer 0 tab you can have the following options:
•Clock Source specifies the timer/counter 0 clock pulse source
•Clock Value specifies the timer/counter 0 clock frequency
•Mode specifies if the timer/counter 0 functioning mode
•Outp. A specifies the function of the timer/counter 0 compare A output and depends of the functioning mode
•Outp. B specifies the function of the timer/counter 0 compare B output and depends of the functioning mode
•Overflow Interrupt specifies if an interrupt is to be generated on timer/counter 0 overflow
•Compare Match A Interrupt specifies if an interrupt is to be generated on timer/counter 0 compare A match
•Compare Match B Interrupt specifies if an interrupt is to be generated on timer/counter 0 compare B match
•Timer Value specifies the initial value of timer/counter 0 at startup
•Compare A specifies the initial value of timer/counter 0 output compare A register
•Compare B specifies the initial value of timer/counter 0 output compare B register.
© 1998-2007 HP InfoTech S.R.L. |
Page 187 |
CodeVisionAVR
If timer/counter 0 interrupts are used the following interrupt service routines may be defined by the CodeWizardAVR:
•timer0_ovf_isr for timer/counter overflow
•timer0_compa_isr for timer/counter output compare A match
•timer0_compb_isr for timer/counter output compare B match
You must note that depending of the used AVR chip some of these options may not be present. For more information you must consult the corresponding Atmel data sheet.
By selecting the Timer 1 tab you can have the following options:
•Clock Source specifies the timer/counter 1 clock pulse source
•Clock Value specifies the timer/counter 1 clock frequency
•Mode specifies if the timer/counter 1 functioning mode
•Out. A specifies the function of the timer/counter 1 output A and depends of the functioning mode
•Out. B specifies the function of the timer/counter 1 output B and depends of the functioning mode
•Out. C specifies the function of the timer/counter 3 output C and depends of the functioning mode
•Inp Capt. specifies the timer/counter 1 capture trigger edge and if the noise canceler is to be used
•Interrupt on specifies if an interrupt is to be generated on timer/counter 1 overflow, input capture and compare match
•Timer Value specifies the initial value of timer/counter 1 at startup
•Comp. A, B and C specifies the initial value of timer/counter 1 output compare registers A, B and
C.
© 1998-2007 HP InfoTech S.R.L. |
Page 188 |