Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Problem on looping, The condition get repeated when it' true.

Status
Not open for further replies.
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..
 

You have to disable ADC.

Code:
ADCON1 = 0x87;


Zip and post the complete mikroC PRO PIC project files and also the Proteus file. I will modify the code for you.
 

Yes, andre_teprom is right.

As PORTA and E which only have ADC functions are not used ADC doesn't need to be disabled.


Not related to your problem but these

Code:
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;

should be replaced by

Code:
sbit LCD_RS at LATC0_bit;
sbit LCD_EN at LATC1_bit;
sbit LCD_D4 at LATC2_bit;
sbit LCD_D5 at LATC3_bit;
sbit LCD_D6 at LATC4_bit;
sbit LCD_D7 at LATC5_bit;

as you are using PIC18F.


You see looping problem because when one or more of the fault if() conditions are true then those if() conditions are executed repeateadly in the main loop and also the sms are sent repeateadly. So, you have to use a array of flag because if there are more than 1 fault then more than one sms has to be sent so you have to set the required flag in the flag array based on the fault(s) and then check the flag array and if flag for a fault is set then sms for that fault has to be sent and the flag has to be cleared. This will solve looping problem but for lcd there should be looping because if there are more than one fault then lcd should constantly and repeateadly show all the faults.
 
Last edited:

You have to disable ADC.

Code:
ADCON1 = 0x87;


Zip and post the complete mikroC PRO PIC project files and also the Proteus file. I will modify the code for you.



Hi, see my attachment..
 

Attachments

  • DOC.rar
    131.4 KB · Views: 43

In your project I guess you are using LDR to detect day and night or dusk or dawn to control street lights. Right ?

If yes,

there is a

Code:
while9PORTB.F7 == 1) {

}

for this why loop is used. Why can't you use

Code:
if(PORTB.F7 == 1) {

}

?

Using loop will repeateadly send SMS after turning ON the lights. In code you have to use a flag and set the flag when

Code:
PORTB.F7 == 1

and then use this flag to send SMS and then clear the flag so that SMS is not repeateadly sent.
 

In your project I guess you are using LDR to detect day and night or dusk or dawn to control street lights. Right ?

If yes,

there is a

Code:
while9PORTB.F7 == 1) {

}

for this why loop is used. Why can't you use

Code:
if(PORTB.F7 == 1) {

}

?

Using loop will repeateadly send SMS after turning ON the lights. In code you have to use a flag and set the flag when

Code:
PORTB.F7 == 1

and then use this flag to send SMS and then clear the flag so that SMS is not repeateadly sent.



Hi, It should if(PORTB.F7 == 1) instead of while(PORTB.F7 == 1) sorry for that
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top