RUNNING LED

 LED RUNNING USING PIC16F877A
       In this case LEDs connected to PORTD will glow one after the other in a chasing manner and the cycle repeats. This is also a test program  for beginners.


C PROGRAM (use High TECH C compiler)
#include <htc.h>
__CONFIG(0x3F3A);   //configuration bits

////////////////////////////////////////////////////////////////////////////////////////////////
void delay()                          //delay function
    {
    for(int i=0;i<100;i++)
        {
            for(int j=0;j<1000;j++);
        }
    }
///////////////////////////////////////////////////////////////////////////////////////////////
main()
{
int a=1;
TRISD=0;                     //set all PORTD bits as output
while(1)                    //infinite loop
    {
    PORTD=a;             
    delay();                //call delay function
    a<<=1;                   //new a = old a left shift by one
    if(a>0b10000000)           //if a exceeds limit of 8 LEDs,
        {                      //then a is made 1
            a=1;
        }
   
    }
}
////////////////////////////////////////////////////////////////////////////////////////////



HEX FILE (save as runnig.hex)

:060000000A128A11BB2F59
:100F760083010A128A11BF2FF401F40AF5018316C0
:100F8600880174088312031388000A128A11DF2766
:100F96000A128A110310F40DF50D7508803AFE0049
:100FA60080307E02031DD92F81307402031CC42FAA
:100FB600F401F40AF501C42FF001F101F201F30185
:100FC600F20A0319F30A7308803AFE0083307E02A0
:100FD600031DEF2FE8307202031CE32FF00A0319FA
:100FE600F10A7108803AFE0080307E02031DFD2F53
:0A0FF6006430700203180800E12FB8
:02400E003A3F37
:00000001FF
 
CIRCUIT DIAGRAM
(same as blinking led circuit diagram)


No comments :

Post a Comment