ICCAVR Manual

12
NEX Robotics Fire Bird III – ICCAVR Manual www.nex-robotics.com 1 Introduction Setting Up a New Project Introduction to ICC AVR: Setting Up a New Project Step 1: Setting default project options In this step we are going to tell the IDE that from now on we are going to use ATMEGA128 microcontroller. Run ICCAVR and then click on the Project Tab and select “Options” Figure 3.5 It will open Compiler options. Select ATMEGA128 microcontroller in device configuration. Then select set as default and close the window.

description

ATMEGA128 microcontroller

Transcript of ICCAVR Manual

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 1

    Introduction Setting Up a New Project Introduction to ICC AVR: Setting Up a New Project Step 1: Setting default project options

    In this step we are going to tell the IDE that from now on we are going to use ATMEGA128 microcontroller. Run ICCAVR and then click on the Project Tab and select Options

    Figure 3.5

    It will open Compiler options. Select ATMEGA128 microcontroller in device configuration. Then select set as default and close the window.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 2

    Figure 3.6

    Step 2: Create a Folder where all files related to this New Project will be stored

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 3

    Step 3: Run ICCAVR and then click on the Project Tab and select the option New from the drop-down list.

    Step 4: Now you will be prompted to assign a name to your project. So browse to

    the Folder that you have created in Step 1 and once there, assign a name and click on Save

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 4

    Step 5: Now click on File Menu and select New. This will create an untitled

    source file where you will write all your code. Again click on File Menu and select Save As and save it in your project folder.

    Step 6: Next comes the task of writing the source code and this is where the magic

    of ICCAVR lies. It makes the task simple for you by automatically generating code to initialize all hardware resources that you may need and in the mode that you need them. It is called the Application Builder and it

    is started by clicking on this icon in the toolbar. As you can see in the figure below, all you need to do is to graphically specify your requirements and it takes care of the rest. This way you are free to just concentrate on the application that you are building. We prefer to teach you how to use this feature by taking up actual examples and therefore this will be dealt with in detail later.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 5

    Step 7: Write the code required for your application. Step 8: To include this file as a source file of your project, right click on File in

    the Project Window and select Add Files and browse to the file you saved in Step 4 and then click on Project->Rebuild All (Shift+F9). Correct any errors if present.

    Step 9: Click on the Tools tab and select the In System Programmer option or click on the icon on the toolbar.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 6

    Step 10: Load the hex file

    In the Programmer Interface section select STK-200 programmer and select LPT1 (parallel port) option. In Target Device Setting section, select Perform Target Signature Check option. Deselect the Auto Program After Compile option and select Verify After Programming option. In EEPROM Options, select Preserve existing content option. In Manual Program NOW section, specify the path of the hex file to be loaded. Now load the hex file into the microcontroller by clicking on the Program FLASH/EEPROM button

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 7

    Example 1 Aim: To turn the buzzer ON every second. Solution : Follow Steps 1 through 4 obediently and then be ready to experience the magic in Step 5

    Start by clicking on this icon in the toolbar and adjust parameters in the window that you get as shown in the screenshots that follow. Note that the code shown on the left has been generated on clicking OK after all required parameters were set. It has been juxtaposed here with the window just to demonstrate the effect of a particular action in the window on the code generated. Screenshot 1 : Here under the CPU tab we select M128 as we are using the ATMega128 microcontroller. Also the Crystal Frequency is selected as 11.059MHz and this is reflected in the code generated as shown.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 8

    Screenshot 2 : Here under the Ports tab we make PortBs 7th pin as output pin and make its default value as zero. The effect of this can be seen in the value assigned to PortB which is 7F as opposed to other ports having FF. Also a port_init() function is generated automatically which initializes all ports as required.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 9

    Screenshot 3 : Here under the Timer1 Tab, we indicate that we will use Timer1 and also our intention to use its Overflow Interrupt. We specify the Frequency that we would operate it on and then adjust the Prescalar till we get a close enough value in the Actual Value(error %) Field. The effects of these actions are shown in the figure below. We get a timer1_init function that sets it in proper mode. Also a timer1_ovf_isr is generated to take care of the overflow interrupt.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 10

    Screenshot 4 : Here under click on the Options Tab and select Include main(). This will give you a readymade main() with all initializations done.

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 11

    Finally, the actually generated code and the additions that we made to it to get our application running is given below. The lines in RED were added by us while rest were generated automatically. /*************************CODE STARTS HERE*************************/ //ICC-AVR application builder : 3/19/2007 8:26:55 PM // Target : M128 // Crystal: 11.059Mhz #include #include unsigned char port_b_copy = 0x0F; void port_init(void) { PORTA = 0xFF; DDRA = 0x00; PORTB = 0x7F; DDRB = 0x80; PORTC = 0xFF; //m103 output only DDRC = 0x00; PORTD = 0xFF; DDRD = 0x00; PORTE = 0xFF; DDRE = 0x00; PORTF = 0xFF; DDRF = 0x00; PORTG = 0x1F; DDRG = 0x00; } //TIMER1 initialisation - prescale:256 // WGM: 0) Normal, TOP=0xFFFF // desired value: 1Hz // actual value: 1.000Hz (0.0%) void timer1_init(void) { TCCR1B = 0x00; //stop TCNT1H = 0x57; //setup TCNT1L = 0x41; OCR1AH = 0xA8; OCR1AL = 0xBF; OCR1BH = 0xA8; OCR1BL = 0xBF; OCR1CH = 0xA8; OCR1CL = 0xBF; ICR1H = 0xA8; ICR1L = 0xBF; TCCR1A = 0x00; TCCR1B = 0x04; //start Timer } #pragma interrupt_handler timer1_ovf_isr:15

  • NEX Robotics Fire Bird III ICCAVR Manual

    www.nex-robotics.com 12

    void timer1_ovf_isr(void) { //TIMER1 has overflowed TCNT1H = 0x57; //reload counter high value TCNT1L = 0x41; //reload counter low value PORTB = port_b_copy; port_b_copy =~port_b_copy; } //call this routine to initialise all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts XDIV = 0x00; //xtal divider XMCRA = 0x00; //external memory port_init(); timer1_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EICRB = 0x00; //extended ext ints EIMSK = 0x00; TIMSK = 0x04; //timer interrupt sources ETIMSK = 0x00; //extended timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialised } void main(void) { init_devices(); while(1) {} } /*************************CODE ENDS HERE*************************/