Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

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 variableTRISB=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.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews