Contents About this Tutorial .......................................................................................................................... 2 Important Information .................................................................................................................... 2 Create Codevision Project ............................................................................................................... 3 Include .H and .C files in CodeVision ............................................................................................... 6 Sample .H File .................................................................................................................................. 7 Sample .C File .................................................................................................................................. 8 SJVE Page 1 of 8 there is a section that explains how to setup header files in CodeVision Important Information 1. it explains how to burn the code onto an Atmega chip using STK500 board and program the microcontroller to output serial data that you can read to and from the microcontroller.686Mhz The clock on the PCB Kit is 16.About this Tutorial This tutorial will guide you on how to create a project in CodeVision. Changing fuse bit setting can disable the Atmega microcontroller SJVE Page 2 of 8 . Do not change the fuse bit settings in CodeVision unless you know what you are doing. The clock on the STK500 kit is 3. Finally. Furthermore.000Mhz 2. Click File Æ New 3.Selecting the chip type lets you choose features of the chip. Open CodeVision 2. but first. you can now use CodeVision to automatically generate template code for Atmega microcontroller. user can choose the settings for UART. This will enable the use of printf and scanf statements. Save and Exit 6. 7. CodeVision will generate the code and now you can burn the code into the Atmega. a few settings need to be changed. SJVE Page 3 of 8 . Select File Æ Generate. 5. You must select the correct frequency of the Atmega otherwise many functions like UART and delay function calls will not work as intended 4. UART enables you to perform input/output functions for the Atmega microcontroller and it is also useful to debug code. You can now name your project files and save them into a project folder. Create Codevision Project 1. After clicking Yes in the previous prompt. In the next figure. Check the “Program the Chip” option and choose the options described by the next figure: SJVE Normally. delay_ms(100).width. Now browse to After Make tab. then you need to enable this feature. Adding the delay is necessary otherwise the microcontroller outputs data so fast that the PC buffer will overflow for the incoming serial data and your computer may freeze while trying to read the data from the serial buffer chip. you do not need to Verify the code so deslect Verify option.8. otherwise leave it alone. Click on Project Æ Configure and go to the C Compiler tab 9. Page 4 of 8 . Scroll down towards the bottom of the code and observe that your entire code needs to be within the while(1) loop. Click OK 12. Under the (s)printf features. First. 10. precision if needed. which is exactly what the PCB kit and the STK500 uses so do not change this unless you know what you are doing. 11. This is an infinite loop and the microcontrollers must have one infinite loop otherwise they it execute code once and stop working. myfloat). select float. Program Fuse Bit(s) is also not needed because this can change the way Atmega starts up using various clock options. Atmega’s come programmed to use external clock. if you wish to display floating point numbers using printf(“%f”. Do not enable this feature unless required because it takes a lot of code memory space. Add the following code inside the while loop: “printf(“test\n”). You should now see the microcontroller outputting data. Choose the speed in bps. connect SJVE Page 5 of 8 .PD0/PD1 to RX/TX and connect serial cable to the 2nd DB9 port. 17. which must be the same as the one in step 4. 21. The code is ready and microcontroller is now printing printf statements. Click OPEN to open the COM port. For the PCB kit. Press Shift+F9 and then select Program the Chip option 16. This could be the same as the Programming COM port if you do not have a 2nd COM port in your computer. Go to the top of the code and add this statement: “#include <delay. now you need to connect the serial cable to see the output. For STK500. Nothing should print at this point because you need to connect the serial cable to which the PCB kit of STk500 is outputting data to. Choose the COM port that is available. Open up Hercules Setup and go to the Serial Tab. read the manual and connect RX/TX and serial cable to the DB9 connector. 19. 20. Download “Hercules Setup” by searching for it in google. Go to Settings Æ Programmer and ensure that the COM port you chose is indeed the COM port connected to STK500 programming port (next to the DC power jack) 15. 13.h> 14. 18. 5.C) need to be included in your project.h) and the accompanying definition file (. 2. the header file (.C files in CodeVision Many times.H and . click on Project Æ Configure Click Add and browse to the C file you wish to add and click OPEN Click OK You do not have to open . Once CodeVision project has been opened. This can be accomplished in the following ways: 1. SJVE Page 6 of 8 .H file the same way. 3. you can right click on “Other Files” and click OPEN to open the header file.Include . for organization purposes. 4.C files in the same folder as the CodeVision project files. It is recommended to put the . On the left side. but you should open it in case you need to edit the header file easily.H and . The sample header file was used to develop a software‐driven UART. but code is omitted in the . If you are declaring a variable. This tells the compiler that the actual definition of the variable is somewhere else.Sample . you must include “extern” prior to the variable definition. Important things to note is that functions can be declared in this file.C file on purpose.H File The next figure shows what can be included in the header file. so it was once working. SJVE Page 7 of 8 . C File Note that in the . You can reference the previous two screenshots to develop your own .H>” In this file.H and .C file. In this file. remove the extern keyword from the variables and give them initial values. the variables are defined by the initial value along with the definition of the actual functions.H file as included by the statement “#include <USART. SJVE Page 8 of 8 .Sample . the only thing required is to include the . For arrays.C files. give the array size.