Saturday, June 9, 2012

Knight Rider Circuit using PIC16F84A



Hello Friends , This is my very first blog post.


This is a simulation of the knight rider circuit designed using pic16F84A.I used the following C code which was compiled by the mikroC,C compiler for Microchip PIC microcontrollers to generate the .Hex file . I used JDM programmer to write the .Hex file to the microcontroller.


C code

void movedown()
{
     while(PORTB.F7!=1)
     {
                PORTB=PORTB*2;
                delay_ms(100);
     }
}

void moveup()
{
     while(PORTB.F0!=1)
     {
                PORTB=PORTB/2;
                delay_ms(100);
     }
}


void main()
{
     TRISB=0;
     PORTB=0b11111111;
     delay_ms(1000);
     PORTB=1;
     delay_ms(100);
     
     while(1)
     {
              movedown();
              moveup();
     }

}

Schematic of the circuit used












1 comment:

  1. can u write c code for fading effect for knight rider circuit. i have following code for PIC16f628a request correct my one for chasing effect. thank you jaya19995@gmail.com


    #include
    #define FADE_RATE 12
    #define INITIAL_WIDTH 128
    void fade()
    {
    unsigned char rate = FADE_RATE;
    unsigned char pulse_width = INITIAL_WIDTH;
    unsigned char count;
    while(pulse_width){
    PORTB= 0b11111111;
    for(count=0; count>1);
    }
    for(b=0x40; b; b>>=1){
    PORTB = b;
    fade(b<<1);
    }
    }
    }

    ReplyDelete