Getting Started with PIC Microcontrollers Kelly Flowers – NN8E April 18th, 2011 My Background • • • • • • Licensed in 1979 Education – BSEE 1981 Licensed Professional Engineer (Ohio) Former NOARS member (80’s and 90’s) Worked for Allen-Bradley/Rockwell for 25yrs Worked with computers and microprocessors since 1979 • Began working with PICs in late 90’s What am I going to cover tonight? • • • • PIC background, purpose, value proposition PIC architecture (what’s it look like inside one) How can you use one? PIC system overview(dev s/w, programmer, target or protoboard) • Programming language choices(Assy, Basic, C) • Simple examples / hands on • Recommended resources Just want to whet your appetite tonight! The 411 on PICs • Peripheral Interface Controllers came along in the 90’s from Microchip • Small pin count microcontrollers intended to be ‘smart’ and ‘fast’ I/O front ends for more traditional microprocessors • Not intended to have big number-crunching ability • Hundreds of PIC’s and dsPIC’s Why are they so popular? • Cost! – Per piece cost is low, typically under $5 – Software development environment needed to program the devices is FREE (MPLAB IDE) – Programmers are low cost • • • • • • • Learning curve is fast(low # of instructions) Proliferation of hardware, software, books Backward compatibility Higher level language compilers(Basic, C) ‘Canned’ serial comms (RS232, SPI, I2C) Flash memory based, quickly re-programmable Minimal support parts needed The simplest of PIC’s This even has analog input capability!!! General PIC project overview INPUTS Digital Analog OUTPUTS PIC Digital SERIAL DEVICES (displays, EEPROM, RTC, smart sensors) What do you need to get started? • PC to load development software(MPLAB) on to • Programmer which connects between PC and your PIC • Target or protoboard or your actual project board to test your program! The simplest of PIC projects Even the 12F675 supports ICSP! What is MPLAB IDE? • This is the program you download to your PC to get started with writing your first program • Integrated Development Environment – Free integrated software tool set for developing and troubleshooting programs for embedded applications using PIC’s – Easily integrates with 3rd party software such as high level language compilers – Really high quality, professional grade software • The bad news is Microchip upgrades it a lot and every few generations changes the look and feel! Programming Language Choices • Assembly language is the lowest level – No extra cost to use – Fastest – Manipulating things at the ‘bit level’ – Not easy to do higher level tasks like serial comm and math 35 Assembly instructions (mid-range) Two Higher Level Choices • BASIC – Micro Engineering Labs • C – Multiple vendors (I use CCS) – Free ‘light’ versions – Popular with scientists and engineers • High level languages are used to simplify more complicated tasks like math and serial communications • Microchip made using these with MPLAB a breeze! • Typically execute more slowly than Assembly programs doing the same thing, but this is not usually a problem • The full versions cost $100 to $300 You’re gonna need a Programmer… Putting it all together • Picture your final project(I like to do the hardware design first) • Download MPLAB or install it off supplied disc • Connect programmer with blank PIC installed • Launch MPLAB and set up for proper PIC and the type of programmer you are using • Write your program(or use an example) and ‘build’ till you have no errors! (the hard part) • Try it out! Do this as many times as needed since you can keep erasing and reprogramming in seconds! I recommend the PICkit 2 + ARRL Book Project Thoughts…. • Keyer • Test equipment – Freq counter – Signal gen (DC to Daylight with DDS board!!!) – SWR / power meter • • • • • • Repeater control Automatic control of anything! Hobby servo control Any timing and/or counting applications Holiday lights Home automation Resources • Microchip website – MPLAB, PICkit 2&3, ICD 2&3, datasheets, app notes • • • • • • ARRL “PIC Programming for Beginners” Hellebuyck “Beginner’s Guide to Embedded C Programming” Square 1 website(www.sq-1.com) Wilmshurst “Designing Embedded Systems with PIC Microcontrollers Nuts and Volts magazine www.sparkfun.com – Programmers, proto boards, parts • www.best-microcontroller-projects.com – Tutorials, projects • www.olimex.com – Excellent cheap proto boards(available at sparkfun) • www.kangaus.com PIC-EL II proto board, docs • www.digikey.com, www.mouser.com, www.jameco.com, www.newark.com PICs and parts • GOOGLE!!! EBAY!!!