Home

Introduction to Microcontroller Programming and Communication

image

Contents

1. INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 11119 18 99490 05 9 COMMUNICATION 3 4 Uploading the Application Using CodeVision AVR For this project the uploading of all applications will be done using CodeVisionAVR It is possible to upload the program from the command line but it will not be used here For more information on this see the STK500 User Manual for a list of all the needed command line information At this point the myTWI Temperature sensor should NOT be connected This program only test the connectivity between the STK500 and the host PC The first step is to make sure that your project in this case the example STK5OO TEST from earlier If the project is open then skip to the next paragraph If it is not go File Open and select the proper file folder CNSTK500 TEST for the example here and select the file named STK500 TEST prj This is the project file that contains all the needed information See Figure 3 4 1 SK CodeVisionAVR File Edit Search View Project Lookin jj STK500 TEST n New Ctri N t Name Date modif Type gt Open CO c d Ji Exe Recent Places Reopen b 4 Linker J List d Obj Desktop l STK500_TEST J 8 STK500_TEST Chris A Computer Page Setup a 2 File name STK500_TEST 3 Exit Files of type Al files Figure 3 4 1 Opening a project in CodeVisionAVR Go to Settings select Programmer to begin the upload process See Figure 3 4 1 below S
2. PORTA OxFF DDRA 0x00 Port B initialization Func7 Out Func6 Out Func5 Out Func4 Out Func3 Out Func2 Out Func1 Out FuncO Out State7 1 State6 1 State5 1 State4 1 State3 1 State2 1 State1 1 State0 1 PORTB OxFF DDRB OxFF Port C initialization Func7 Out Func6 Out Func5 Out Func4 Out Func3 Out Func2 Out Func1 Out Func0O Out State7 1 State6 1 State5 1 State4 1 State3 1 State2 1 State1 1 State0 1 PORTC OxFF DDRC OxFF Port D initialization Func7 In Func6 In Func5zIn Func4 In Func3 In Func2 In Funci In FuncO In State7 T State6 T State5 T State4 T State3 T State2 T State1 T StateO T PORTD 0x00 DDRD 0x00 Port E initialization Func2 In FuncizIn FuncO In State2 T State1 T StateO T PORTE 0x00 DDRE 0x00 Timer Counter O initialization Clock source System Clock Clock value Timer O Stopped Mode Normal top FFh OCO output Disconnected TCCRO 20x00 TCNTO 0x00 OCRO 0x00 Timer Counter 1 initialization Clock source System Clock Clock value Timer1 Stopped Mode Normal top FFFFh OC1A output Discon OC1B output Discon Noise Canceler Off Input Capture on Falling Edge Timer1 Overflow Interrupt Off Input Capture Interrupt Off Compare A Match Interrupt Off Compare B Match Interrupt Off TCCR1A 20x00 TCCR1B 20x00 TCNT1H 0x00 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 38 INTROD
3. SCL line 3 LM75 Temperature Sensor Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 8 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 31829910 0 9 COMMUNICATION Section 2 Problem introduction 2 1 Initial Setup The microcontroller board must first be setup to accept programming To achieve this we must take the 6 pin ISP cable figure 2 1 3 and connect it from ISP6PIN to SPROG3 figure 2 1 2 Next connect the USB to Serial adapter into the main middle port figure 2 1 2 serial port Then connect the USB cable into an available port on the host PC Lastly connect the approved AC DC power adapter into the power connector located on the microcontroller figure 2 1 1 Figure 2 1 1 From top to bottom power light power switch power adaptor port The upper left also contains the reset button Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 9 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 318 99100 9 COMMUNICATION ee eee eEEE By T Figure 2 1 2 The above images show the location for the ISP6PIN cable and the correct RS232 port to be used for programming ttti gd gg AFTTITITTITOS a egar o te he 5 3 win a S9 wn cts iiiiijijiii Ew yi Figure 2 1 3 Sample image of the proper RS232 connection from STK500 to host pc the 6 pin ISP cable connecting the ISP6PIN to SPROG3 and the power adaptor location 2 2 Port Se
4. Analog Comparator SPI 12C 1 Wire Analog Comparator SPIL 12C 1 Wire LCD BitBanged Project Information LCD Bit Banged Project Information Chip ExtemalSRAM Ports Chip External SRAM Ports Port 4 PotB PortC PotD Porte Port PotB PotC PotD Port E Data Direction Pullup Dutput Value Data Direction Pullup Output Value BitO In T Bio BitO In P Bit O Bit1 In T Bit Bit1 In P Bit 1 Bit2 In T Bit 2 Bit2 In P Bit2 Bit3 In T Bit 3 Bit3 In P Bit 3 Bit4 In T Bit4 Bit4 In P Bit 4 B5 In T Bit5 Bit5 In P Bit 5 Bit amp In T Bit 6 Bit amp In P Bit 6 Bt In T Bit Bit In P Bit Figure 3 1 6 The default setting is on the left and the target settings are on the right Make your setting match those on the right Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 20 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI ler eyes COMMUNICATION External IAQ Timers USART External IRQ Timers USART Analog Comparator LSPL I2C d Wire Analog Comparator SPL l2C Wire LCD Bit Banged Project Information LCD BitBanged Project Information Chip Esxtemal SRAM Ports Chip External SRAM Ports PortA PotB PotC PotD PortE Port A PotB PotC PotD PotE Data Direction Pullup Output Value Data Direction Pullup Output Value BitO In T Bid BitO Out 1 Bio Bit1 In T Bit 1 Bit1 Qut 1 Bit Bit2 ln T Bit 2 Bit2 Out 1 Bit2 Bit3 In T Bit 3 Bi
5. INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 9949 05 9 COMMUNICATION Christopher S McCoy Dr Zalewski CEN 3213 Florida Gulf Coast University Fort Myers FL December 4 2009 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 1 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 99190 05 9 COMMUNICATION Section 1 Introduction Overview This project will provide an overview including sample work of the interaction between a user an Atmel AVR STK500 P NHATSTK500 microcontroller external temperature sensor and LED display Included will be a short introduction and overview of the integrated development environment IDE that Atmel packages with the microcontroller card as well some sample diagnostic applications used to test the overall functionality of the controller This project will serve as a step by step manual so that any user will be able to follow page by page and recreate the work have outlined Problem Introduction The goal of this project is to compile a detailed and easy to follow tutorial detailing the setup and implementation of an Amtel AVR STK500 microcontroller board temperature sensor and LED display This will be accomplished though a detailed set of step by step instruction including illustrations and labeled photos showing the correct setup A section outlining the setup and use of the Atmel IDE and any other required testing applications Another secti
6. Revision 1925C AVR 3 03 March 2003 www atmel com atmel acrobat doc1925 pdf gt 2 Atmel Corp 8 bit Microcontroller with 8K Bytes In System Programmable Flash Revision 2512J AVR 10 06 October 2006 lt www atmel com dyn resources prod documents doc2512 pdf gt 3 myAVR myTWI Temperature Sensor 1 02 Technical Description pp 1 10 August 2008 4 Atmel Corp AVRO33 Getting Started with the CodeVisionAVR C Compiler Revision 2500C AVR 04 08 April 2008 lt http www atmel com dyn resources prod documents doc2500 pdf gt 5 Atmel Corp AVRO33 Getting Started with the CodeVisionAVR C Compiler 8 bit Microcontrollers Application Note Revision 2500C AVR 04 08 pp 1 18 April 2008 lt http www atmel com dyn resources prod documents doc2500 pdf gt 6 myAVR myAVR LCD add on Viewed December 1 2009 lt http shop myavr com Additional 20modules myAVR 20LCD 20add on htm sp article sp php amp artID 15 gt www myavr info download produkte lcd pb lcd de en pdf gt 7 myAVR mySmartUSB MK2 Viewed December 1 2009 lt http shop myavr com index php spzarticle sp php amp artlDz242 gt lt http www myavr info download produkte mysmartusb mk2 pb mysmartusb mk2 de en pdf Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 36 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 9919 05 9 COMMUNICATION Appendix A Source Code for Temperature Sensor and Motor Integration e
7. The entire CodeVisionAVR project file is available for download at my website Hinclude mega8515 h Standard Input Output functions include lt stdio h gt Contains printf and sprintf include lt delay h gt Contains delay ms include lt stdlib h gt Contains abs 12C Bus functions Hasm equ i2c port 0x07 PORTE equ sda bitzO equ scl bitz1 endasm include lt i2c h gt LM75 Temperature Sensor functions include lm75 h Standard Input Output functions include lt stdio h gt Declare your global variables here void main void Declare your local variables here variable to store the temperature taken from the sensor int tempC_x10 0 1 second delay is taken between readings int DELAY_ms 1000 stores current temps used to compare against maxTemp in order to determine if the fan should be enabled int temp 0 variable to hold max allowed temp before the fan should be enabled int maxTemp 0 variable used to enable disable the fan operation int flag 0 Input Output Ports initialization Port A initialization Func7 In Func6 In Func5zIn Func4 In Func3 In Func2 In Funci In FuncO In State7 P State6 P State5 P State4 P State3 P State2 P State1 P StateO P Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 37 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 11119 108 99190 05 9 COMMUNICATION
8. University Page 27 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI A emcee COMMUNICATION Once the Chip Programmer is open there are several settings that we must change First select the proper MCU ATmega8515L for this Next select the SCK Frequency Default for our MCU is 230400 S CodeVisionAVR Chip Programmer STK500 AVRISP ES E File Edit Program Read Compare Help Chip ATmegaB5l5L fi Program All SCK Freq 230400 Hz FLASH EEPROM Start 0 h End 345 h Start 0 h End 1FF h Checksum 1930h Checksum FEOOh Chip Programming Options FLASH Lock Bits Program Fuse Bis No Protection CKSELO 0 CKSEL1 0 Programming disabled z EUR TRI SUTO 0 Programming and Verification disabled suT1 0 BODEN 0 Boot Lock Bit 0 BO1 1 BO2 1 B01 0 BO2 1 B01 0 B02 0 B01 1 BO2 0 Boot Lock Bit 1 B11 1 B12 1 B11 0 B12 1 B11 0B12 0 B11 1 B12 0 BODLEVEL 0 BOOTRST 0 BooTsz0 0 BODTSZ1 0 EESAVE 0 CKOPT 0 WDTON 0 C S8515C 0 Check Signature V Check Erasure Preserve EEPROM V Verify Figure 3 4 5 Chip Programmer configuration With the programmer open select the Program menu Erase Chip This will ensure that the chip is blank before we load the program Figure 3 4 6 Erasing the chip each time you reprogram it ensures that the memory used will be accurate and that nothing is corrupt S CodeVisio
9. to the project For this example we will use STK5OO TEST as the name for all the required files the extensions will obviously be different The following illustrations Figure 3 1 10 show these windows BK Sere C Cempier Source He GX Seve Compiler Project File Saven Ji STKWO TEST Oot4 m5 Swain U STKRS TEST 0J nm gt Name Date mod Type Size r Mant Date modi Type fue This folder is empty E That Fokus ix empty Recent Pleces Recent Places Desktop Desktop Chm Chrig A A Computer Compuber Network Hertsi Fle nave STKS00 TEST fe name STKO TEST Save at type C Compiler fiaa c Cane Sum gat pa Pest Hen or Cancel _ fll Save C Users Chres Desktop CEN3212 Proyect McCoyProyect antstied cwp As mad Save jj STKS00 TEST Q2 i a Name Date modif Type Size e No gems match your search Recent Places Desktop Chris A Computer Network ferme RG TES Cm Save astyee CoddeWViaardAVR project fies cp Cancel Figure 3 1 10 File save screens This concludes the software and project setup portion of this guide Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 22 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 99190 05 9 COMMUNICATION 3 2 Basic Application Example In CodeVisionAVR make sure that the STK500 TEST C is open Copy the following code into this file include delay h Contains d
10. 2 4 1 Once this is complete connect the wire to PBO and PB1 on PORTB Figure 2 4 2 See Figure 2 4 3 for completed setup Figure 2 5 1 DC Motor with wire attached j E s s i Li P a PORTE AUX h a CS p 2 Figure 2 5 2 Motor connection to STK500 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 16 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI A emcee COMMUNICATION Figure 2 5 3 Completed setup after section 2 1 2 2 2 3 2 4 and 2 5 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 17 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 3182 991008 COMMUNICATION Section 3 Required Software Sample Applications and Running an Application 3 1 CodeVision AVR Introduction and Initial Project Setup There are numerous IDE s available to use to program any of the AVR devices For this project I have chosen to focus on CoedVisionAVR It is easy to use reliable and efficient Outlined throughout this section are the steps needed to successfully install start a new project and ultimately program the MCU Begin by visiting http www hpinfotech ro html cvavr htm to download the evaluation more than adequate for our needs of the software Save the file and then double click to execute once it has finished downloading A directory must be created to store the files used in this example Go to your C drive and creat
11. E CodeVisionAVR host Shared Folders Mruth324 File Edit Search View Project Tools Settings Help 1 ap c x i 3 SA Editor oy Debugger d aD M MS 03 37 ASE APE v o I f Programmer F Code Navigator XD M Cc Terminal M Ola sk asm ru MENN Je amp Figure 3 4 2 Starting the programmer Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 26 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 99419 05 9 COMMUNICATION The window that opens now requires you to choose AVR Chip Programmer Type From the dropdown menu select Atmel STK500 AVRISP Make sure the COM port matches that of what is listed in device manager from section 3 3 This is the setting where your USB RS232 adapter is so that the software knows where to the MCU is connected See Figure 3 4 3 5 Programmer Settines ES AVR Chip Programmer Type Atmel STK500 AVRISP v Communication Port COM3 m ATmega153 CKDIV8 Fuse Warning Figure 3 4 3 Proper Programmer configuration The next step is to select Tools then Chip Programmer See Figure 3 4 4 E CodeVisionAVR C Users Chris Desktop CEN3212 Project McCoyProjectMct File Edit Search View Project DLWA Settings Help iia CodeWizardAVR Shift F2 Debugger Shift F3 p Fl Functions 174 ou 175 pa Hasdar LI McCoyProj c Figure 3 4 4 Chip Programmer Christopher S McCoy Fall 2009 Florida Gulf Coast
12. ON TO MICROCONTROLLER PROGRAMMING AND DIN A emcee COMMUNICATION com3_STK500_DAQ Hyperterminal moea m ee ee ROSRGRR ome m qe Fie Edt View Cal Transfer Help ia 55 same 24 E E e PA S Connected 0 00 25 Auto detect 115200 6 N 1 SCROLL CAPS NUM Captun Figure 3 6 2 Correct output in HyperTerminal for the sample application using the myTWI Temperature Sensor Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 33 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 994190 05 9 COMMUNICATION 3 7 Application Featuring the myTWI Temperature Sensor and DC Motor The program incorporating this application can be seen in Appendix 1 Follow the hardware setup outlined in Section 2 5 This application is based off the previous example with the myTWI Temperature sensor with several changes to incorporate the motor and change the output This application reports the current temperature read by the sensor It is then reported back and printed in the HyperTerminal window If the temperature read is above 27 degrees Celcius the printed messaged changes from just the temperature to WARNING The temperature is current temperature degrees Celsius Fan Starting When the temperature falls below the 27 degree threshold the output returns to simply printing the temperature and the motor shuts off See Figure 3 7 1 for same HyperTerminal output 8 STK500 HyperTermina
13. PCF8563 F 41 gt Enabled Address V 0 Output Active High Temperature C Hyst 75 40 5 80 Figure 3 6 1 Setting PORTE to use the temperature sensor Add the following code instead of that listed in Section 3 1 Once copied follow the steps listed in Section 3 3 to save compile and load the new program into the MCU Next follow the steps in Section 3 5 to use HyperTerminal to execute See Figure 3 6 2 for the proper output Standard Input Output functions include lt stdio h gt Contains printf and sprintf Q0 include delay h Contains delay ms include lt stdlib h gt Contains abst The int 1m75 temperature lO0 unsigned char chip function returns the temperature in degrees C times 10 retrieved from the LM75 sensor with the address chip CAUTION A 300ms delay must be present between two successive Galle to thas function xt FF Ro F F Get the temperature as an integer in degrees Celcius times 10 tempC x10 lm75 temperature 10 0 PORTC PORTC toggle LED values Send the temperature data via USART Divide by 10 to get the proper whole number temperature Append the decimal value of the temperature to one place by using modulus 10 printf i u tempC x10 10 abs tempC x10 10 PORTC PORTC Delay for DELAY_ms amount of time delay_ms DELAY_ms Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 32 INTRODUCTI
14. RODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 111 9 3182 99100 COMMUNICATION Connect To com3_5TK500_DAQ Enter details for the phone number that you want to dial Country region Area code Phone number Connect using COM3 COM3 Properties Port Settings Bits per second 115200 z Data bits 3 Parity N one Stop bits 1 Flow control None Figure 3 5 3 HyperTerminal port settings 45 com3 STK500 DAO HyperTerminal Jog Fie Edit View Call Transfer Help Dg es ut E53 er USART Communication Test Succeeded Hello Goodbye Connected 0 00 33 Auto detect 115200 8 N 1 Figure 3 5 4 Successful execution of sample program Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 31 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 11119 18 99190 05 9 COMMUNICATION 3 6 Sample Program implementing the myTWI Temperature Sensor Begin by following the steps in Section 3 1 with a couple changes Create a new directory to store the project files in For this example we ll use CXTemp Example Follow the steps listed in 3 1 The exceptions to this is Select the tab IC2 PORTE and check Enabled under the LM75 tab See figure 3 6 1 External IRO Timers USART LCD Bi Banged Project Information Chip External SRAM Ports Analog Comparator SPI l2C 1 wire I2C Pott PORTE x SDABit o w SCLBit 1 w LM 5 051621
15. UCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 9919 05 9 COMMUNICATION TCNT1L 0x00 ICR1H 0x00 ICR1L 0x00 OCR1AH 0x00 OCR1AL 0x00 OCR1BH 0x00 OCR1BL 0x00 External Interrupt s initialization NTO Off INT1 Off INT2 Off MCUCR 0x00 EMCUCR 0x00 Timer s Counter s Interrupt s initialization TIMSK 0x00 USART initialization Communication Parameters 8 Data 1 Stop No Parity USART Receiver On USART Transmitter On USART Mode Asynchronous USART Baud Rate 115200 UCSRA 0x00 UCSRB 0x18 UCSRC 0x86 UBRRH 0x00 UBRRL 0x01 Analog Comparator initialization Analog Comparator Off Analog Comparator Input Capture by Timer Counter 1 Off ACSR Ox80 12C Bus initialization i2c_init LM75 Temperature Sensor initialization thyst 75 C tos 80 C O S polarity 0 Im75 init 0 75 80 0 Create a flag variable set it to 1 when the lights are enabled once the temp falls below the threshold the application will exit the if loop and move on to where the flag will be reset while 1 Get the temperature as an integer in degrees Celcius times 10 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 39 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 108 994190 05 9 COMMUNICATION tempC x10 21m75 temperature 10 0 Send the temperature data via USART Divide by 10 to get
16. ack and connect it to GRN and VTE pins of the PORTE header on the MCU Ensure that the red wire connects the 5V pin to the VTW pin and that the black wire connects the ground on the sensor to the ground on the PORTE header Figure 2 4 2 Connect the SDA SCL cable blue and white to PEO and PE1 on the PORTE header Ensure that the blue wire connects SDA and PEO while the white wire connects SCL and PE1 pins Figure 2 4 2 PF pi o X14 GNI Figure 2 4 1 and 2 4 2 Two wire connection to the temperature sensor and corresponding MCU connection on PORTE header Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 14 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 99190 05 9 COMMUNICATION VR AREF PPPPPPPPPPPppy 4 big had i b oP i 4 wrPrrrrrrer hd m e 7 TE Ede P PPPPPPPPpPPpPpE T oi Figure 2 3 3 Complete MCU following steps listed in 2 1 2 2 2 3 and 2 4 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 15 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 11119 18 99190 05 9 COMMUNICATION 2 5 The DC Motor This section will detail the setup of the motor The motor used in this project is available from RadioShack part number 273 0258 You will need an additional two wire cable to attach to the motor in order to connect it to the STK500 Connect one wire to pole and the other to the pole Figure
17. aner FBR Mb codes ENF uuu meres ER 3 a 2 D saiae LIM fern es ees erem at Fregecs Holey t m Inet Thia gpregram r s produced hy Lh Eres Fier EPD Funchani lCodaNirardAUM Vlog 4a valcatios hEEn wer bad ntecech oo LE act c Vaergion au ere eri Wf Fonction Cal Tee 5 3 Eid l amp urthor Fresvars for sralcation and non commercial cae ccly m f man Company Eg GS TACK Fane O T Smaa z f pira E g D5TACE Fune 2 0 ara 1 amp Enip typ nnrir 7 Program type T 1 m Figure 3 2 3 Any errors that might occur will be here Christopher S McCoy Fall 2009 Florida Gulf Coast University Aurumatis Propran lanaFrarsr je Copyright idS 4 IlO03 Favel XNaidus EF I nFoTack s r l f Aaji LiL Appiiearimm INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 11119 18 99190 05 9 COMMUNICATION 3 3Host PC Required Setup Before we can test the connectivity we must make sure that the host PC is properly configured Specifically we need to make sure that the USB RS232 convertor is properly configured If the adapter came with a driver CD make sure you insert and install the drivers Once this is complete right click on Computer select Properties and select Device Manager from the left hand side of the window Figure 3 3 1 In the Device Manager window select Ports COM amp LPT You should see in the drop down USB Serial Port COM3 The COM numb
18. e a new fold named STK500 TEST The location should read C STK500_ TEST Once the download has completed and the software is installed press the start menu All Programs CodeVisionAVR folder and then select CodeVisionAVR C compiler Evaluation I3 Wis dows Medie Player ig Windows Meehag pace amp Windows Motile Device Czntcr g Windows Movie Maker iE Widows Phatu Gelly ET Wir dew Update b Accessoris da Active 5C Burrer b AIM Je Atmel AVi lois Aud o Converter ME Corel sona C Compiler i velurh Jee ga CozeV s onAV7 C Corpilzr Evelucti jal Un netal CodzVizizn VR C Comcile Connal To Control Panel Default Programs ub Del Support Fdo and Support 4 Del Support Center ide De Webcam b Dink Ixtres anz Upgrades ub F ngerprinz Reader Suite Gare d HP de ints SRO het Wireless Jo Inzzl F Marx Storage Menager iPhone Con guretion Ltilizy iT ores 7 agitech Je Megiclso ub Meintena gt ce ub Mehwareby es Arni Malere d Ihi7rosolk V ause J Microsoft Offizc Microsoft Office Live Add in 4 Figure 3 1 1 Start menu illustration to launch CodeVisionAVR Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 18 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DIN A PNE COMMUNICATION Next click File New and a window will open Figure 3 1 2 Select Project and click Ok Figure 3 1 3 SK CodeVisionAVR File Edit Search View Project Tool
19. elay ms Send the following message via USART communication printf USART Communication Test Succeeded r n Check state of PORTA Pins if PINA OxXFF If a button is pressed input pulled low toggle bits on PORTC PORTC ePORTOS Send the following message via USART communication primte Bel lol r n gt Delay so flashing LED s are visible delay_ms 1000 printf Goodbye r n PORTC PORTC Once this is complete go to File Save all to save the changes made to all files Figure 3 2 1 Next select Project Build All to compile Figure 3 2 1 This generates all the required files that will be send to program the MCU in a later step This should compile error free Figure 3 3 2 but if for some reason there are you can see them in the Errors tab towards the bottom of the IDE Figure 3 3 3 E CodeVisionAVR CAUsers Chris D fil CodeVisionAVR CAUsersVChris Desktop VCEN3212 Project McCoyProj pest fede 7 E id Edit Search View Project File Edit Search View JO Tools Settings Help i 3 New Ctrl N Aai 5D c 2 H a 5j Check Syntax BE Open Ctrl O 5 7 E m m N mom a Compile F9 i Reopen bee 4 Build Shift F9 E Saye K amp Code Navigator Ys 22 Build All Ctrl FO ie IE SAC Ip E CodeVisionAVR Stop Compilatic Ez Project McCoyPro z SaveAl Shift Ctrl S Other Files V Clean Up Cj Clo
20. er will likely be different as your computer may assign this a different COM port Figure 3 3 2 If you do not something similar to this then you adapter is not installed correctly and need to follow the steps of this section again it Open jE y Control Panel System E Y Sea Explore SS Manage Gas i d Scan with AVG View basic information about your computer O Device Manager Windows edition Wap telo mie fy Remote settings Disconnect Network Drive Windows Vista Home Premium 9 System protection Create Shortcut Copyright 2007 Microsoft Corporation All rights reserved O Adv ed sys S 5 i Delete y Advanced system settings Service Pack 1 Rename Upgrade Windows Vista File Action View Help e 52 ts eA H A Batteries 5 a Biometric m q Computer H Disk drives cM Display adapters H DVD CD ROM drives E oa Human Interface Devices c IDE ATA ATAPI controllers E y IEEE 1394 Bus host controllers 5 Imaging devices B E Jungo H 2 Keyboards H A Mice and other pointing devices H E Monitors H E Network adapters Ports COM amp LPT Y USB Serial Port oO i Processors B E SD host adapters H Q Sound video and game controllers H Storage controllers fq System devices H Universal Serial Bus controllers Figure 3 3 2 USB RS232 adapter setup properly Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 25
21. he STK500 The STK500 is composed of 3 sections as illustrated above The target section contains the plastic dual in line sockets programming headers and the jumpers used in board configuration The control section provides an interface for the host PC and the MCU to communicate The user interface section contains the LED s push button switches and input output headers Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 5 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 3182 eyes COMMUNICATION eader for iet Bode ae Expansion Boards Target AVR Options Setting Target Reset i Jumpers Push Button Switches ower Switch Header for 17 BPa Switches Power Connector gt Parallel Programming RS 232 Interface Headers Header RS 232 Port g for Programming DataFlash Interface Status LED Header RS 232 Port for Communication Socket for Header for LEDs Crystal Program Button LEDs 10 pin ISP Header Header for for External Target Only Expansion Boards Target ISP Headers 6 pin ISP Header Figure 1 4 STK500 Components 1 4 Figure 1 5 ATMEGA8515L 8PU preinstalled at SCKT3000D3 This is an 8 bit RISC MCU in PDIP form All 6 pin headers in the target socket section are color and number coordinated with their respective target headers Once the ISP and its target are connected this also allows all other sockets to Christopher S McCo
22. ith corresponding device driver Test System Two Specifications Intel Core2Duo Model T7250 2 00GHz 3 0GB of DDR2 RAM 150GB Fujitsu HDD Model MHY2160BH Dynex DX UBDB9USB to RS2323 serial port adapter cable with corresponding device driver Note All testing and development will be done on a Windows Vista both 32 bit and 64 bit based machine Compatibility with Windows XP will also be tested Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 3 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 3182 eee COMMUNICATION ig Figure 1 1 6 wire 10 wire and 2 wire cables Figure 1 2 RSR232 serial cable and Dynex RS232 to USB adapter cable LIEST LB re LUG IN CLASS 2 mp TRANSFORMER LAS TSG NE ATE Risk of electri shock Figure 1 2 Power adapter used and the adapter wire provided with kit not used Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 4 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 111 9 31829910 0 8 COMMUNICATION uL eV 9 M M MOM M MM B my fit iiiiiiine TeeTT ete ee E EU m jiiiiiiiiis 3 t cs t1 se 21111111107 pe zu niti Bu d Siem gt Witt DE Hum 4 La a Te it c NH lt EXI a LET EL NNNHNN 2M THH SIM Ere LES ti TI t es s MEWE MEME 4 E04 EL A E ta User Interface Target Socket Control Figure 1 3 Section diagram of t
23. l lt a E Ai a co 9 jab Sm View Call Transfer Help The current temperature is 24 5 degrees Celcius The current temperature is 25 5 degrees Celcius The current temperature is 26 0 degrees Celcius The current temperature is 26 5 degrees Celcius The current temperature is 26 5 degrees Celcius WARNING Temperature is 27 0 degrees Celcius fan Starting WARNING Temperature is 27 0 degrees Celcius fan Starting MARNING Temperature is 27 0 degrees Celcius fan Starting WARNING Temperature is 27 0 degrees Celcius fan Starting The current temperature is 26 5 degrees Celcius The current temperature is 26 5 degrees Celcius Connected 0 00 19 ANSIW 115200 8 N 1 Figure 3 7 1 Sample Output to modify the sensor program Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 34 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 99190 05 9 COMMUNICATION Section 4 Conclusion The basis of this project was to establish connection between a host PC and the AVR STK500 8 bit microcontroller This was accomplished through the example program in Section 3 4 The project was then expanded to include the myTWI Temperature sensor in Section 3 6 with the code and illustrations of the proper output The last iteration on this project was to build on the temperature sensor This was done by including a small electric motor that would be activated based on the temperature reading taken fr
24. nAVR C hip Programmet File Edit Program Read Compare Help AK Erase Chip Chip Blank Check ivi SCK F Si FLASH Hz esl T EEPROM Start S Lock Bits 5 h Sp Fuse Bit s heck all C ss pp Figure 3 4 6 Erase Chip option under the Program menu Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 28 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI N A emcee COMMUNICATION Next select the Program menu then Flash This loads the current project HEX file onto the MCU Figure 3 4 7 S CodeVisionAVR C hip Programmet File Edit Program Read Compare Help SK Erase Chip 1 Chip 3 Blank Check vl SCK F S FLASH iw He e EEPROM FLASI id Start Si Lock Bits E lh 5 Fuse Bitis 1 Check S al E m ae eee Figure 3 4 7 Flash option in the Chip Programmer This concludes the MCU programming You can now close the Chip Programmer and the CodeVisionAVR IDE if you would like and move on to the next section Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 29 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 99190 05 9 COMMUNICATION 3 5 Running the Application Using HyperTerminal To begin press the reset button on the STK500 This resets the application and starts it from the beginning The application will run continuously while the unit is powered on because of the infinite loop located in the main body of the applica
25. om the sensor The application output changed based off this reading and the motor was activated based on the reading The next step in expanding this project could be either by the addition of an LCD screen that would also display the output It would be a simple integration using the myAVR LCD add on 6 This is a multi line LCD screen that can be customized to work with nearly anything This could be coupled with remote access through something like a webpage allowing the sensor to be monitored remotely as well as on site The addition of the mySmartUSB MK2 USB programmer would make the unit much more user friendly Serial is legacy technology and the USB Serial adapters are notorious for their configuration problems It is nearly possible to find a host PC that comes standard with a serial port USB however is one of the most widely used I O ports worldwide It is on nearly every PC made This ability would greatly expand the market for this system Multi platform support for example Apple Linux etc would also be an option Embedded systems need to be flexible and having a system that has only been tested on a Windows based system severely limits this flexibility Taking the time to develop this would be highly beneficial Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 35 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 12119 18 9919 05 9 COMMUNICATION Citations 1 Atmel Corp AVR STK500 User Guide
26. on will outline the application development and implementation It will include pseudo code as well as sample sections from the actual program Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 2 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 99490 05 9 COMMUNICATION Required Materials and Component Illustrations Atmel AVR STK500 Starter Kit P NHATSTK500 Personal Windows Based Computer If using Windows Vista you will need to download HyperTerminal See section 4 for more information 10 15 V AC DC power supply with 500mA minimum mwTWI Temperature sensor available from http shop myavr de Add Ons9620und9620Module myTWI9620Add On9620Temperatursensor htm spz article sp php amp artlD 71 Metal Gear 1 5 3VDC Motor RadioShack 273 058 http www radioshack com product index jsp productid22102828 Atmel AVR Studio 4 16 or later IDE Windows based development tool other operating system compatible IDE s are available for download from various websites but will not be covered in this guide Minimum System Requirements are as follows 486 Processor Pentium recommended 16MB of RAM 15MB of HDD space Windows 95 98 2000 or NT 4 0 115200 baud RS232 Port Test System One Specifications Intel Core2 Quad CPU Q6600 2 40GHz 8GB Corsair DDR2 800MHz RAM 500GB Western Digital HDD model WD5000AACS Windows Vista Ultimate 64 Dynex DX UBDB9 USB to RS2323 serial port adapter cable w
27. s Settings Help D New CtrHN amp Open Ctrl O K Reopen RE Code Information File Type CO Source Page Setup Project 4 Exit 9 You are about to create a new project e Do you want to use the Code WizardAVR Figure 3 1 4 Select Yes to confirm the start of the new project The window that opens now is the CodeWizardAVR Chip setup window The first tab that is open is to select Chip being used Select ATmega8515L from the Chip dropdown Make sure the Clock setting is 3 6864MHz the correct frequency for out MCU Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 19 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 12119 18 99190 05 9 COMMUNICATION External IRQ Timers USART Analog Comparator SFI 12C 1 wire LCD BirBanged Project Information Chip External SRAM Ports Chip ATmega8515L wl Clock 3 6864 tj MHz Check Reset Source Program Type Application m Figure 3 1 5 Chip setup tab Next select the Ports tab Select PORTA and make the settings match those of Figure 3 1 6 The PULLUP OUTPUT value must be changed from T to P Once this is complete select PORTC Make sure your window matches the one as shown in Figure 3 1 7 In this case the Data Direction must be changed from In to Out and the Pull up Output needs to be changed to 1 ExemallEFQ Timers USART External IRQ Timers USART
28. se Ctrl F4 Information 5 Close All fff Convert to Library Page Setup Ref zato Previous Print Preview d Notes Print Ctrl P s Ss SN Configure v X ius ESSE J TI Aa DSTACK R Mi 15 Figure 3 2 1 Save All and Build All Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 23 Ki Information Compiler INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI L PNE COMMUNICATION Chip ATmega8515L Clock frequency 3 686400 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 const stored in FLASH No 8 bit enums Yes Enhanced core instructions Yes Automatic register allocation Yes Smart register allocation Yes Build 34 10470 line s compiled No warnings Bit variables size 0 byte s Data Stack area 60h to DFh Data Stack size 128 byte s Estimated Data Stack usage 32 byte s RAM Global variables area Eh to E3h RAM Global variables size 4 byte s Hardware Stack area E4h to 25Fh Hardware Stack size 380 byte s i Heap size 0 byte s EEPROM usage 0 byte s 0 0 of EEPROM Program size 303 words 1818 bytes 22 2 of FLASH Ele dt Search yew Broject Iesm gemings Hep bec uugccoofiSBe i nan Bajza zjale annen BTVROLM O A SRS MN Bees adya 1 1X BE Coda Mavig
29. t3 Out 1 Bit3 Bit4 In T Bit4 Bit4 Out 1 Bit4 Bit5 In T Bit5 BitS Out 1 Bit5 Bit6 In T Bit 6 Bit6 Out 1 Bit Bit n T Bit Bit Out 1 Bit Figure 3 1 7 Default settings on the left target settings on the right Make your settings match those of the right The next step is to select the USART tab and check both the Receiver and Transmitter boxes Next change the Baud Rate to 115200 Ensure you window matches those of Figure 3 1 8 Analog Comparator SPI 20 1 Wite LCD Bit Banged Project Information Chip JL External SRAM Ports External IRQ Timers USART Receiver Rx Interrupt Transmitter _ Tx Interrupt Baud Rate 115200 v x2 Baud Rate Error 0 2 Communication Parameters 8 Data 1 Stop No Parity vi Made Asynchronous vi Figure 3 1 8 USART Tab make sure your window matches this Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 21 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND DI N A PNE COMMUNICATION 3 CodeWizardAVR untitled cwp File Edit Help D New L mr Open LJ Save Ic a Agi Save As ict Informa Fort Q Program Preview USAF E Generate Save and Exit 4 Exit Transmitter _ Tx Interrupt Interrupt Figure 3 1 9 Go File Generate Save and Exit as shown above A window will open asking you to save a file It is recommended that you use the same folder for all files pertaining
30. the proper whole number temperature Append the decimal value of the temperature to one place by using modulus 10 temp tempC x10 10 maxTemp 27 if temp gt maxTemp printf WARNING Temperature is i u degrees Celcius fan Starting n n r tempC_x10 10 abs tempC_x10 10 enable the port to start the motor if flag O PORTC PORTC flag 1 else disable or make sure the port is disabled and change flag value temp is under the threshold of 27 the port should be off if flag 1 disable the port and reset the flag PORTC PORTC flag 0 printf The current temperature is i u degrees Celcius n n r tempC_x10 10 abs tempC_x10 10 Delay for DELAY_ms amount of time delay_ms DELAY_ms Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 40
31. the push button switches is pressed Figure 2 3 1 Illustration for SWITCHES to PORTA connection using a 10 pin cable Using another 10 pin cable connect LEDS header to the PORTC header Make sure the same pin correlation is followed in this step as the one above Figure 2 3 2 This enables the MCU to turn on or off the LED s Figure 2 3 2 Illustration of 10pin cable connecting LEDS to PORTC Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 12 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 31829910 0 89 COMMUNICATION FTTTTTTTID d amp BR HALLO L1 D ba 5 a PE LL uu E E m E TU SETITITITTIIIII 5 Md E p a Figure 2 3 3 STK500 after completing steps outlined in 2 1 2 2 and 2 3 Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 13 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T0 11119 18 99190 05 9 COMMUNICATION 2 4 myTWI Temperature Sensor Setup Start by taking a 2 wire cable red and black in the illustration and connecting it to the ground and voltage 5V pins on the temperature sensor Figure 2 4 1 Next take another 2 wire cable blue and white in the illustration and connect the SDA and SCL pins Figure 2 4 1 T amp 2 SDA l sc J 5 V GND TWI FC e CN Figure 2 4 0 myTWI Temperature sensor pin out Take the cable connected to ground 5V red and bl
32. tion This program requires that the board be configured following the steps outlined in sections 2 1 2 2 and 2 3 If the unit is not configured this way power it down and correct this immediately Windows Vista does not include HyperTerminal You can correct this by extracting hypertrm dll and hypertrm exe from any Windows XP computer You can then place these files in a folder anywhere on your computer and execute the program by running hypertrm exe If you do not have access to a Windows XP machine you can visit my website at http satnet fgcu edu csmccoy index htm and download a zip file containing these files Begin by opening HyperTerminal Name the current session something like STK5OO TEST and press ok Figure 3 5 1 Select the proper COM port in our examples this is COM3 and press OK Figure 3 5 2 Press ok and ensure that the Bits per Second is set to 115200 Data Bits is set to 8 Parity set to none Stop Bits set to 1 and Flow Control set to none Figure 3 5 3 Press Ok to continue Press the reset button on the PCB press one of the push buttons and the HyperTerminal window should look like Figure 3 5 4 Connection Description 2 T3 New Connection Enter a name and choose an icon for the connection Name com3_STK5S00_ DAL Icon 3 a5 358 ok Cancel Figure 3 5 1 Setting up the connection Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 30 INT
33. tup for Data Transmission Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 10 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 3182 99100 COMMUNICATION Disconnect the power adaptor and serial cable if connected before doing any of the following steps The alternate serial port closest to the edge on the board figure 2 1 2 is not configured by default to allow the microcontroller to send data to the host PC To enable this functionality take one of the 2 wire cables and connect it from RXD and TXD pins to the PDO and PD1 of PORTD figure 2 2 1 Please refer to the pg 64 in the ATmega8515 datasheet see citation for availability for detailed description as the user manual does not detail this process Figure 2 2 1 Connect the 2 pin cable from the RXD TXD connection to PDO PD1 making sure that the green wire connects RXD to PDO 2 3 Conectivity Configuration Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 11 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 111 9 318 meee COMMUNICATION This section will outline the necessary hardware configuration for in system programming onboard and host to board communication Using a 10 wire cable connect the SWITCHES header to the PORTA headerp ensuring that PAO connects to SW1 and so on Figure 2 3 1 There is a red stripe on the cables to help ensure this is accomplished This allows the MCU to receive input if one of
34. y Fall 2009 Florida Gulf Coast University Page 6 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 111 9 3182 991008 COMMUNICATION be programmed that are bordered in the same color You can seem some examples of this above and later on in section 2 when the hardware connectivity is explained As stated above the user interface section contains the push buttons LED s and the I O ports used to activate the LED s or notify the MCU of a button press There are 8 programmable buttons as well as 8 corresponding LED s PAD PA Phd a PAG 1 r GNC T Sut SWJ lt SWS 3M WT G uce POC PD Ppa PDE GNL 2 eee ee es ee bg ne I ICICICICCTC 3 dd oo gt END Li 1 rr T 7 enh E A BRE LEDU ED um j n gt sa aa T IA T E T a m i EL LEW er ba i t _ c Reva FII ME Bee EDG n LED Alro BN Figure 1 7 Switch 1 1 and 2 and the LED control header Christopher S McCoy Fall 2009 Florida Gulf Coast University Page 7 INTRODUCTION TO MICROCONTROLLER PROGRAMMING AND BI T 121 9 31829910 0 9 COMMUNICATION The mwTWI Temperature sensor used is a pressed circuit board containing an LM75 temperature sensor 3 Serial data and serial clock lines are the most important lines used in communication with the main MCU 3 i Jalal lalalim mlamas myTWI ToTTTTTMTTTS emperatur Sensor ce Www myAVR de m Figure 1 8 1 SDA line 2

Download Pdf Manuals

image

Related Search

Related Contents

ATTUATORE PNEUMATICO A CILINDRO SERIE 1-X-431  Universal Security Instruments USI-1213 Specification Sheet  Neuro InterStim Bladder Brochure  Omega Engineering OMEGAETTE POCKET PP OS-PP User's Manual  PDFファイル - 医薬品医療機器総合機構  4324kB - 宮木電機製作所  Ejecución de instalaciones. Obras civiles de centros de transformación  

Copyright © All rights reserved.
Failed to retrieve file