Emmanuel1992
Junior Member level 2
Hello guys I have the problem, I have tried to make the program on mikroc pro for pic to control street lights automaticaly by using LDR and also the system check for the status of all lights and i have tried to build it and no error on it, but the problem is when I simulate on proteus and when a specific condition met that condition get repeated continuously it doesn't stop for only one condition. any one who have an idea can help me to solve that issue coz am suppose to submit it soon as possible below is my full code.
Am using pic18f452 microcontroller
Am using pic18f452 microcontroller
Code C - [expand] 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 // LCD module connections sbit LCD_RS at RC0_bit; sbit LCD_EN at RC1_bit; sbit LCD_D4 at RC2_bit; sbit LCD_D5 at RC3_bit; sbit LCD_D6 at RC4_bit; sbit LCD_D7 at RC5_bit; sbit LCD_RS_Direction at TRISC0_bit; sbit LCD_EN_Direction at TRISC1_bit; sbit LCD_D4_Direction at TRISC2_bit; sbit LCD_D5_Direction at TRISC3_bit; sbit LCD_D6_Direction at TRISC4_bit; sbit LCD_D7_Direction at TRISC5_bit; // End LCD module connections void Init_Mobile(); int count=0; void Init_Mobile() { Delay_ms(1000); UART1_Write_Text("AT\r\n"); Delay_ms(500); UART1_Write_Text("ATE0\r\n"); Delay_ms(500); UART1_Write_Text("AT+CMGF=1\r\n"); Delay_ms(500); } void main() { TRISD=0X00; PORTD=0; TRISB=0XFF; TRISC=0b11000000; Lcd_Init(); UART1_init(9600); Delay_ms(1000); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(2,1,"SYSTEM"); Lcd_Out(3,-3,"INITIALIZING...."); Delay_ms(2500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,2,"UNIVERSITY OF"); Lcd_Out(2,2,"DAR ES SALAAM"); Lcd_Out(4,-1,"*** UDSM ***"); Delay_ms(2500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); Init_Mobile(); while(1) { if(PORTB.F7==0) { PORTD=0b00000000; Delay_ms(100); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"LIGHTS TURNED"); Lcd_Out(2,1,"OFF SUCCESSFULLY"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LIGHTS TURNDED OFF SUCCESSFULLY"); UART1_Write(26); Delay_ms(100); } if(PORTB.F7==1) { PORTD=0b00111111; Delay_ms(500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"LIGHTS TURNED"); Lcd_Out(2,1,"ON SUCCESSFULLY"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LIGHTS TURNDED ON SUCCESSFULLY"); UART1_Write(26); Delay_ms(100); } if((PORTB.F0==1)&&(PORTD.F0=1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 1"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 1"); UART1_Write(26); Delay_ms(100); } if((PORTB.F1==1)&&(PORTD.F1==1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 2"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 2"); UART1_Write(26); } if((PORTB.F2==1)&&(PORTD.F2==1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 3"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 3"); UART1_Write(26); } if((PORTB.F3==1)&&(PORTD.F3==1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 4"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 4"); UART1_Write(26); } if((PORTB.F4==1)&&(PORTD.F4==1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 5"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 5"); UART1_Write(26); } if((PORTB.F5==1)&&(PORTD.F5==1)) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"FAULT DETECTED"); Lcd_Out(2,1,"ON LIGHT 6"); Lcd_Out(4,-3,"SENDIND SMS....."); Delay_ms(1500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"AUTOMATIC STREET"); Lcd_Out(2,1,"LIGHTS AND FAULT"); Lcd_Out(3,-3,"DETECTION SYSTEM"); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+255717677776"); UART1_Write(0x22); UART1_Write(0x0d); Delay_ms(200); UART1_Write_Text("LFAULT DETECTED ON LIGHT 6"); UART1_Write(26); } } }
Last edited by a moderator: