Friday, 18 May 2012

week 10: Final Program


#include <16f877A.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#include <lcd.c>
#define GREEN_LED PIN_B2
#define YELLOW_LED PIN_B1
#define RED_LED PIN_B0
#define PUSH_BUTTON PIN_A0
#define PUSH_BUTTON2 PIN_A1
#define PUSH_BUTTON3 PIN_A2
#define BUZZER PIN_B4
#INT_RB //Interrupts from Pins B4
void RB_ISR( )
{  disable_interrupts(INT_RB);
    while (!input(PIN_B7)) //Detect Pin B7
      {  lcd_init( );
                {   lcd_putc("\fHELP!!!!");
                     delay_ms(5);
                }
         output_low(BUZZER);
         delay_ms (200);
         output_high(BUZZER);
         delay_ms (200);
         output_low(BUZZER);
         delay_ms (200);
      }
     clear_interrupt(INT_RB);
     enable_interrupts(INT_RB);
}
void wait_for_one_press( )
{  while(!input(PUSH_BUTTON)) ;
   while(input(PUSH_BUTTON)) ; //Wait for one press
}
void light_one_led(int led)
{   output_high(RED_LED);
   output_high(YELLOW_LED);
   output_high(GREEN_LED);

        switch(led)
                 {   case 0 : output_low(RED_LED); break;
                      case 1 : output_low(YELLOW_LED); break;
                      case 2 : output_low(GREEN_LED); break;
                  }
}
   void main()
{ int count = 0;
     set_tris_b(0xFF); // set up port b
      port_b_pullups(TRUE);  //Enable pull up resistors for Port B
      clear_interrupt(INT_RB);
      enable_interrupts(INT_RB); //Enable Port B4-7 interrupts
      enable_interrupts(GLOBAL);  //Enable all interrupts
      EXT_INT_EDGE(H_TO_L); // interrupt on falling edge
      lcd_init( );
      {  lcd_putc("\fmy name is NADIY\npush to JUMP");
         delay_ms(50);
      }
{  wait_for_one_press();
         light_one_led(0);
         delay_ms(1000);
         light_one_led(1);
         delay_ms(1000);
         light_one_led(2);
         delay_ms(1000);
      }    
while(TRUE)
{    
     lcd_init( );
     lcd_putc("\fWelcome to FYP\n");
    printf (lcd_putc,"LAP = %U",count);
    delay_ms(300);
     wait_for_one_press( );
    count++;
    if(count>99)
     count = 0;
}
}

No comments:

Post a Comment