LED Toggle using Button Key


Demo code for LED Toggle using Button Key in Bootloader USB PIC18F4550.

Compiler : Microchip C18 C Compiler

Kit : Bootloader USB PIC18F4550

Project : LED Toggle using Button Key


Hardware connection : COL 0 -> +5V , RD0 -> ROW 0



#pragma code InterruptVectorHigh = 0x2008
#pragma code InterruptVectorLow = 0x2018
#pragma code main = 0x2020

#include < p18F4550.h>
#include < delays.h>

#define key   PORTDbits.RD1   		/* PORT for key */
#define TRIS_key  TRISDbits.TRISD1    	/* TRIS for key */ 

void delay (void)
{
Delay10KTCYx(100);
}
void toggle(void)
{
    if(LATB == 0xff) 
      LATB = 0;
    else
      LATB = 0xFF;
	while(key) delay();
}
void main (void)
{
  /* Make all bits on the Port B (LEDs) output bits.
   /* If bit is cleared, then the bit is an output bit.
   */
  TRISB = 0;
  TRIS_key =1;

  while (1)
    {
	  if(key == 1) toggle();

    }
}



User Comments

No Posts found !

Login to Post a Comment.