PIC18F45K20-I/ML Microchip Technology, PIC18F45K20-I/ML Datasheet

IC PIC MCU FLASH 16KX16 44QFN

PIC18F45K20-I/ML

Manufacturer Part Number
PIC18F45K20-I/ML
Description
IC PIC MCU FLASH 16KX16 44QFN
Manufacturer
Microchip Technology
Series
PIC® XLP™ 18Fr

Specifications of PIC18F45K20-I/ML

Program Memory Type
FLASH
Program Memory Size
32KB (16K x 16)
Package / Case
44-QFN
Core Processor
PIC
Core Size
8-Bit
Speed
64MHz
Connectivity
I²C, SPI, UART/USART
Peripherals
Brown-out Detect/Reset, HLVD, POR, PWM, WDT
Number Of I /o
35
Eeprom Size
256 x 8
Ram Size
1.5K x 8
Voltage - Supply (vcc/vdd)
1.8 V ~ 3.6 V
Data Converters
A/D 14x10b
Oscillator Type
Internal
Operating Temperature
-40°C ~ 85°C
Processor Series
PIC18F
Core
PIC
Data Bus Width
8 bit
Data Ram Size
1.5 KB
Interface Type
CCP/ECCP/EUSART/I2C/MSSP/SPI
Maximum Clock Frequency
64 MHz
Number Of Programmable I/os
36
Number Of Timers
4
Maximum Operating Temperature
+ 85 C
Mounting Style
SMD/SMT
3rd Party Development Tools
52715-96, 52716-328, 52717-734, 52712-325, EWPIC18
Development Tools By Supplier
PG164130, DV164035, DV244005, DV164005, PG164120, DV164136
Minimum Operating Temperature
- 40 C
On-chip Adc
14-ch x 10-bit
Package
44QFN EP
Device Core
PIC
Family Name
PIC18
Maximum Speed
64 MHz
Operating Supply Voltage
2.5|3.3 V
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With
DM240313 - BOARD DEMO 8BIT XLPAC164112 - VOLTAGE LIMITER MPLAB ICD2 VPPDM164124 - KIT STARTER FOR PIC18F4XK20AC164322 - MODULE SOCKET MPLAB PM3 28/44QFN
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
PICkit™ 3 Debug Express
®
PIC18F45K20 – MPLAB
C Lessons
© 2009 Microchip Technology Inc.
DS41370C

Related parts for PIC18F45K20-I/ML

PIC18F45K20-I/ML Summary of contents

Page 1

... PICkit™ 3 Debug Express PIC18F45K20 – MPLAB © 2009 Microchip Technology Inc. ® C Lessons DS41370C ...

Page 2

... PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, TSHARC, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. ...

Page 3

... Switch Input ............................................................................... 31 3.4.3.3 Rotating the LEDs ..................................................................... 32 3.4.4 Build and Program the Lesson 4 Code ..................................................... 32 3.5 Lesson 5: Using Timer0 ............................................................................... 33 3.5.1 The PIC18F45K20 Timer0 Module ........................................................... 33 3.5.2 Exploring the Lesson 5 Source Code ........................................................ 35 3.5.3 Build and Program the Lesson 5 Code ..................................................... 36 3.5.4 Assigning the Timer0 Prescaler ................................................................. 36 © ...

Page 4

... Using Breakpoints ......................................................................................40 3.6.5 Watching Variables and Special Function Registers .................................43 3.7 Lesson 7: Analog-to-Digital Converter (ADC) .............................................. 45 3.7.1 PIC18F45K20 ADC Basics .......................................................................45 3.7.2 ADC Configuration and Operation .............................................................45 3.7.3 Exploring the Lesson 7 Source Code ........................................................48 3.7.4 Build and Run the Lesson 7 Code with PICkit 3 Debug Express ...............48 3 ...

Page 5

... Chapter 3. “PICkit™ 3 Debug Express Lessons”– describes the 12 PICkit 3 Debug Express Lessons in detail. • Appendix A. “Schematics” – illustrates the schematic for the PICkit 3 Debug Express 44-pin Demo Board with PIC18F45K20. © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS ...

Page 6

... Optional arguments mcc18 [options] file [options] Choice of mutually exclusive errorlevel {0|1} arguments selection Replaces repeated text var_name [, var_name...] Represents code supplied by void main (void) user { ... } © 2009 Microchip Technology Inc. Examples ® IDE User’s Guide ...

Page 7

... For the latest information on using other tools, read the tool-specific Readme files in the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files contain update information and known issues that may not be included in this user’s guide. © 2009 Microchip Technology Inc. Preface DS41370C-page 3 ...

Page 8

... Programmers – The latest information on Microchip programmers. These include the MPLAB PM3 and PRO MATE Plus and PICkit™ 1 development programmers. DS41370C-page 4 ® II device programmers and the PICSTART © 2009 Microchip Technology Inc. ® ® ...

Page 9

... Technical support is available through the web site at: http://support.microchip.com DOCUMENT REVISION HISTORY Revision A (January 2009) • Initial Release of this Document. Revision B (January 2009) • Revised document title; changed references from C18 to C compiler throughout document. Revision C (April 2009) • Revised Appendix A: Schematic. © 2009 Microchip Technology Inc. Preface DS41370C-page 5 ...

Page 10

... PICkit™ 3 Debug Express NOTES: DS41370C-page 6 © 2009 Microchip Technology Inc. ...

Page 11

... Lesson 10: Using Internal EEPROM - Lesson 11: Program Memory Operations - Lesson 12: Using the CPP Module PWM Appendix A. “Schematics”: Schematic for PICkit 3 Debug Express 44-pin Demo Board with PIC18F45K20. 1.1 BEFORE BEGINNING THE LESSONS Please ensure the following files and software has been installed on your PC before beginning: 1 ...

Page 12

... PICkit™ 3 Debug Express FIGURE 1-1: MPLAB C COMPILER INSTALLATION CONFIGURATION OPTIONS DS41370C-page 8 © 2009 Microchip Technology Inc. ...

Page 13

... Code will execute properly but it cannot be read out or copied. Program memory can be read using table read instructions, and can be written through a special code sequence using the table write instruction. © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS Overview DS41370C-page 9 ...

Page 14

... The return stack is a separate area of memory, allowing 31 levels of subroutines. The CALL/RETURN stack is distinct from the software stack maintained by MPLAB C Compiler. The software stack is used for automatic parameters and local variables and resides in file register memory as defined in the Linker Script. DS41370C-page 10 © 2009 Microchip Technology Inc. ...

Page 15

... Project Wizard…. The Project Wizard “Welcome!” dialog is shown. Click Next to continue. 3.1.1.1 STEP ONE: SELECT A DEVICE In the Project Wizard dialog, select PIC18F45K20 as the target device in the dropdown box, as shown in Figure 3-1, and click Next to continue. © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS ® ...

Page 16

... This PIC18F microcontroller project will select the “Microchip C18 Toolsuite” from the “Active Toolsuite:” dropdown box, as shown in Figure 3-2. Click Next to continue. FIGURE 3-2: DS41370C-page 12 WIZARD STEP ONE: SELECT PIC18F45K20 DEVICE WIZARD STEP TWO: SELECT TOOLSUITE © 2009 Microchip Technology Inc. ...

Page 17

... Hello LED.c file in the project directory from Step Three and click Add. The file will now show up on the right pane of the Dialog window, as shown in Figure 3-4. Click Next to continue. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons WIZARD STEP THREE: CREATE A NEW PROJECT ...

Page 18

... Linker Scripts, and other files. As shown in Figure 3-5, the Lesson 1 LED project currently contains only one source file, 01 Hello DS41370C-page 14 LED.c, which was added in the Project Wizard. © 2009 Microchip Technology Inc. ...

Page 19

... File > Save As… to save a new copy in the current project directory and then add the new file to the project final step use File > Save Workspace to save the project and its working environment. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons THE PROJECT WINDOW Basic Linker Script file for compiling a memory image in non-extended processor mode ...

Page 20

... Select Project > Save Project to save the new project configuration. Exploring the Lesson 1 Source Code 3.1.2 Double-click the 01 Hello LED.c source file name to open the lesson source code file in an MPLAB IDE editor window. DS41370C-page 16 ADD FILES TO PROJECT NEW PROJECT FILES © 2009 Microchip Technology Inc. ...

Page 21

... Set while ( When this code is built, programmed into the PIC18F45K20 microcontroller and executed, it will turn on the LED connected to I/O pin RD7 by driving the pin high. Let’s discuss the elements of the code that makes this happen: #pragma config #include TRISD LATDbits.LATD7 while(1) © ...

Page 22

... Navigate to the Power tab and use the slider bar to set the output voltage to 3.25V, check the box labeled “Power target circuit from PICkit 3” and press the OK button. Once power to the target is enabled, the device ID of the PIC18F45K20 will be displayed (last line in Figure 3-10A). ...

Page 23

... Program. The results of the programming operation will appear in the Output window as shown in Figure 3-11. Congratulations! You have created, built, programmed, and executed your first Microchip PIC18F project! © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons OUTPUT WINDOW PICkit 3 PROGRAMMER PICkit 3 PROGRAMMER POWER SUPPLY ® ...

Page 24

... If an error occurs during programming, consult the PICkit 3 help file in the Note: MPLAB IDE. Select Help > Topics… then under the “Programmers” head- ing select “PICki t 3 Programmer” and click OK. On the Contents tab, select the “Troubleshooting” section for information. DS41370C-page 20 © 2009 Microchip Technology Inc. ...

Page 25

... For example, in the PIC18F45K20 the Configuration bits select such features as which oscillator option to use, whether the processor runs in Traditional or Extended mode; whether to use the Brown-out Reset circuit and which voltage to trip at ...

Page 26

... Config Settings” topic as shown in Figure . Click OK. 3. When the Help window opens, select the Contents tab, and expand the “Configuration Settings” section. 4. Select the PIC18F45K20 microcontroller to display all the Configuration bit set- ting attributes that can be used with the #pragma config directive, as shown in Figure . ...

Page 27

... Microchip Technology Inc. PICkit™ 3 Debug Express Lessons This sets the PIC18F45K20 to run using the internal oscillator crystal or external oscillator is needed. The default frequency is 1 MHz. The oscillator is covered in more detail in Lesson 9. It also sets OSC1 and OSC2 pins to be used as the RA6 and RA7 I/O port pins as the OSC pin functions are not needed ...

Page 28

... Build and Program the Lesson 2 Code Select MPLAB IDE menu, build the Lesson 2 project and program the code into the demo board PIC18F45K20 using the PICkit 3 Programmer as we did in Lesson 1. The demo board LED 7 will blink continuously at 200 ms on and 200 ms off. ...

Page 29

... Other variables declared in a udata or idata section will be placed at subsequent addresses. For instance, the 16-bit integer address 0x301 and 0x302 Note that function local variables will be placed on the software stack. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons LESSON 3 GLOBAL VARIABLE DECLARATION I ...

Page 30

... Program memory Instructions. Compiles all subsequent instructions into the program memory space of the target PIC18FXXXX. Data stored in program memory. Used in conjunction with the rom keyword, the following constant data is compiled into the program memory space. Lesson3_Table = 0x180 © 2009 Microchip Technology Inc. ...

Page 31

... Exploring the Lesson 3 Source Code Open the lesson source code file 03 Rotate LED editor window not open already. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons PROGRAM MEMORY “LED_LOOKUPTABLE” ARRAY VALUES DS41370C-page 27 ...

Page 32

... The LED number is incremented to the next LED. The if state- ment checks to see if it has been incremented past the last LED reset to the first LED, number Lesson 2, a “delays” library function is used to create a time delay. @ 1MHz © 2009 Microchip Technology Inc. ...

Page 33

... Remember, for the compiler to know about the #define definitions, the header file must be included in the C file done in 04 Switch Input.c: #include © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons HEADER FILE Switch_Pin PORTBbits ...

Page 34

... Note that the switch on the 44-Pin Demo Board doesn’t bounce much, but it is good practice to debounce all system switches. FIGURE 3-21: 3.4.3 Exploring the Lesson 4 Source Code Open the lesson source code file 04 Switch Input editor window not open already. DS41370C-page 30 SWITCH DEBOUNCING PROGRAM FLOW © 2009 Microchip Technology Inc. ...

Page 35

... Therefore, reading PORTBbits.RB0 will give the value of the signal on the RB0 pin. Don’t forget – in the header file, this was defined as Switch_Pin, which is what the code uses to read the pin value: #define Switch_Pin © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons S *******************************************/ instructions = 0 ...

Page 36

... The bit will eventually be shifted out of the Most Significant bit of LED_Display, so the code checks for this, and sets LED_Display to ‘1’ again. For more information on I/O port pins, see Section 10 “I/O Ports” of the PIC18F45K20 Data Sheet (DS41303). 3.4.4 ...

Page 37

... The PIC18F45K20 Timer0 Module The Timer0 module is the timer/counter peripheral of the PIC18FXXXX microcontroller that may be used to count oscillator clock cycles or external events on the T0CKI pin. It can be configured as an 8-bit or 16-bit timer, which means it can count from 0 to 255 65535 ...

Page 38

... The timer will overflow in 65536 counts. At the instruction clock rate of 250 kHz, the timer overflow will occur every 65536 250,000) = 262ms. This is a time in the range we want, so the prescaler is not assigned to Timer0. It runs directly off the instruction clock. DS41370C-page 34 © 2009 Microchip Technology Inc. ...

Page 39

... To configure Timer0 with these settings, the binary value 0b0000100 is written to T0CON. The PIC18F45K20 has 3 other configurable timers: Timer1, Timer2 and Timer3. More information on all four timer modules can be found in the PIC18F45K20 Data Sheet (DS41303), Sections 11 through 14. 3.5.2 Exploring the Lesson 5 Source Code Open the lesson source code file 05 Timer ...

Page 40

... Rebuild and reprogram the Lesson 5 project with change in the source code. The LEDs will rotate more slowly, 4 times slower to be exact, than before. DS41370C-page 0b00001000; 0b00000001 © 2009 Microchip Technology Inc. ...

Page 41

... These locations are not available for use by user code. In the MPLAB IDE, registers marked with an “R” in register displays represent reserved registers, as shown in Figure 3-26. FIGURE 3-26: RESERVED ICD FILE REGISTER LOCATIONS IN THE PIC18F45K20 © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 37 ...

Page 42

... Basic Debug Operations 3.6.3.1 HALT The PIC18F45K20 on the demo board is now running the lesson program code. Code execution can be halted (stopped) at any time by selecting Debugger > Halt <F5>. A green arrow on the left margin of the MPLAB IDE editor window will show the next statement to be executed ...

Page 43

... This is only available when the target is halted. Halt the demo board PIC18F45K20 currently running, and select Debugger > Reset > Processor Reset <F6> This will open up a new file in the MPLAB IDE called c018i ...

Page 44

... In the MPLAB IDE 05 Timer.c source code, place the editor cursor on line 111, SwitchPressed = TRUE;, and right-click to open the contextual menu. Select Set Breakpoint as shown in Figure 3-31. A red octagon with the letter ‘B’ will appear in the editor margin to indicate a breakpoint has been set on that line. DS41370C-page 40 © 2009 Microchip Technology Inc. ...

Page 45

... LEDs will rotate as the code runs since the breakpoint statement has not been executed yet. Press the Demo Board Switch button. The program will halt on the breakpoint statement, as shown in Figure 3-33. <F8> can now be used to step through the code. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons BREAKPOINT SET DS41370C-page 41 ...

Page 46

... Resource Toolbar provides information on the total number of breakpoints available for the selected device (“HW BP”) and the number of used breakpoints (“Used”). The PIC18F45K20 can have breakpoints set at once, and has 2 currently available since one is already set on line 111 of 05 Timer.c. ...

Page 47

... LATD, which our program uses to set the LEDs. User variables are added using the dropdown on the upper right, and clicking the Add Symbol button. Add the LED_Display , SwitchPressed , and Direction variables now. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons WATCH WINDOW DS41370C-page 43 ...

Page 48

... Add TMR0L and TMR0H SFRs to the Watch window, and observe them counting while you step through the code. Note that they don’t increment once per step, as each C statement may be compiled into more than one assembly instruction and Timer0 is incremented once per assembly (machine) instruction. DS41370C-page 44 WATCH VARIABLES © 2009 Microchip Technology Inc. ...

Page 49

... Demo Board V for this device. The ADC can convert the voltage from any one of 13 channels on the PIC18F45K20. These analog input channels, numbered AN0 up to AN12, are shared with digital microcontroller pins and must be configured as analog inputs to be used with the ADC. ...

Page 50

... The ADC clock should be set as short as possible but still greater than the minimum period “TAD” time, data sheet parameter 130. The minimum TAD time for the PIC18F45K20 (as of this writing) is 1.4us MHz oscillator F clock. One clock period 1/500kHz = 2us, which is greater than the minimum TAD = 1.4us. Thus ADCSx = ‘ ...

Page 51

... ADCON0. Bit ADON is set to ‘1’ to turn on the ADC peripheral. The GO/DONE bit is left clear as we don’t wish to start a conversion yet. ADCON0 = 0b00000001 FIGURE 3-38: © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons ADCON0: A/D CONTROL REGISTER 0 DS41370C-page 47 ...

Page 52

... Watch window. Use Breakpoints and Step commands to explore the code. Observe how the ADC result in ADRESH is affected by the potentiometer voltage, and how this result is copied into TMR0. DS41370C-page 48 = ADC_Convert(); // MSB from ADC = 0; // LSB = 0 / 1/(1MHz/ 1/250kHz OSC © 2009 Microchip Technology Inc. ...

Page 53

... See Section 19.0 “10-Bit Analog-to-Digital Converter (A/D) Module” in the PIC18F45K20 Data Sheet (DS41303) for more information on the ADC peripheral. If TMR0L is added to the Watch window, it will cause incorrect operation Note: when stepping through the following 2 lines of code: This is caused by the buffered nature of TMR0H. When “Stepping Over” the TMR0H assignment statement, the MPLAB IDE will read the TMR0L register to update the value in the Watch window ...

Page 54

... When using interrupts, the interrupt vectors must be defined and placed at the appropriate vector addresses using the #pragma code directives. An inline assembly GOTO statement redirects program execution to the interrupt functions, whose name serves as the GOTO argument. DS41370C-page 50 © 2009 Microchip Technology Inc. ...

Page 55

... Timer0 and external pin interrupts are set up using the INTCONx Special Function Registers. Other interrupts are setup through a number set of peripheral interrupt SFRs: PIRx, PIEx and IPRx. The PIRx registers contain the interrupt flags. The © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons ***********************************************/ ...

Page 56

... PIEx registers, and the IPRx register bits set the interrupt priority as low or high. For detailed information the bits in these registers, see Section 9.0 “Interrupts” of the PIC18F45K20 Data Sheet (DS41303). FIGURE 3-43: LESSON 8 INTERRUPT INITIALIZATIONS ...

Page 57

... Turning the demo board potentiometer will affect the rotation speed of the LEDs. The switch may be pressed to reverse the rotation. Use breakpoints to explore the interrupting functions. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons INTCONbits.PEIE Interrupt Functions No Interrupts; all interrupts disabled. ...

Page 58

... PICkit™ 3 Debug Express 3.9 LESSON 9: INTERNAL OSCILLATOR Using the on-chip internal oscillator and PLL (Phase Locked Loop) of the PIC18F45K20 is discussed. Clocks from 31 kHz MHz can be generated without requiring external oscillator components. Key Concepts - To use the internal oscillator block, set the OSC Configuration bits to INTIO67 or INTIO7 ...

Page 59

... INTOSC 8 MHz oscillator, on which all other frequencies are based, or the INTRC low-power 31 kHz oscillator as discussed in Section 3.9.1. This selection is made with the INTSRC bit in the OSCTUNE register. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 55 ...

Page 60

... This can save on power consumption when fast clock speeds aren’t required. The OSTS and IOFS bits are read-only Status bits. The PIC18F45K20 has the option to start-up running off the internal oscillator until an external oscillator circuit has stabilized ...

Page 61

... Build and program the Lesson 9 project, then Run the application in the debugger. Pressing the demo board switch causes the program to change the oscillator frequency during execution. As the oscillator frequency increases, the rate at which the LEDs count increases. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons here.Interrupt handles ...

Page 62

... PICkit™ 3 Debug Express 3.10 LESSON 10: USING INTERNAL EEPROM The PIC18F45K20 microcontroller includes 256 bytes of on-chip EEPROM for data storage. This lesson discusses reading and writing the internal EEPROM in software. Key Concepts - The 4 SFRs that control EEPROM operations are EECON1, EECON2, EEDATA and EEADR ...

Page 63

... EEPROM writes take some time to erase and program the byte in the array. This time is listed as parameter D122 in the data sheet Section 26.0 “Electrical Characteristics”, and is usually several ms. During this time, the PIC18F45K20 microcontroller continues to execute program code. The program may determine when a write has completed by polling interrupt generated by the EEPROM module ...

Page 64

... PICkit™ 3 Debug Express For more information on the data EEPROM memory see Section 7.0 of the PIC18F45K20 Data Sheet (DS41303). FIGURE 3-51: void EEPROM_Write(unsigned { // writes // location EECON1bits.EEPGD EECON1bits.CFGS EEDATA EEADR = EECON1bits.WREN INTCONbits.GIE EECON2 EECON2 EECON1bits.WR INTCONbits.GIE while (EECON1bits. EECON1bits.WREN } 3.10.3 Exploring the Lesson 10 Source Code The Lesson 10 program writes all 256 bytes of the data EEPROM memory, writing each location with value = 255 – ...

Page 65

... For more information on project memory models, see Chapter 3 of the “MPLAB C18 C Compiler User’s Guide” (DS51288). © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 61 ...

Page 66

... Now, rom_pointer points to the program memory byte at address 0x320. Reading Flash program memory then simply requires declaring a ROM pointer and using an assignment statement to read the pointer value. DS41370C-page 62 PROJECT CODE MODEL SETTINGS = hello_str &hello_str[0] = *rom_pointer = (near rom char *)0x320; © 2009 Microchip Technology Inc. ...

Page 67

... The PIC18F45K20 erase block size is 64 bytes. This means it will always erase 64 sequential bytes at once, and the block must start at an address that is a multiple of 64. For example, we could erase the 64 bytes from address 128 through 191 at once, but not the 64 bytes from address 100 through 163 ...

Page 68

... If the rom_pointer value were left at 0x11F, the data would be written as intended started at 0x100. DS41370C-page ram_array[i];// write to the holding registers = (near rom unsigned char *)0x100; = ram_array[i]; // write to the holding registers © 2009 Microchip Technology Inc. ...

Page 69

... Bulk Erase on the microcontroller, which erases all program memory and data EEPROM memory possible to prevent other Configuration bits from being changed after the device is initially programmed using the WRTC Configuration bit. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons int address, ...

Page 70

... Figure 3-55 and observe the characters of the hello_str[] string are read into the singlechar variable one at a time until the terminating ‘0’ value of the string is reached. The next statement demonstrates reading from an explicit program memory address using a function: singlechar DS41370C-page 66 = ProgMemRdAddress(0x107); // returns 'M' from "Microchip". © 2009 Microchip Technology Inc. ...

Page 71

... Run the program. After running for a few seconds, select Debugger > Halt. The program should be stopped at final while(1) loop. Select Debugger > Read again and we can see that the write to program memory was successful. FIGURE 3-57: PROGRAM MEMORY WRITE RESULTS © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 67 ...

Page 72

... PICkit™ 3 Debug Express 3.12 LESSON 12: USING THE CCP MODULE PWM This lesson gives a brief introduction to using the Pulse Width Modulation (PWM) functionality of the Capture/Compare/PWM (CCP) peripheral of the PIC18F45K20. Key Concepts - The PWM time base (frequency) is determined by Timer2 and the PR2 Special Function Register. ...

Page 73

... Since Timer2 starts set PR2 = 249 counts 0-249 (250 counts), resets to zero, and counts back to 249. A simplified diagram of the PWM module is shown in Figure 3-60. FIGURE 3-59: T2CON: TIMER2 CONTROL REGISTER © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 69 ...

Page 74

... The 8 Most Significant bits, 0b01 1111 01 or 0x7D, are written to CCPR1L, and the 2 LSbs are written to the DC1B1 and DC1B0 bits in CCP1CON. DS41370C-page 70 © 2009 Microchip Technology Inc. ...

Page 75

... The PWM signal from the CCP1 module is normally output on the CCP1/RC2 pin. However, this pin is not connected to any demo board LEDs. To output a signal on an LED pin, the Enhanced CCP module (ECCP) on the PIC18F45K20 is utilized. This functionality is selected in the upper 2 bits of CCP1CON (P1Mx), which are set to 0b01 so the modulated PWM signal appears on the P1D/RD7 which drives LED 7. No other aspect of the enhanced PWM functionality is used ...

Page 76

... Build and program the Lesson 12 project, then Run the application in the debugger. You will see the demo board LED 7 continuously get brighter then dimmer! If you have an oscilloscope available, connect a probe to one of the RD7 signal points on the demo board to see the changing the PWM waveform. DS41370C-page 72 © 2009 Microchip Technology Inc. ...

Page 77

... Appendix A. Schematics FIGURE A-1: RA7 © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS SCHEMATIC FOR PICKIT 3 DEBUG EXPRESS 44-PIN DEMO BOARD WITH PIC18F45K20 RC0 RC1 RA6 DS41370C-page 73 ...

Page 78

... Fax: 886-3-6578-370 Taiwan - Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan - Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand - Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 © 2009 Microchip Technology Inc. EUROPE Austria - Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark - Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France - Paris Tel: 33-1-69-53-63-20 ...

Related keywords