Emmanuel1992
Junior Member level 2
ADC and Comparators are not disabled.
Hi, how to do that sir?
- - - Updated - - -
hi
it is using your code only you just need to check carefully follow these steps
1) in void check_port_status() function mentioned all your port checking activities i.e. PORTB.F7 ==0 , PORTB.F7 == 1 etc. set different status 0,1 ,2 .. for them.
2) in while loop put relavent action codes which you have already written in if.. condition
3) set- reset the flags
structure is already ready.
- - - Updated - - -
hi
same you can impleament with all your conditions including (&&) conditions...
- - - Updated - - -
hi
pls refer this hope it will help
Code:
#define Light_Turn_on 1
#define Light_Turn_off 2
#define Light_fault_detected 3
//.... other status comes here
// take some flags keep initial values 0
char status_updated_for_status_1 = 0;
char status_updated_for_status_2 = 0;
char status_updated_for_status_3 = 0;
//.... other flags comes here (use bitfields for memory saving ... )
// make one function that checkes only stauts of ports
void check_port_status()
{
if(PORTB.F7==0)
{
if(status_updated_for_status_1 == 0)
{
Status = Light_Turn_on ;
status_updated_for_status_2 = 0;
status_updated_for_status_3 = 0;
}
}
if(PORTB.F7==1)
{
if(status_updated_for_status_2 == 0)
{
Status = Light_Turn_off;
status_updated_for_status_1 = 0;
status_updated_for_status_3 = 0;
}
}
if((PORTB.F0==1)&&(PORTD.F0=1))
{
if(status_updated_for_status_3 == 0)
{
Status =Light_fault_detected;
status_updated_for_status_1 = 0;
status_updated_for_status_2 = 0;
}
}
// .... other ports comes here
}
//in your while loop
while(1)
{
switch(status)
{
case Light_Turn_on :
status_updated_for_status_1 = 1;
// put your LCD code & uart code here. i.e. action to be taken
// this part taken from your code please modify this .... too bulky .. for time being taken from your code
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);
Status = 0;
break ;
case Light_Turn_off :
status_updated_for_status_2 = 1;
// put your LCD code & uart code here. i.e. action to be taken
Status = 0;
break ;
//.... other cases
}
}
Hi again, Thank you for your reply, let me check it then i will give you the feedback, GOD BLESS YOU..