This program are build in PICC compiler
#include <16f877A.h>
#include <lcd.c>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#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
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;
{ wait_for_one_press();
light_one_led(0);
delay_ms(100);
light_one_led(1);
delay_ms(100);
light_one_led(2);
delay_ms(100);
{
while(TRUE)
{ output_c((count/10<<4)+(count%10));
delay_ms(5);
wait_for_one_press();
count++;
if(count>99)
count = 0;
}
}
void wait_for_one_press2( )
{ while(!input(PUSH_BUTTON2)) ;
while(input(PUSH_BUTTON2)) ; //Wait for one press
}
void main2( )
{ int count = 0;
lcd_init( );
while(TRUE)
{ lcd_putc("\fWelcome to my FYP\n");
printf (lcd_putc,"Count = %U",count);
delay_ms(250);
wait_for_one_press2( );
count++;
if(count>99)
count = 0;
}
}
For the push button, can try RB change interrupts. That's the input at Pins B4, B5, B6 and B7. Using interrupt can make program more efficient. Refer to the interrupts.
ReplyDelete