fork download
  1. #include <p18f4520.h>
  2. #include <delays.h>
  3. #define BUZZER PORTAbits.RA3 //Buzzer connected to PORTA 3rd PIN
  4. #define SWITCH0 PORTBbits.RB0 //Switch0 connected to PORTB 0th PIN
  5. #define SWITCH1 PORTBbits.RB1 //Switch1 connected to PORTB 1st PIN
  6. void main(void)
  7. {
  8. TRISA = 0x00; // RA3,OutPut Direction
  9. TRISB = 0xff; // RB0,B1 Input Direction
  10. TRISD = 0x00; // [RD0-3=LED's][RD4,5=Relay1,2] OutPut Direction
  11. PORTD = 0xff;// [RD0-3=LED's][RD4,5=Relay1,2] Initialise as 0xff
  12.  
  13. while (1)
  14. {
  15. if(!SWITCH1) // Condition for 1st switch
  16. {
  17. while (1)
  18. {
  19. BUZZER =1; // Buzzer On
  20. PORTD = 0x37;
  21. Delay10KTCYx(100); // 400mSDelay
  22. PORTD = 0x3B; // (LED's sequence Left to Right=1011=B)
  23. Delay10KTCYx(100);
  24. PORTD = 0x3D;
  25. Delay10KTCYx(100);
  26. PORTD = 0x3E;
  27. Delay10KTCYx(100);
  28. if(!SWITCH0) // check if 2nd switch is pressed
  29. break;
  30. }
  31. }
  32. else if(!SWITCH0) // Condition for 2nd switch
  33. {
  34. while (1)
  35. {
  36. BUZZER =0; // Buzzer Off
  37. PORTD = 0xcE;
  38. Delay10KTCYx(100);
  39. PORTD = 0xcD; // LED's sequence Right to Left=1101=D
  40. Delay10KTCYx(100);
  41. PORTD = 0xcB;
  42. Delay10KTCYx(100);
  43. PORTD = 0xc7;
  44. Delay10KTCYx(100);
  45. if(!SWITCH1) // check if 1st switch is pressed
  46. break;
  47. }
  48. }
  49. }
  50. }
Success #stdin #stdout 0.02s 25896KB
stdin
Standard input is empty
stdout
#include <p18f4520.h>
#include <delays.h>
#define BUZZER PORTAbits.RA3 //Buzzer connected to PORTA 3rd PIN
#define SWITCH0 PORTBbits.RB0 //Switch0 connected to PORTB 0th PIN
#define SWITCH1 PORTBbits.RB1 //Switch1 connected to PORTB 1st PIN
void main(void)
{
 TRISA = 0x00; // RA3,OutPut Direction
 TRISB = 0xff; // RB0,B1 Input Direction
 TRISD = 0x00; // [RD0-3=LED's][RD4,5=Relay1,2] OutPut Direction
 PORTD = 0xff;// [RD0-3=LED's][RD4,5=Relay1,2] Initialise as 0xff

 while (1)
 {
 if(!SWITCH1) // Condition for 1st switch
 {
 while (1)
 {
 BUZZER =1; // Buzzer On
 PORTD = 0x37;
 Delay10KTCYx(100); // 400mSDelay
 PORTD = 0x3B; // (LED's sequence Left to Right=1011=B)
 Delay10KTCYx(100);
 PORTD = 0x3D;
 Delay10KTCYx(100);
 PORTD = 0x3E;
 Delay10KTCYx(100);
 if(!SWITCH0) // check if 2nd switch is pressed
 break;
 }
 }
 else if(!SWITCH0) // Condition for 2nd switch
 {
 while (1)
 {
 BUZZER =0; // Buzzer Off
 PORTD = 0xcE;
 Delay10KTCYx(100);
 PORTD = 0xcD; // LED's sequence Right to Left=1101=D
 Delay10KTCYx(100);
 PORTD = 0xcB;
 Delay10KTCYx(100);
 PORTD = 0xc7;
 Delay10KTCYx(100);
 if(!SWITCH1) // check if 1st switch is pressed
 break;
 }
 }
 }
}