dsPICElmer 166An introduction to using the dsPICJohn J. McDonough, WB8RCR
Chapter 2.5First Program - Blink an LEDThe first program will be the classic "flash an LED" program. This provides a simple look into progra
Chapter 2. First Program - Blink an LED6 The first time MPLAB-X is launched it will display the MPLAB-X "Start Page". The start page has ma
Creating the project7 The first panel chooses the overall type of project. Almost always the default selections of "MicrochipEmbedded" and
Chapter 2. First Program - Blink an LED8 The next selection is for the hardware programming or debugging tool. In this exercise, the simulator willbe
Creating the project9In the final project wizard panel, enter a name for the project.Figure 2.8. Assign project name
Chapter 2. First Program - Blink an LED10 Two panes will open on the left of the main MPLAB-X window. The upper pane (labeled Projects) willlist the
Editing and Compiling the Source112.2. Editing and Compiling the Source Once a project has been created, the next order of business is to create a fi
Chapter 2. First Program - Blink an LED12A dialog will open allowing you to provide a name for the project. Be certain the filename you choose endsin
Editing and Compiling the Source13Figure 2.12. Add codeFigure 2.13. Compile button
Elmer 166dsPIC Elmer 166An introduction to using the dsPICEdition 1Author John J. McDonough, WB8RCR [email protected] text of and illustrations in th
Chapter 2. First Program - Blink an LED142.3. Running the SimulatorFigure 2.14. Set a breakpointFigure 2.15. Debug program buttonFigure 2.16. Debuggin
Running the Simulator15Figure 2.17. Second toolbar rowFigure 2.18. Open the variables window
Chapter 2. First Program - Blink an LED16Figure 2.19. Create a watch expressionFigure 2.20. Select the variable to watchFigure 2.21. Observe the value
Debugging the program17Figure 2.22. Download program button2.5. Debugging the program 2.6. Documenting the program /* Exercise01_main.c - Blink an LED
Chapter 2. First Program - Blink an LED18// Ex02.c - Blink an LED#include <xc.h> int main (void){ _TRISD3 = 0;
Chapter 3.19Configuration Registers // Configuration fuses_FOSC (XT) // 7.3728 xtal / 4 = 1.8432 MIPS_FWDT (WDT_OFF)
Chapter 4.21Timers // Set up timer // 7.3728 MHz * 16xPLL /Fosc/4 / 256 prescaler / 57600 counter // timer should fire twice per second. Since the
Chapter 5.23Interrupts // Set up timer // 7.3728 MHz * 16xPLL /Fosc/4 / 256 prescaler / 57600 counter // timer should fire twice per second. Since
iiiPreface
24
Chapter 6.25Liquid Crystal Displays
26
Chapter 7.27The I2C Device RoutinesThere are a large number of parts available using the Inter-Integrated Circuit, or I2C, communicationsprotocol. I2C
Chapter 7. The I2C Device Routines28Since the DAC is a relatively simple device, using the routine is quite straightforward. Although theMCP4726 inclu
Using the MCP23008 I/O Expander29The MCP23008 I/O Expander is a more complex device[MCP5]. It has eight I/O pins, each of which maybe configured as an
Chapter 7. The I2C Device Routines307.4. Using the MB85RC16V FRAMThe MB85RC16V Ferroelectric Random Access Memory[FUJ1] is a 2Kx8 non-volatile memory
Chapter 8.31The I2C LibraryIn addition to the device routines, the library includes a complete set of low level I2C routines for deviceswith seven bit
Chapter 8. The I2C Library328.3. Sending data to an I2C deviceThus to send data to a device the sequence is: starting the transaction, sending the con
Chapter 9.33Building Libraries
Elmer 166ivC.3.3. Structure and Union types ... 59C.4. Control Flow
34
Chapter 10.35Analog Inputs // Initialize ADC /* set port configuration here */ ADPCFGbits.PCFG8 = 0; // ensure AN8/RB8 is analog /* set channel s
Chapter 11.37Reading Switches
Chapter 12.39Pulse Width Modulation // Set up timer 2 for PWM TMR2 = 0; // Clear timer 2 PR2 = 1000; // Timer 2 cou
Chapter 13.41Serial Output
Chapter 14.43Serial Input
vPreface
44
Chapter 15.45Unusual Devices
46
47Appendix A. Installing MPLAB-X Figure A.1. Locate the Development ToolsFigure A.2. Select Tools to Download
Appendix A. Installing MPLAB-X48Figure A.3. Open Downloaded InstallerFigure A.4. Allow it to run
49Figure A.5. Install WizardFigure A.6. XC Already Downloaded
50
51Appendix B. Setting up a project inMPLAB-X Figure B.1. MPLAB-X Desktop IconFigure B.2. New Project ButtonFigure B.3. MPLAB-X Project Type
Appendix B. Setting up a project in MPLAB-X52Figure B.4. Selecting the ProcessorFigure B.5. Select Programmer/DebuggerFigure B.6. Selecting the Toolch
53Figure B.8. Create a Source FileFigure B.9. Name the Source File
vi
54
55Appendix C. The C LanguageC.1. IntroductionThis appendix will not turn you into an expert C programmer, nor is it even a decent tutorial. it will,ho
Appendix C. The C Language56that long. Of course, this can have very unfortunate side effects. But C has great faith that you knew whatyou were doing
Array and Pointer types57Type Bits Min Maxunsigned long long 64 0 18446744073709551615 The following are the floating point types: Table C.2. Floati
Appendix C. The C Language58A pointer is specified by prefixing the name with an * in the declaration. Thus, int *n; specifies apointer, n, which poin
Structure and Union types59C.3.3. Structure and Union types struct { int PointID; double Temperature; double ScalingFactor; double Offset
60
61Appendix D. The dsPIC-EL Board
63Appendix E. Microchip PIC Families Figure E.1. PIC Families
Chapter 1.1Overview1.1. Overview of MicrocontrollersA microcontroller is a microprocessor intended for embedded1 applications.Microcontrollers differ
64
65Appendix F. Compiler Support LocationsThe following directories are all relative to the compiler install directory which is typically something like
66
67Appendix G. Revision HistoryRevision 0-3 Sun Jan 20 2013 John McDonough [email protected] correctionsRevision 0-2 Wed Jan 9 2013 John McDonough wb
68
69Bibliography[Barr] Michael Barr. Copyright © 2012 Barr Group. Barr Group . Embedded Systems Glossary. E.[FUJ1] Sales Promotion Department, Fujitsu
70
71IndexAAckI2C, 31ACKstatusI2C, 31ANSI C, 56Array, 55BBackspace characterin character literals, 57Basic, 55Bell characterin character literals, 57Brow
Index72MCP23008writeRegister, 29MCP4726, 27, 32MCP4726write, 28MPLAB-Xicon, 5launching, 5New project, 6New project wizard, 6Start page, 6MPLAB-X proje
Chapter 1. Overview2Figure 1.1. dsPIC OverviewTable 1.1. The dsPIC30F FamilyMinimum Maximum dsPIC30F4011Program Memory 6K 144K 48KData Memory 256 8192
Building Programs31.3. Building ProgramsFigure 1.3. Program Building Process
Comments to this Manuals