Brillasoko
Newbie level 6
- Joined
- Mar 22, 2013
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,391
// 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!");
}
}
/*
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!");
}
}
/*
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!");
}
}
/*
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!");
}
}
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!"); } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?