Saturday, January 1, 2011

【 Weak current College 】 PIC Microcontroller development of 】


Summary of the PIC in domestic popularity, this article describes the Microchip PIC MCU development process software and hardware design experience, skills. Keywords Microchip microcontroller power programming
By the United States Microchip company PIC series single-chip, because of its ultra small form factor, low power, low cost, more variety, and other characteristics, are widely used in industrial control, instrumentation, instrumentation, communications, electronics, toys, and other areas, this article summarizes the author in the PIC MCU development process some experience, skills, and for peer reference. 1 how to further reduce power consumption in battery-powered instruments is an important factor. PIC16C×× series single-chip itself lower power consumption (at 5V, 4MHz oscillation frequency is operating current of less than 2mA). To further reduce power consumption, while ensuring meet work requirements, can reduce the frequency of the decline in the working frequency can greatly reduce power consumption (such as PIC16C×× in 3V, 32kHz, its current can be reduced to 15 μ A), but a lower operating frequency may cause some routines (such as mathematical calculations) takes more time. In this case, when the SCM oscillating way uses the RC circuit forms, you can stop working frequency of the solution to. It is in an idle I/O pins (such as RB1) and the crossover between the OSC1 pin a resistor (R 1), as shown in Figure 1. Low-speed status reset RB1 = 0. The need for quick operation when you reset the RB1 = 1, because when battery is charging, the capacitor voltage rise faster, operating frequency increases, the operation time reduction, operational end also reset the RB1 = 0, go slow, low-power state. Work frequency changes according to the R volume 1 of resistance (Note R 1 cannot be chosen too little to prevent oscillation circuit does not, generally select is greater than 5 k Ω).
In addition, further reducing power consumption to take full advantage of the "sleep" command. Implementation of the "sleep" command, the machine is in a sleep state, power consumption for a few µA. Procedures not only in standby state using the "sleep" command to wait for the event, you can also use the program in the delay (see example 1 and example 2). In delay program "sleep" directive to reduce power consumption is concerned, at the same time, even off the broken state, Port b port-level changes to wake-up "sleep", the end of the delay in advance. This is particularly useful for certain applications. Also note that when using the "sleep" when you want to handle and WDT, broken relationship. Figure 1 improving the operating frequency of example 1 (written by Mplab-C) cases 2 (Masm) Delay () Delay {; trip to switch interrupts directive/* this line can be combined with switch interrupts directive */movlw.10for (I = 0; I < = 10; I ++) movwf CounterSLEEP (); Loop1} Sleepdecfsz Countergoto Loop1return2 note INTCON RBIF bits in the interrupt INTCON allowed to interrupt status bits are not affected. B when a PORT configured as input, the input in the RB <7:4> PIN for each read operation cycle is sampling and and old latch value comparison, once different resulting in a high level, and reset the RBIF = 1. Before starting the RB interrupt, perhaps the RBIF has reset the "1", so he should check out RB interrupt to Qing RBIF from RBIF original values, and the interrupt processing is completed it is best to RBIF Qing. 3 using Mplab-C advanced language PIC Microcontroller program when issues 3.1 program compilation instructions embedded in the attention of writing format see example 3.
Cases 3
... ... ... ... while (1) {# asmwhile (1) {… # asm/* should start on one line */# endasm ...} /* Does not properly compile */# endasm ...} /* Compile pass */... When the inline assembly instruction, asm from "#" to "endasm" every instruction must be on a separate line, otherwise an error when compiled. 3.2 addition, multiplication of the most secure method, see example 4.
Cases 4
# include <16c71.h> # include unsigned int a, b; unsigned long c; void main () {a = 200; b = 2; c = a * b;}/* get the correct results 400 */c = because Mplab-C to 8 × 8 multiplication to compile c = a * b and returns the result to a single byte, the result overflows c is ignored. Changed the example of the "c = a * b;" expression is "c = c = a; b; c *", the most secure (on the addition of treatment ibid.). 3.3 learn multiplication and Division method function registers occupancy as the PIC chip RAM only a few dozen bytes, space particularly valuable, but the RAM address Mplab-C compiler has not released, that is, a variable use of address cannot be assigned to other variables. As RAM space does not meet the requirements of far too many variables, some of the variables can be used only by forcing users assigned the same RAM space used interchangeably. But the multiplication and Division in Mplab-C method functions required to use RAM space for storing intermediate results, so if you multiply/divide method function consumes RAM and user variable address overlap, it can lead to unpredictable results. If the c program used for multiplication and Division of operation, it is a good idea to programmatically machine code disassembly code (included in the generated LST file) view the multiplication and Division method uses address other variable address conflicts so that program. Mplab-C Manual did not take given itsDivision function specific RAM address consumption. Example 5 is a multiplications function to 0 × 13, 14, 0 × 0 × 19, 0 × 1A address consumption.
Cases 5
partially disassembled code # include 01A7081FMOVF 1F, 01A80093MOVWF W # include 13; unsigned long lease Value @ 0x101A90820MOVF 20, Wchar Xm @ 0x2d; 01AA0094MOVWF 14; borrowing void main () 01AB082DMOVF 2D, W {Value = 19; 20; 01AC0099MOVWF borrow Xm = 40; 01AD019ACLRF1A; loan Value = Value * Xm01AE235FCALL 035Fh; call the multiply function ... 01AF1283BCF 03, 5} 01B0009FMOVWF 1F; return result low byte 01B10804MOVF 04, 20; return result W01B200A0MOVWF high byte 4 repeat programming on on-chip hardware emulator users, always choose a chip with EPROM to debug programs. Each change a program, is the original content to erase, then programming, process waste considerable time and shortens the life of the chip. If after a programmed results compared with the previous time, only the corresponding machine code is the same as the bit byte from "1" into "0" in the previous programming writing data on the chip, again without having to erase the primitive content.
In the debugging process, frequently encountered constant adjustments, such as the constant change in guarantee corresponds bit from "1" "0", can be primitive content base to continue programming. In addition, because the directive "NOP" corresponding machine code as "00," debugging instructions delete, first with the "NOP" directive alternative, compiled in primitive content continue to programming.
In addition, in a chip with EPROM programming, special attention is confidential status bits. Manufacturers of next-generation with EPROM chips confidential status bits from the original EPROM erasable type changed to fuse type, once the program code confidential fuse programming to "0", repeat programming EPROM chip programming would not be renewed. Use should be made aware of this point, so as to avoid unnecessary waste (Microchip information did not address). Reference 1 Micorchip PIC16Cxx Data Book
2 MPLAB-C USER’S GUIDE

No comments:

Post a Comment