#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;
}
}
}
}
I2luY2x1ZGUgPHAxOGY0NTIwLmg+CiNpbmNsdWRlIDxkZWxheXMuaD4KI2RlZmluZSBCVVpaRVIgUE9SVEFiaXRzLlJBMyAvL0J1enplciBjb25uZWN0ZWQgdG8gUE9SVEEgM3JkIFBJTgojZGVmaW5lIFNXSVRDSDAgUE9SVEJiaXRzLlJCMCAvL1N3aXRjaDAgY29ubmVjdGVkIHRvIFBPUlRCIDB0aCBQSU4KI2RlZmluZSBTV0lUQ0gxIFBPUlRCYml0cy5SQjEgLy9Td2l0Y2gxIGNvbm5lY3RlZCB0byBQT1JUQiAxc3QgUElOCnZvaWQgbWFpbih2b2lkK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KDEwMCk7CiBQT1JURCA9IDB4Yzc7CiBEZWxheTEwS1RDWXgoMTAwKTsKIGlmKCFTV0lUQ0gxKSAvLyBjaGVjayBpZiAxc3Qgc3dpdGNoIGlzIHByZXNzZWQKIGJyZWFrOwogfQogfQogfQp9IA==
#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;
}
}
}
}