Tutorial 0.0–PIC(18F) Microcontroller Programming in C (I/O Interfacing)

This is PIC Microcontroller 1st tutorial and in this tutorial we are going to learn, how to interface I/O Ports with PIC Microcontroller. PIC(18F4550)  Microcontroller has 5 I/O Ports(A,B,C,D,E) those can work both as Input and  Output. To program PIC Microcontroller in C you need MPLAB IDE which can easily be downloaded from Microchip’s site.
  1. To make any Port I/O you need to remember one keyword which is TRISX (X is Port Name you are using). Now if you write TRISB=1 this will make Port B as Input and writing TRISB=0 make Port B as Output.
  2. Lets see a program in which Microcontroller gets Input from Port B and display Output at Port A. The program begin by writing #include where p18f4550.h is the header file you need to attach with your Project. Click here to see how to attach files in MPLAB IDE.
    #include  Header File attached to Project
    void main()
    {
    TRISB=1;              Make Port B as Input
    TRISA=0;              Make Port A as Output
    while(1)              Super loop
    {
    PORTA=PORTB;          Copy Data at Port B to Port A
    }
    }
     
  3. while(1) {  …….} is called the Super loop and is used when you are using file for hardware.
  4. This program will continuously copy data from Port B to Port A. If you need to See the Program working in your computer you can download PIC Simulator IDE and watch your program working.
  5. Keep trying these type of Programs. Enjoy…

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Engr.Arif Naseem | Bloggerized by Naseem - | Affiliate Network Reviews