-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
135 lines (114 loc) · 3.48 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*********************************************************
This application uses HC-05 Bluetooth Module to do serial
communication between PIC16F877A and an Android Phone.
*********************************************************/
#include<16f877A.h> // Include our device's header file
/* Definining configuration for our application*/
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000) // Definition of oscilaator frequecy
/* RS232 communication settings */
#use rs232(baud=9600, xmit=pin_c6,rcv=pin_c7,parity=N, stop=1)
#use fast_io(b) // Port direction lines
char veri; // We create a global char variable
#int_rda // Interrupt occurs when RX pin has a signal
void interrupt()
{
disable_interrupts(int_rda); // We disabled int_rda interrupt
veri = getch();
/* Conditions for living room light */
if(veri == 'a')
{
delay_ms(200);
output_high(pin_b0);
puts("\n\rLights of the living room is ON");
}
if(veri == 'b')
{
delay_ms(200);
output_low(pin_b0);
puts("\n\rLights of the living room is OFF");
}
/* Conditions for bedroom light */
if(veri == 'c')
{
delay_ms(200);
output_high(pin_b1);
puts("\n\rLights of the bedroom is ON");
}
if(veri == 'd')
{
delay_ms(200);
output_low(pin_b1);
puts("\n\rLights of the bedroom is OFF");
}
/* Conditions for bathroom light */
if(veri =='e')
{
delay_ms(200);
output_high(pin_b2);
puts("\n\rLights of the bathroom is ON");
}
if(veri == 'f')
{
delay_ms(200);
output_low(pin_b2);
puts("\n\rLights of the bathroom is OFF");
}
/* Conditions for kitchen light */
if(veri =='g')
{
delay_ms(200);
output_high(pin_b3);
puts("\n\rLights of the kitchen is ON");
}
if(veri == 'h')
{
delay_ms(200);
output_low(pin_b3);
puts("\n\rLights of the kitchen is OFF");
}
/* Conditions for Air Conditioner in the living room */
if(veri == 'm')
{
delay_ms(200);
output_high(pin_b4);
puts("\n\rAir Conditioner in the living room is ON");
}
if(veri == 'n')
{
delay_ms(200);
output_low(pin_b4);
puts("\n\rAir Conditioner in the living room is OFF");
}
/* Conditions for Air Conditioner in the bedroom */
if(veri == 'z')
{
delay_ms(200);
output_high(pin_b6);
puts("\n\rAir Conditioner in the bedroom is ON");
}
if(veri == 'x')
{
delay_ms(200);
output_low(pin_b6);
puts("\n\rAir Conditioner in the bedroom room is OFF");
}
} //end interrupt
void main()
{
setup_psp(PSP_DISABLED); // Disabled PSP Module
setup_spi(SPI_SS_DISABLED); // Disabled SPI Module
setup_timer_1(T1_DISABLED); // Disabled Timer1
setup_timer_2(T2_DISABLED,0,1); // Disabled Timer2
setup_adc_ports(NO_ANALOGS); // No analog input
setup_adc(ADC_OFF) ; // Disabled ADC Module
setup_CCP1(CCP_OFF) ; // Disabled CCP1 Module
setup_CCP2(CCP_OFF) ; // Disabled CCP2 Module
set_tris_b(0x00); // Define PORTB as output
output_b(0x00); // Clear all PORTB in beginning
enable_interrupts(GLOBAL); // Allow intrrepts which are enabled
while(1)
{
enable_interrupts(int_rda); // Enable int_rda interrupt
}
} // end main