You are on page 1of 8

Contents

AboutthisTutorial..........................................................................................................................2
ImportantInformation....................................................................................................................2
CreateCodevisionProject...............................................................................................................3
Include.Hand.CfilesinCodeVision...............................................................................................6
Sample.HFile..................................................................................................................................7
Sample.CFile..................................................................................................................................8

SJVE

Page1of8

AboutthisTutorial

ThistutorialwillguideyouonhowtocreateaprojectinCodeVision.Furthermore,itexplainshowto
burnthecodeontoanAtmegachipusingSTK500boardandprogramthemicrocontrollertooutput
serialdatathatyoucanreadtoandfromthemicrocontroller.Finally,thereisasectionthatexplains
howtosetupheaderfilesinCodeVision

ImportantInformation

1. TheclockontheSTK500kitis3.686Mhz
TheclockonthePCBKitis16.000Mhz
2. DonotchangethefusebitsettingsinCodeVisionunlessyouknowwhatyouaredoing.
ChangingfusebitsettingcandisabletheAtmegamicrocontroller

SJVE

Page2of8

Selectingthechiptypeletsyouchoose
featuresofthechip.Youmustselect
thecorrectfrequencyoftheAtmega
otherwisemanyfunctionslikeUART
anddelayfunctioncallswillnotworkas
intended
4. Inthenextfigure,usercanchoosethe
settingsforUART.Thiswillenablethe
useofprintfandscanfstatements.
UARTenablesyoutoperform
input/outputfunctionsfortheAtmega
microcontrolleranditisalsousefulto
debugcode.

CreateCodevisionProject

1. OpenCodeVision
2. ClickFileNew

3. AfterclickingYesintheprevious
prompt,youcannowuseCodeVisionto
automaticallygeneratetemplatecode
forAtmegamicrocontroller.

5. SelectFileGenerate,SaveandExit
6. Youcannownameyourprojectfiles
andsavethemintoaprojectfolder.
7. CodeVisionwillgeneratethecodeand
nowyoucanburnthecodeintothe
Atmega,butfirst,afewsettingsneedto
bechanged.

SJVE

Page3of8

8. ClickonProjectConfigureandgoto
theCCompilertab
9. First,ifyouwishtodisplayfloating
pointnumbersusingprintf(%f,
myfloat);thenyouneedtoenablethis
feature.Donotenablethisfeature
unlessrequiredbecauseittakesalotof
codememoryspace.Underthe
(s)printffeatures,selectfloat,width,
precisionifneeded,otherwiseleaveit
alone.

10. NowbrowsetoAfterMaketab.Check
theProgramtheChipoptionand
choosetheoptionsdescribedbythe
nextfigure:

SJVE

Normally,youdonotneedtoVerifythe
codesodeslectVerifyoption.Program
FuseBit(s)isalsonotneededbecause
thiscanchangethewayAtmegastarts
upusingvariousclockoptions.
Atmegascomeprogrammedtouse
externalclock,whichisexactlywhatthe
PCBkitandtheSTK500usessodonot
changethisunlessyouknowwhatyou
aredoing.
11. ClickOK
12. Scrolldowntowardsthebottomofthe
codeandobservethatyourentirecode
needstobewithinthewhile(1)loop.
Thisisaninfiniteloopandthe
microcontrollersmusthaveoneinfinite
loopotherwisetheyitexecutecode
onceandstopworking.Addthe
followingcodeinsidethewhileloop:
printf(test\n);
delay_ms(100);
Addingthedelayisnecessaryotherwise
themicrocontrolleroutputsdatasofast
thatthePCbufferwilloverflowforthe
incomingserialdataandyourcomputer
mayfreezewhiletryingtoreadthedata
fromtheserialbufferchip.

Page4of8

PD0/PD1toRX/TXandconnectserial
cabletothe2ndDB9port.
21. Youshouldnowseethemicrocontroller
outputtingdata.

13. Gotothetopofthecodeandaddthis
statement:#include<delay.h>
14. GotoSettingsProgrammerand
ensurethattheCOMportyouchoseis
indeedtheCOMportconnectedto
STK500programmingport(nexttothe
DCpowerjack)
15. PressShift+F9andthenselectProgram
theChipoption
16. Thecodeisreadyandmicrocontrolleris
nowprintingprintfstatements,now
youneedtoconnecttheserialcableto
seetheoutput.
17. DownloadHerculesSetupby
searchingforitingoogle.
18. OpenupHerculesSetupandgotothe
SerialTab.ChoosetheCOMportthatis
available.Thiscouldbethesameasthe
ProgrammingCOMportifyoudonot
havea2ndCOMportinyourcomputer.
Choosethespeedinbps,whichmustbe
thesameastheoneinstep4.Click
OPENtoopentheCOMport.

19. Nothingshouldprintatthispoint
becauseyouneedtoconnecttheserial
cabletowhichthePCBkitofSTk500is
outputtingdatato.
20. ForthePCBkit,readthemanualand
connectRX/TXandserialcabletothe
DB9connector.ForSTK500,connect

SJVE

Page5of8

Include.Hand.CfilesinCodeVision

Manytimes,fororganizationpurposes,theheaderfile(.h)andtheaccompanyingdefinitionfile(.C)
needtobeincludedinyourproject.Thiscanbeaccomplishedinthefollowingways:
1.
2.
3.
4.

OnceCodeVisionprojecthasbeenopened,clickonProjectConfigure
ClickAddandbrowsetotheCfileyouwishtoaddandclickOPEN
ClickOK
Youdonothavetoopen.Hfilethesameway,butyoushouldopenitincaseyouneedtoedit
theheaderfileeasily.Ontheleftside,youcanrightclickonOtherFilesandclickOPENto
opentheheaderfile.
5. Itisrecommendedtoputthe.Hand.CfilesinthesamefolderastheCodeVisionprojectfiles.

SJVE

Page6of8

Sample.HFile

Thenextfigureshowswhatcanbeincludedintheheaderfile.Importantthingstonoteisthatfunctions
canbedeclaredinthisfile.Ifyouaredeclaringavariable,youmustincludeexternpriortothe
variabledefinition.Thistellsthecompilerthattheactualdefinitionofthevariableissomewhereelse.
ThesampleheaderfilewasusedtodevelopasoftwaredrivenUART,soitwasonceworking,butcodeis
omittedinthe.Cfileonpurpose.

SJVE

Page7of8

Sample.CFile

Notethatinthe.Cfile,thevariablesaredefinedbytheinitialvaluealongwiththedefinitionofthe
actualfunctions.Inthisfile,theonlythingrequiredistoincludethe.Hfileasincludedbythestatement
#include<USART.H>Inthisfile,removetheexternkeywordfromthevariablesandgivetheminitial
values.Forarrays,givethearraysize.
Youcanreferencetheprevioustwoscreenshotstodevelopyourown.Hand.Cfiles.

SJVE

Page8of8

You might also like