Beginner Guide To A Pic Programming-neogeo.zip

1. Beginner guide to a PIC Programing The following link is a tutorial series on the 14-bit core PIC family made by Microchip. It covers common PICs like 16F84, 16F628, 16F87x etcIt tells you nearly everything about its architectures like program code bus and data bus and many other aspects like Reset, Oscillators etc. It is much easier to learn while someone is talking to you via diagram and animated drawings. At this moment, the following areas are covered: Architecture, Instruction Set, Development Tools Overview, Device Configuration, Resets and Oscillator I also strongly recommend reading PICmicro Mid-Range MCU Family Reference Manual as it contains important information of all 16F PIC features. Example topics covered includes Device Structure and Varieties, explaining the Oscillator, Memory Organizations and EEPROM, Interrupts, Ports, Timers, A/D, LCD, CCP, Watchdog, the Instruction Set, and so on But most important thing is you should familiar electronics and programing to do pic project 2. Which PIC to choose? For hobbyist, usually we would like those PICs that allow us to program it many many times. So this rules out PIC that has a C in its part number which usually is of the type one-time programmable. The F in its part number generally means Flash technology and this type of PIC are what we often used for experimenting. Many examples and projects we found on the Internet built around 16F84, but please keep in mind that this PIC is old, more expensive, less powerful and now obsoleted, so dont use it for any new design, unless you dont have the source code for your project but stuck with just the HEX object code. If you are new to PICs, youd probably buy the 16F628A or 16F88. There are many tutorials and schematics that use them. It is not difficult to adapt 16F84 source codes for use on newer PICs. For experienced users, it is even possible to disassemble the object code for 16F84 and use it with newer PICs. 16F628A-18Pin, Flash based,Internal Oscillator, PWM module, ICSP, USART 16F88-18Pin, as 16F628A but with added A/D converter If you are looking for bigger PICs to have more I/O pins, try 16F876-28 pin and 16F877-40pin or their newer A version. Also small PIN count PIC: 12F675-8pin or 10F206-6pin! 508a-pinout Later you may want to advance to 18F PIC series, which are called High End, because they are more powerful and have better support for higher level languages (mostly C optimized). Just for information, there is also a DsPIC series from Microchip, which offer 16-bit core and DSP capabilities and with clock frequency up to 160Mhz brings you absolute top power solution These CPUs are really powerful. 3.Refer Datasheets first 4. What is involved in using a PIC A PIC is piece of plastic with pins sticking out. It will do nothing. Internally it has memory which can store binary instructions that it understands. So we need to translate what we wanted it to do into binary instructions stored inside the PIC. The whole process involve two steps. Human instructions can be in the form of computer languages like C or JAL or assembly. (Download mplab to write assembly pic programs) We write the instructions in a text file and a software translate/compile/assembly it into another text file containing HEX codes representing binary instructions that the PIC understands. This is called the object file. Then a piece of hardware(called Hardware device programmer) which sits between the Personal Computer and the PIC whose job is to read the object file and transfer it into the PIC, more often with other functions like reading codes back out from the PIC or verify the codes with the object file. Another piece of software(programming software) is required to control this piece of hardware to perform these functions. Dont confuse this software with that for compiling the human instructions into object form. Free assembly coding tutorials Download When the HEX file is ready, there are two ways to download it into the flash memory of the PIC. One can either use a hardware device programmer mentioned above or a bootloader via serial port of the PC. A bootloader is some codes inside the PIC which read data from its serial RX/TX pin and program the data into the flash memory. This allow very easy operation when one wants to develop codes without the need of a hardware programmer. However, there are some catches.( We commonly use ICPROG to write hex file in to pic. Download ICPROG) a. Not all PICs can support bootloader operation as only those that can program their own flash memory will work b. The bootloader code must be loaded into the PIC first by a hardware programmer c. Bootloader takes up some code memory spaces d. The PIC will have to be running at the time of programming e. 4b. What hardware device programmer to use Programmer circuits: We recommend the parallel programmer P16Pro40 as many had been built and works perfectly. A warning: Serial programmer designs like JDM or RCD relies heavily on the current and voltage capability of the serial port on your PC/laptop. If it works, congratulation. If it doesnt, bad luck. There is nothing you can do to make it work. 5. PIC Programming softwares: There are many choices and are listed below in no particular oder. There is no limit on how many you can use as different software features different PIC types support. Check the software to see if it actually supports the PIC that you use. IC-Prog PicAllW 18F PIC Programming Software WinPic WinPic800 6. Some of my PIC output PINs are not working! This is a common problem. Usually people try to output logic 1(HIGH) to PINs which are only inputs (aka PORTA,5 or PORTE,3 are usually Input only), or you are trying to get 5V from a PIN which can only pull down to 0V GND. Such PIN is called Open drain Output, similar to open-collector in TTL logic. Such PIN is missing a MOSFET transistor from VDD to PIN, therefore PIN cant go HIGH. And of course the MOSFET transistor which is there connecting PIN to VSS cant output high but only 0V. If you want to use it as a general TTL compatible output, just add a Pull-up resistor from that PIN to +5V (4K7 is good). But keep in mind this logic 1(HIGH) wont be strong enough to drive a LED! (If you want to drive LED with it, connect anode of LED to +5V via a current limiting resistor and its Cathode to PIN, this will allow you to turn on the LED by putting logic 0 on the PIN. Beginners usually dont like Open Drain/Collector PINs, but they will find it useful latter, when they advance into self-designing level. Make sure that any internal PERIPHERAL is NOT taking over desired PIN, For example if you activates TIMER1 oscillator or ICD support, you cant use PORTB6,7 for ANY other purpose! This applies to both Input and Output problems. List of peripherals (and features) that may cause problems: MCLR – may prevent PINs PORTA,5 OR PORTE,3 to be used as general purpose input, disable it by clearing Master Clear Enable bit in configuration register. Comparator Module – pins PORTA 0-3 are defaulted to Analog mode with comparators enabled. Writing a correct value to CMCON register (read Datasheet) will disable them. (Affected devices: 16F628, 16F628A, 16F876A, 16F877A, 16F88, 12F629, 12F675, 12F683 and more) LVP – this is a special way of programming PIC with only +5V on MCLR and LVP pin PORTB3 or PORTB4 will control if PIC is on normal or in program mode. because this feature will takeover/block one PIN in the middle of an eight bit port, I highly recommend to DISABLE it by clearing LVP bit in config register. ICD support will allow you to debug the PIC, but if you dont use ICD, under no circumstances enable DUBUG bit in config register, this would reserve PORTB6 & PORTB7 pins and your program wont be able to use them. 7. Some of my input PINs are not working! First check the datasheet if the default state of the PIN is Digital Input, if it says that the Reset state is analog (comparator or ADC), you need to disable analog feature at the beginning of your program. This is a common problem, when you switch from 16F84 to 16F628 without rewriting the program (16F628 has Comparators turned on by default, whereas 16F84 doesnt have them at all). Also if you plan to use PORTA,5 or PORTE,3 as general inputs, you have to disable MCLR function first because they share the same PIN. 8. What are Watchdog, CCP, Timer etc Watchdog timer (WDT) is an Independent oscillator+timer, that will reset (or wake-up) the PIC if you dont clear the timer value periodically. This clearing has to be done regularly in your PIC software by calling CLRWDT instruction. Watchdog prevents your program to be locked in infinite loop, because if it get stuck, the CLRWDT instruction wouldnt get executed and the PIC will reset and get out from the loop. Or you can use Watchdog to periodically wake the PIC up from sleep, and thus saves one precious Timer (that can be used elsewhere). The WDT is a crude RC oscillator, its accuracy is very poor, and highly dependent on external factors such as temperature. However, this doesnt matter for its designed purpose as a watchdog. CCP is a unit that has three functions: a. In Capture mode, CCPR register captures the 16-bit value of the TMR1 register (Timer1) when an event occurs on pin RB3/CCP1. b. In Compare mode, the 16-bit CCPR register value is constantly compared against the TMR1 register pair value. When a match occurs, the RB3/CCP1 pin is altered (see datasheet) c. In Pulse Width Modulation (PWM) mode, the CCP1 pin produces up to a 10-bit resolution PWM output. Since the CCP1 pin is multiplexed with the PORTB data latch, the TRISB bit must be cleared to make the CCP1 pin an output. Timer unit has to modes of operation: d. Counter mode, is counting impulses from a dedicated input pin. This can serve also as a debounced input (Timer overflow will indicate that a button was pressed) e. Timer mode, is counting oscillator pulses (Primary or Secondary), this will allow your program to know how much real time has passed (to construct delays, software serial buses etc) 9. Simulate Pic program before make hardware Using proteus you can simulate your dream circuit. You can test your project before make it.The Proteus Design Suite is wholly unique in offering the ability to co-simulate both high and low-level micro-controller code in the context of a mixed-mode SPICE circuit simulation. With this Virtual System Modelling facility, you can transform your product design cycle, reaping huge rewards in terms of reduced time to market and lower costs of development. continue reading and see pictures ..promeganet.. 相关的主题文章: