Thursday, March 18, 2010

PIC microcontroller



I learned to program 8051 microcontrollers in assembly as well as SDCC. Now I wanted to shift to PIC and AVRs but the problem was I did not have those chips. And getting those chips were almost impossible then. But now you can find some PIC and AVR microcontrollers.


Some inverter company of Nepal imported PIC 16F72 microcontrollersfor the use in their inverters. So, I managed some 3/4 16F72 and started working on those.


I will now post my experiences based on programming PIC microcontrollers in Hi-Tech C. PIC 16F72 are great microcontrollers and just 28 pins device. It has ICSP and can be programmed in the final target circuit.




This microcontroller has 3 input/output ports, two 8-bit timers and a 16-bit timer with Compare, capture and PWM modes, 8-bit 5channel ADC, Synchronous serial port with SPI(master/slave) and I2C(slave only). It can work at a maximum frequency of 20 Mhz. Can be clocked using crystal oscillator, resonator, RC oscillator or external clock pulse. It has 2KB x 14 words of program memory and 128 bytes of RAM.
These all features integrated into a single chip makes a good microcontroller and sufficiently small to to fit your control system in a pretty small circuit.



Making the programmer for this device was really challenge. 16F72 have built in ICSP in them, so these devices can be programmed in the target circuit with ICSP programmers. But I wanted to build a programmer that would be able to program almost all the PIC microcontrollers. 


I found a  programmer by Feng3. This is a cool programmer. It is able to program almost all the PIC micrcontrollers. It is able to program 8-pin to 40-pin devices. See the site to find out the supported devices and the circuits. You can download the Zipped verson that contains the schematics, PCB designs and some documentaton from here.


I was really excited to get this programmer work. It has quite a jizzy PCB design and of course making PCB with hot iron was really harsh. Here is the glimpse of the programmer that I made.
                                                                                                                                                             
This programmer requires a very simple programming software called IC-PROG. It is very small in size and loads very quickly.  You can download it from the here.


PIC microcontroller can be clocked using RC oscillator which is very good and makes economic use in small embedded applications.


I made a small custom board out of 16F72 which uses RC oscillator.  In the figure above the RC oscillator setting gives the instruction cycle of approximately 1 Mhz. Unlike the reset in 8051 is active high, it is just opposite in case of PICs. Providing 0v signal  to MCLR pin resets the device. So a button is provided to reset the microcontroller.  The microcontroller has 3 ports. Port A which has only 6-pins, Port B and Port C each of 8-bits. So all together we have 22 input/output programmable pins available.

      Programming PIC microcontroller in C requires MPLAB ide  and Hi-tech C compiler which can be downloaded from Microchip's homepage.  MPLAB IDE have Hi-tech C integrated in the same set up package. The set up will ask if you want to install Hi-tech C.


Now we will write a simple program to blink a led across PORTB. Open the MPLAB ide. To create the project go to project.

Now Go to Project wizard.


Click Next to proceed to next step.


Select the device as you wish to use. I selected PIC 16f72. Now click Next.


We will program in Hi-tech C. So, I am selecting Hi-tech universal toolsuite from the drop down menu.Proceed to the next step.




Now create a new project menu appears.







Now I am creating a project called blink inside the directory blink.


We are not adding any source file into the current project.So click next.

Now we have created a project file called blink.mcp and cofigured Hi-tech C as a compiler. Now we will make a C file to blink the led across PORTB.




























Now to write C file.Go to project menu and select add new files to project.



























I have created a C file "blink.c" in the project directory.Now click save to finish creating a C file.
We shall write the C program to blink PORTB.







        

Thursday, February 25, 2010

BLOGGING

I have been very much excited to create my own blog.I have some experiences in electronics and I wish to publish some articles based on my experinces in electronics.
We do not get AVR or PIC microcontrollers in Nepal.But through the simulation software called proteus and thorough net surfing I have been able to create some stuffs with these things as well.I will post articles in using these stuffs and how you can get these items in Nepal.
I will discuss the programmer for PIC16f72 and programming these devices in C.

Followers