PIC18F45K20T-I/PT Microchip Technology, PIC18F45K20T-I/PT Datasheet

32KB, Flash, 1536bytes-RAM, 36I/O, 8-bit Family,nanowatt XLP 44 TQFP 10x10x1mm T

PIC18F45K20T-I/PT

Manufacturer Part Number
PIC18F45K20T-I/PT
Description
32KB, Flash, 1536bytes-RAM, 36I/O, 8-bit Family,nanowatt XLP 44 TQFP 10x10x1mm T
Manufacturer
Microchip Technology
Series
PIC® XLP™ 18Fr

Specifications of PIC18F45K20T-I/PT

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
Program Memory Size
32KB (16K x 16)
Program Memory Type
FLASH
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
Package / Case
44-TQFP, 44-VQFP
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 PIC18F4XK20
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
Other names
PIC18F45K20T-I/PTTR

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
PIC18F45K20T-I/PT
Manufacturer:
MICROCHIP
Quantity:
6 700
Part Number:
PIC18F45K20T-I/PT
Manufacturer:
Microchip Technology
Quantity:
10 000
Part Number:
PIC18F45K20T-I/PTC07
Manufacturer:
MICREL/麦瑞
Quantity:
20 000
PICkit™ 3 Debug Express
®
PIC18F45K20 – MPLAB
C Lessons
© 2009 Microchip Technology Inc.
DS41370C

Related parts for PIC18F45K20T-I/PT

PIC18F45K20T-I/PT 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

... 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 © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS Table of Contents ® IDE .................................. 11 DS41370C-page iii ...

Page 4

... Exploring the Lesson 11 Source Code with PICkit 3 Debug Express ......66 3.12 Lesson 12: Using the CCP Module PWM .................................................. 68 3.12.1 PWM Overview .......................................................................................68 3.12.2 Using the CCP Module ............................................................................68 3.12.3 Exploring the Lesson 12 Source Code ....................................................71 3.12.4 Build and Run the Lesson 12 Code with PICkit 3 Debug Express ...........72 Appendix A. Schematics DS41370C-page iv © 2009 Microchip Technology Inc. ...

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 Preface NOTICE TO CUSTOMERS ® ...

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

... Add header file path to MCC_INCLUDE environment variable Update MPLAB IDE to use this MPLAB C18 Place Link to documentation for this compiler in MPLAB IDE Help Topics 3. The PICkit 3 Debug Express Lessons files. © 2009 Microchip Technology Inc. PICkit™ 3 DEBUG EXPRESS ® ® ...

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 ® ® IDE IDE ...

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

... 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) © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons ...

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). DS41370C-page 18 © 2009 Microchip Technology Inc. ...

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

... PIC18F45K20 Configuration bits, see Section 23.1 “Configuration Bits” in the data sheet, under the section heading 23.0 “Special Features of the CPU”. In the Lesson 2 source code, all Configuration bits are defined at the top of the 02 Blink LED.c file, as shown in Figure 3-12. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DS41370C-page 21 ...

Page 26

... CP3 = OFF CPD = OFF WRT1 = OFF, WRT2 = OFF, WRT3 WRTC = OFF, WRTD = OFF EBTR1 = OFF, EBTR2 = OFF, EBTR3 FIGURE 3-14: PIC18F45K20 CONFIGURATION // CONFIG1H // CONFIG2L // CONFIG2H = PORTC // CONFIG3H // CONFIG4L // CONFIG5L // CONFIG5H = OFF // CONFIG6L // CONFIG6H = OFF // CONFIG7L // CONFIG7H © 2009 Microchip Technology Inc. ...

Page 27

... There are also libraries for using hardware peripheral functions such as adc, i2c, pwm, spi, usart, and timers as well as for software emulation of peripherals like sw_i2c, sw_uart, and sw_spi. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons This sets the PIC18F45K20 to run using the internal oscillator crystal or external oscillator is needed ...

Page 28

... 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. DS41370C-page 24 th the oscillator clock; in other words, it takes 4 clocks to © 2009 Microchip Technology Inc. ...

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

... Build and Program the Lesson 4 Code Build the Lesson 4 project and program the code into the demo board using the PICkit 3 Programmer. Press the Demo Board Switch button to rotate the LEDs. The LEDs will advance once for each button press. DS41370C-page 32 © 2009 Microchip Technology Inc. ...

Page 37

... Timer0 high byte. This allows the entire 16-bit timer to be read or written at once. Therefore, to read the timer, always read TMR0L first, then TMR0H. To write the timer, always write TMR0H first then TMR0L. Timer0 operation is controlled by the T0CON SFR, shown in Figure 3-24. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons TMR0 TMR0L ...

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

... The ‘0’ value will not actually be written to the timer upper byte until TMR0L is written. Line 4 clears TMR0L, which also causes TMR0H to be written to the high byte of the timer. Thus, the entire 16-bit timer is loaded with the hex value 0x0000. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons LEDDirections; {FALSE, TRUE} BOOL; ...

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

... MPLAB IDE editor window will show the next statement to be executed. Your code will probably have stopped in a different place than that shown in Figure 3-27. FIGURE 3-27: GREEN ARROW POINTS TO NEXT STATEMENT TO EXECUTE DS41370C-page 38 © 2009 Microchip Technology Inc. ...

Page 43

... This is the start-up code, part of the MPLAB C library. This library code initializes the C software stack, assigns appropriate data values to any initialized data variables, and jumps to the start of the application function main(). © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons STEP INTO ...

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

... 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. FIGURE 3-34: DS41370C-page 42 BREAKPOINT HALT BREAKPOINTS DIALOGUE © 2009 Microchip Technology Inc. ...

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

... RA0 should be set to ‘1’ (analog input). However, we still want RB0/AN12 configured as a Digital input to for the switch. Therefore, we will clear ‘0’ the AN12 bit in ANSELH. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons / 1023 ...

Page 50

... One clock period 1/500kHz = 2us, which is greater than the minimum TAD = 1.4us. Thus ADCSx = ‘000’. DS41370C-page 46 and some combination. Since the demo board does not Including the values from #1, the DD ADCON2: A/D CONTROL REGISTER 2 , selecting bits ADCS = F OSC result gives a 500 kHz ADC OSC © 2009 Microchip Technology Inc. ...

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

... The enable bits allow only selected events to cause in interrupt. All interrupts are ORed together, and then ANDed with a global interrupt enable. FIGURE 3-39: © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons TMR0H = ADC_Convert(); TMR0L = 0; ...

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

... Interrupting enabled. // clear roll-over interrupt // Timer0 is low priority // enable the Timer0 interrupt INT0 (switch pressed) interrupts flag interrupt No Interrupts; all interrupts disabled. No Interrupts; all interrupts disabled. High priority interrupts only enabled. Both priority level interrupts enabled © 2009 Microchip Technology Inc. ...

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

... MHz, 2 MHz, 4MHz, 8 MHz, 16 MHz and (with the PLL) 32 MHz and 64 MHz. Recall from previous lessons that the default frequency on a Reset is 1 MHz. FIGURE 3-45: SIMPLIFIED INTERNAL OSCILLATOR BLOCK DIAGRAM DS41370C-page 54 © 2009 Microchip Technology Inc. ...

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

... INTOSC = 8 MHz or INTOSC = 16 MHz. Enabling the PLL with a 4 MHz base frequency gives a 16 MHz clock, and with a 16 MHz base frequency gives 64 MHz. For further information on the internal oscillator block, see Section 2.6 of the PIC18F45K20 Data Sheet (DS41303). DS41370C-page 56 and temperature changes. DD © 2009 Microchip Technology Inc. ...

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

... The microcontroller will continue to execute code during an EEPROM write cycle. 3.10.1 Reading a data byte from EEPROM The EECON1 Special Function Register controls operations to both the internal EEPROM as well as the program memory Flash array. FIGURE 3-49: EECON1: EEPROM CONTROL REGISTER 1 DS41370C-page 58 © 2009 Microchip Technology Inc. ...

Page 63

... Alternatively, the program can be alerted that the write has been completed with an interrupt. The EEPROM module will set the EEIF bit in PIR2 when the write completes. © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons DATA EEPROM READ EEPROM_Read(unsigned ...

Page 64

... Begin Write sequence = 0xAA Set WR bit re-enable interrupts == 1) wait for write to complete Disable writing char databyte) at the address given EEPROM memory Config registers byte to be written address of location to write. begin EEPROM write as a precaution. © 2009 Microchip Technology Inc. ...

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 sequence for writing program memory is very similar to that for erasing. The differences are that a ROM pointer is used to write the 32 locations, and that the EECON1 bit, FREE, is cleared to select a write operation. Don’t forget that the locations to be written must be erased first! © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons = 1; ...

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

... LED light as continuously on. 3.12.2 Using the CCP Module Timer2 is used to set the period, or frequency, of the PWM waveform. Timer2 operation is very similar to Timer0 discussed in Lesson 5, with a few differences. Namely, Timer2 is always an 8-bit timer. DS41370C-page 68 © 2009 Microchip Technology Inc. ...

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 first thing done in the lesson source code is to set PWM pin RD7 to an output. TRISDbits.TRISD7 = 0; Timer2 is then configured to generate the PWM period discussed previously in this lesson. T2CON = PR2 = 249;// © 2009 Microchip Technology Inc. PICkit™ 3 Debug Express Lessons 0b00000111;// Prescale = 1:16, Timer 2 Period ...

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