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

This is 2nd tutorial on I/O programming of PIC Microcontroller. In this tutorial we are going to learn how to make delay program in PIC Microcontroller using integer values. The following program sends values from zero to 100 on Port B with some delay.
  1. In this program you can change delay interval by changing the value 1000 in delay function
    #include  Header File attached to Project
    void delay();                     Initialize delay function
    void main()
    {
    unsigned int i;                  Initialize i as integer variable
    TRISB=0;                              Make Port B as Output
    for(i=0;i<=100;i++)
    {
    PORTA=i;                             Send value of i at Port B
    delay();                                Call delay function
    }
    }

    void delay()
    {
    unsigned int j;                    Make j integer variable
    for(j=0;j<1000;j++);           Delay
    }
  2. If I need different delay intervals I can make a variable delay function as follow:
    void delay(unsigned int value)
    {
    unsigned int j;
    Make j integer variable
    for(j=0;j<value;j++); Delay
    }
    so I can call this function by writing void delay(1000);
  3. One thing you need to know about Microcontrollers is that Microcontrollers only understand Hex data (binary values). Hex data can be write as 0XAA(where 0X means it’s hex data). So if I want to send Hex Data on Port i  can do it as follow:
    void main()
    {
    unsigned int i;
    Initialize i as integer variable
    unsigned char z[] = “0X55,0XAA,0X00”; Hexadecimal data
    TRISB=0; Make Port B as Output
    for(i=0;i<=2;i++)
    {
    PORTA=z[i];
    Send value of i at Port B
    delay(); Call delay function
    }
    }

  4. Keep trying these type of Program. For practice, try to solve the following problem:
    Write a Program which display 0 to 9 counting on 7 segment display.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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