[SOLVED] PIC18F4550 MikroC code problem

Status
Not open for further replies.

Brillasoko

Newbie level 6
Joined
Mar 22, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,391
I wrote some code in MikroC using a PIC18F4550 to switch on or off an airconditioner based on a sensor detecting the presence of people in a room.
This is the code:
Code:
// LCD Module Connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD Module Connections

int i;   // Timing counter variable

void tempCheck();    // Various control functions
void crosscheck();
void finalCheck();
void crosscheckend();
void secondCheck();
void short_delay();
void medium_delay();
void long_delay();

void main()
{
   CMCON=0x07;
   ADCON1=0x0f;
   OSCCON=0x60;
   ADRESH=ADRESL=0;
   TRISA=0xff;          // Sensor Input
   PORTA=0;
   TRISB=0;             // LCD Output
   PORTB=0;
   TRISC=0;             // Relay Outputs
   PORTC=0;
   delay_ms(1000);
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1,1,"System On");
   delay_ms(2000);
   while(1)
   {
           if(PORTA.f0==1)     // Presence Detected
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Occupied");
                short_delay();
           }

           else               // Detection of unoccupation
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Unoccupied");
                medium_delay();
                secondCheck();
           }
   }
}


// Definition of various functions
void short_delay()   // For 5s delay
{
   for(i=0;i<5;i++)
   {
      delay_ms(1000);
   }
}

void medium_delay()   // For 10s delay
{
   for(i=0;i<10;i++)
   {
       delay_ms(1000);
   }
}

void long_delay()     // For 15s delay
{
   for(i=0;i<15;i++)
   {
        delay_ms(1000);
   }
}

void secondCheck()   // Check before compressor is switched off
{
     if(PORTA.f0==1)
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Occupied");
         short_delay();
     }

     else
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Unoccupied");
         PORTC.f0=1;
         Lcd_Out(2,1,"Compressor Off");
         medium_delay();
         tempCheck();
     }
}

void tempCheck()  // Intermediate check for temporary vacation
{
    if(PORTA.f0==1)
    {
       medium_delay();
       crosscheck();
    }

    else
    {
       long_delay();
       finalCheck();
    }
}

void crosscheck()      // Crosscheck before restoring compressor operation
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        long_delay();
        finalCheck();
     }
}

void finalCheck()       //Check before A/C Shutdown
{
     if(PORTA.f0==1)
     {
        medium_delay();
        crosscheckend();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

void crosscheckend()     // Final Crosscheck
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

But in bulding it I am getting these error messages:
46 324 Undeclared identifier 'Lcd_Init' in expression AirC Project.c
47 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
48 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
49 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
55 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
56 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
62 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
63 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
100 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
101 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
107 324 Undeclared identifier 'Lcd_Cmd' in expression AirC Project.c
108 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
110 324 Undeclared identifier 'Lcd_Out' in expression AirC Project.c
114 312 Internal error '' AirC Project.c
0 102 Finished (with errors): 02 Apr 2013, 08:05:57 AirC Project.mcppi

I have checked the LCD libraries in the library manager. Can anyone help me solve this problem?
Thanks
 
Last edited by a moderator:

I'm using MikroC Pro for PIC v6.00.
What I did:
- unchecked ALL libraries except the normal LCD_Library (not TFT!!)
- replaced all "delay_ms" to "Delay_ms" because my compiler is case sensitive
And the project is compiled without any error (attached)
 

Attachments

  • ForBrillasoko.rar
    42 KB · Views: 131

I compiled your project without doing any changes or deselecting any library and it compiled fine. Try reinstalling the Compiler.
 

Attachments

  • compiled.jpg
    377.4 KB · Views: 518

Thank you guys. It did work when i reinstalled the compiler.
But it came up with a different problem. When i run the simulation, everything on the LCD displays apart from the last sentence ("AirCon Off!").
It rather loops between the two displays before it ("Area Unoccupied, Compressor Off" and "Area Unoccupied"). How do i solve this problem?
 

This is the code:

Code:
/*
   Microcontroller based Air Conditioner Control Design Project
   © Team Glasses, 2013
   Microcontroller used:PIC18F4550
*/

// LCD Module Connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD Module Connections

int i;   // Timing counter variable

void tempCheck();    // Various control functions
void crosscheck();
void finalCheck();
void crosscheckend();
void secondCheck();
void short_delay();
void medium_delay();
void long_delay();

void main()
{
   CMCON=0x07;
   ADCON1=0x0f;
   OSCCON=0x60;
   ADRESH=ADRESL=0;
   TRISA=0xff;          // Sensor Input
   PORTA=0;
   TRISB=0;             // LCD Output
   PORTB=0;
   TRISC=0;             // Relay Outputs
   PORTC=0;
   Delay_ms(1000);
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1,1,"System On");
   Delay_ms(2000);
   while(1)
   {
           if(PORTA.f0==1)     // Presence Detected
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Occupied");
                short_delay();
           }

           else               // Detection of unoccupation
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Unoccupied");
                medium_delay();
                secondCheck();
           }
   }
}


// Definition of various functions
void short_delay()   // For 2 min delay
{
   for(i=0;i<120;i++)
   {
      Delay_ms(1000);
   }
}

void medium_delay()   // For 3 min delay
{
   for(i=0;i<180;i++)
   {
       Delay_ms(1000);
   }
}

void long_delay()     // For 5 min delay
{
   for(i=0;i<300;i++)
   {
        Delay_ms(1000);
   }
}

void secondCheck()   // Check before compressor is switched off
{
     if(PORTA.f0==1)
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Occupied");
         short_delay();
     }

     else
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Unoccupied");
         PORTC.f0=1;
         Lcd_Out(2,1,"Compressor Off");
         medium_delay();
         tempCheck();
     }
}

void tempCheck()  // Intermediate check for temporary vacation
{
    if(PORTA.f0==1)
    {
       medium_delay();
       crosscheck();
    }

    else
    {
       long_delay();
       finalCheck();
    }
}

void crosscheck()      // Crosscheck before restoring compressor operation
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        long_delay();
        finalCheck();
     }
}

void finalCheck()       //Check before A/C Shutdown
{
     if(PORTA.f0==1)
     {
        medium_delay();
        crosscheckend();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

void crosscheckend()     // Final Crosscheck
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

I have also included the Proteus design file
View attachment Air Conditioner Pro.zip
 
Last edited:

If PORTA.f0 is a switch you have to use debounce code for it. Comment and mention in the code which Lcd lines are repeating and what is the value of porta.f0 at that time. Zip and post your hex files and mikroC project files.
 

I am actually using a PIR sensor for the design but I used a switch as a replacement since Proteus does not have one in its libraries.
I have added the comment to the code.

Code:
/*
   Microcontroller based Air Conditioner Control Design Project
   © Team Glasses, 2013
   Microcontroller used:PIC18F4550
*/

// LCD Module Connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD Module Connections

int i;   // Timing counter variable

void tempCheck();    // Various control functions
void crosscheck();
void finalCheck();
void crosscheckend();
void secondCheck();
void short_delay();
void medium_delay();
void long_delay();

void main()
{
   CMCON=0x07;
   ADCON1=0x0f;
   OSCCON=0x60;
   ADRESH=ADRESL=0;
   TRISA=0xff;          // Sensor Input
   PORTA=0;
   TRISB=0;             // LCD Output
   PORTB=0;
   TRISC=0;             // Relay Outputs
   PORTC=0;
   Delay_ms(1000);
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1,1,"System On");
   Delay_ms(2000);
   while(1)
   {
           if(PORTA.f0==1)     // Presence Detected
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Occupied");
                short_delay();
           }

           else               // Detection of unoccupation
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Unoccupied");
                medium_delay();
                secondCheck();
           }
   }
}


// Definition of various functions
void short_delay()   // For 2 min delay
{
   for(i=0;i<120;i++)
   {
      Delay_ms(1000);
   }
}

void medium_delay()   // For 3 min delay
{
   for(i=0;i<180;i++)
   {
       Delay_ms(1000);
   }
}

void long_delay()     // For 5 min delay
{
   for(i=0;i<300;i++)
   {
        Delay_ms(1000);
   }
}

void secondCheck()   // Check before compressor is switched off
{
     if(PORTA.f0==1)
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Occupied");
         short_delay();
     }

     else
     {
         Lcd_Cmd(_LCD_CLEAR);				/* The problem occurs from here when the compressor goes off to the finalCheck() and crosscheckend() functions when the A/C is to go off. In all the instances PORTA.f0=0.
                                                                            The two lines are those in this function and those in the 'else' section of the main() function. */
         Lcd_Out(1,1,"Area Unoccupied");		
         PORTC.f0=1;
         Lcd_Out(2,1,"Compressor Off");
         medium_delay();
         tempCheck();
     }
}

void tempCheck()  // Intermediate check for temporary vacation
{
    if(PORTA.f0==1)
    {
       medium_delay();
       crosscheck();
    }

    else
    {
       long_delay();
       finalCheck();
    }
}

void crosscheck()      // Crosscheck before restoring compressor operation
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        long_delay();
        finalCheck();
     }
}

void finalCheck()       //Check before A/C Shutdown
{
     if(PORTA.f0==1)
     {
        medium_delay();
        crosscheckend();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

void crosscheckend()     // Final Crosscheck
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        PORTC.f1=1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

These are my project files
View attachment project.rar
 

I tried to fix the problem i earlier stated by trying to jump out of the while loop from one of the functions.
But i'm still getting the same results. Can anyone help me. I have commented the places where i would like to exit the while loop and the line i would like to go when i exit the loop.
Thanks.
Code:
/*
   Microcontroller based Air Conditioner Control Design Project
   © Team Glasses, 2013
   Microcontroller used:PIC18F4550
*/

// LCD Module Connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD Module Connections

int i;   // Timing counter variable

void tempCheck();    // Various control functions
void crosscheck();
void finalCheck();
void crosscheckend();
void secondCheck();
void short_delay();
void medium_delay();
void long_delay();

void main()
{
   CMCON=0x07;
   ADCON1=0x0f;
   OSCCON=0x60;
   ADRESH=ADRESL=0;
   TRISA=0xff;          // Sensor Input
   PORTA=0;
   TRISB=0;             // LCD Output
   PORTB=0;
   TRISC=0;             // Relay Outputs
   PORTC=0;
   Delay_ms(1000);
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1,1,"System On");
   Delay_ms(2000);
   while(1)
   {
           if(PORTA.f0==1)     // Presence Detected
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Occupied");
                short_delay();
           }

           else               // Detection of unoccupation
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Unoccupied");
                medium_delay();
                secondCheck();
           }
   }
   Lcd_Cmd(_LCD_CLEAR);             //I want to reach this point of the code after exiting the while loop
   Lcd_Out(1,1,"AirCon Off");	
}


// Definition of various functions
void short_delay()   // For 2 min delay
{
   for(i=0;i<120;i++)
   {
      Delay_ms(1000);
   }
}

void medium_delay()   // For 3 min delay
{
   for(i=0;i<180;i++)
   {
       Delay_ms(1000);
   }
}

void long_delay()     // For 5 min delay
{
   for(i=0;i<300;i++)
   {
        Delay_ms(1000);
   }
}

void secondCheck()   // Check before compressor is switched off
{
     if(PORTA.f0==1)
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Occupied");
         short_delay();
     }

     else
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Unoccupied");
         PORTC.f0=1;
         Lcd_Out(2,1,"Compressor Off");
         medium_delay();
         tempCheck();
     }
}

void tempCheck()  // Intermediate check for temporary vacation
{
    if(PORTA.f0==1)
    {
       medium_delay();
       crosscheck();
    }

    else
    {
       long_delay();
       finalCheck();
    }
}

void crosscheck()      // Crosscheck before restoring compressor operation
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        long_delay();
        finalCheck();
     }
}

void finalCheck()       //Check before A/C Shutdown
{
     if(PORTA.f0==1)
     {
        medium_delay();
        crosscheckend();
     }

     else
     {
        PORTC.f1=1;        // I want to exit the while loop after this line has been executed. 
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}

void crosscheckend()     // Final Crosscheck
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }

     else
     {
        PORTC.f1=1;      // I want to exit the while loop after this line has been executed
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}
 

If you exit while(1) loop then the code that is after while loop gets executed once and the system halts. You have to reset the System to restart the program. Is it what you want to do?


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
/*
   Microcontroller based Air Conditioner Control Design Project
   © Team Glasses, 2013
   Microcontroller used:PIC18F4550
*/
 
// LCD Module Connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD Module Connections
 
int i;   // Timing counter variable
 
void tempCheck();    // Various control functions
void crosscheck();
void finalCheck();
void crosscheckend();
void secondCheck();
void short_delay();
void medium_delay();
void long_delay();
 
void main()
{
   CMCON=0x07;
   ADCON1=0x0f;
   OSCCON=0x60;
   ADRESH=ADRESL=0;
   TRISA=0xff;          // Sensor Input
   PORTA=0;
   TRISB=0;             // LCD Output
   PORTB=0;
   TRISC=0;             // Relay Outputs
   PORTC=0;
   Delay_ms(1000);
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1,1,"System On");
   Delay_ms(2000);
   while(1)
   {
           if(PORTA.f0==1)     // Presence Detected
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Occupied");
                short_delay();
           }
 
           else               // Detection of unoccupation
           {
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Out(1,1,"Area Unoccupied");
                medium_delay();
                secondCheck();
           }
   }
L1:   Lcd_Cmd(_LCD_CLEAR);             //I want to reach this point of the code after exiting the while //loop
   Lcd_Out(1,1,"AirCon Off");   
}
 
 
// Definition of various functions
void short_delay()   // For 2 min delay
{
   for(i=0;i<120;i++)
   {
      Delay_ms(1000);
   }
}
 
void medium_delay()   // For 3 min delay
{
   for(i=0;i<180;i++)
   {
       Delay_ms(1000);
   }
}
 
void long_delay()     // For 5 min delay
{
   for(i=0;i<300;i++)
   {
        Delay_ms(1000);
   }
}
 
void secondCheck()   // Check before compressor is switched off
{
     if(PORTA.f0==1)
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Occupied");
         short_delay();
     }
 
     else
     {
         Lcd_Cmd(_LCD_CLEAR);
         Lcd_Out(1,1,"Area Unoccupied");
         PORTC.f0=1;
         Lcd_Out(2,1,"Compressor Off");
         medium_delay();
         tempCheck();
     }
}
 
void tempCheck()  // Intermediate check for temporary vacation
{
    if(PORTA.f0==1)
    {
       medium_delay();
       crosscheck();
    }
 
    else
    {
       long_delay();
       finalCheck();
    }
}
 
void crosscheck()      // Crosscheck before restoring compressor operation
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }
 
     else
     {
        long_delay();
        finalCheck();
     }
}
 
void finalCheck()       //Check before A/C Shutdown
{
     if(PORTA.f0==1)
     {
        medium_delay();
        crosscheckend();
     }
 
     else
     {
        PORTC.f1=1;        // I want to exit the while loop after this line has been executed.
    goto L1; 
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}
 
void crosscheckend()     // Final Crosscheck
{
     if(PORTA.f0==1)
     {
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"Area Occupied");
        PORTC.f0=0;
        Lcd_Out(2,1,"Compressor On");
        short_delay();
     }
 
     else
     {
        PORTC.f1=1;      // I want to exit the while loop after this line has been executed
    goto L1;
        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Out(1,1,"AirCon OFF!");
     }
}



I was busy that day so I didn't solve your problem. Explain clearly what problem you have with the code so that I can fix it. I had advised you to use debounce delay for switches but you have not done it.


Edit: You have used a lot of delays to check if a pin has changed its previous state or not. It is very wrong. I see you have used 2, 3, and 5 minutes delays in you code. If such a high delay is being executed then no other task is performed at that time. If all delays are removed then maybe all you code will take some 50 ms to execute once. You have to use external interrupt pin to monitor pin state (air conditioner) and timer to create delays.
 
Last edited:

I solved the problem using a for loop to delay the display of the LCD for some time before the system reset itself. The switch is not there, it's just used in place of a PIR sensor. And the 2,3 and 5 min delays are just hypothetical values, shorter delays would be used in the actual circuit.

- - - Updated - - -

I solved the problem using a for loop to delay the display of the LCD for some time before the system reset itself. The switch is not there, it's just used in place of a PIR sensor. And the 2,3 and 5 min delays are just hypothetical values, shorter delays would be used in the actual circuit.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…