?? 14thjune.c
字號:
else if(curr_menu == 7)
{
getKey();
curr_key = mapKey(new_num);
if(curr_key == '1') // emergency
{
flag=1;
LIGHT_MODE0 = 0;
LIGHT_MODE1 = 0;
LIGHT_MODE2 = 1;
}
else if ( curr_key == '2') //vacation
{
flag=1;
LIGHT_MODE0 = 0 ;
LIGHT_MODE1 = 1;
LIGHT_MODE2 = 1;
}
else if ( curr_key == '3') //normal
{
flag=1;
LIGHT_MODE0 = 1 ;
LIGHT_MODE1 = 0;
LIGHT_MODE2 = 1;
}
else if ( curr_key == '4') //party
{
flag=1;
LIGHT_MODE0 = 1 ;
LIGHT_MODE1 = 1;
LIGHT_MODE2 = 0;
}
else if ( curr_key == '5') //ON
{
flag=1;
LIGHT_MODE0 = 1 ;
LIGHT_MODE1 = 1;
LIGHT_MODE2 = 1;
}
else if ( curr_key == '6') //OFF
{
flag=1;
LIGHT_MODE0 = 0 ;
LIGHT_MODE1 = 0;
LIGHT_MODE2 = 0;
}
else if(curr_key == 'U')
{curr_menu = 4;flag=1;}
else if(curr_key == 'D')
{curr_menu = 0;flag=1;}
else if(curr_key == '0')
{curr_menu = 8;flag=1;}
}
else if (curr_menu == 8)
{
getKey();
curr_key = mapKey(new_num);
if(curr_key == '8')
{curr_menu = 1;flag=1;}
}
}
else if(security_enabled == 1)
{
getKey2();
curr_key = mapKey(new_num);
if(new_num != 0)
{
if(mapKey(new_num) == 'C')
{
if(num_entered > 0)
num_entered--;
else
return;
}
else
{
tempCode[num_entered] = mapKey(new_num);
num_entered++;
}
}
if(num_entered == 4)
{ lcd_goto(0x40+num_entered-1);
lcd_puts("*");
if(tempCode[0] == securityCode[0] && tempCode[1] == securityCode[1]
&& tempCode[2] == securityCode[2] && tempCode[3] == securityCode[3])
{
security_enabled = 0;
curr_menu = 0;
master_lock = 0;
burglar_enabled = 0;
burglaralarm=0;
fire_enabled = 0;
fireerror==0;
flag=1;
}
num_entered = 0;
}
return;
}
else if(security_enabled == -1) //new pswd enter mode
{
getKey2();
if(new_num != 0)
{
if(mapKey(new_num) == 'C')
{
flag=1;
if(num_entered > 0)
num_entered--;
else
return;
}
else
{
newCode[num_entered] = mapKey(new_num);
securityCode[0] = newCode[0];
securityCode[1] = newCode[1];
securityCode[2] = newCode[2];
securityCode[3] = newCode[3];
num_entered++;
}
//flag=1;
}
if(num_entered == 4)
{
lcd_goto(0x40+num_entered-1);
lcd_puts("*");
security_enabled = 0;
curr_menu = 9;
num_entered = 0;
flag=1;
}
return;
}
}
//***********************************************
//decode button pressed
void getKey(void)
{
TRISD=0x1f;
DelayMs(100);
if (RD4==1)
{
key = PORTD & 0x0F;
new_num=key;
}
else
new_num=55;
}
void getKey2(void)
{
TRISD=0x1f;
DelayMs(200);
while (RD4==0){};
key = PORTD & 0x0F;
new_num=key;
}
char mapKey(int myNum)
{
switch(myNum)
{
case 0:
return '1';
case 1:
return '7';
case 2:
return '4';
case 3:
return '*';
case 4:
return '3';
case 5:
return '9';
case 6:
return '6';
case 7:
return '#';
case 8:
return '2';
case 9:
return '8';
case 10:
return '5';
case 11:
return '0';
case 12:
return 'U';
case 13:
return 'C';
case 14:
return 'D';
case 15:
return 'E';
default:
return '=';
}
}
void task_burglar(void)
{
if (security_enabled ==0)
{
if(burglar_enabled == 1)
{
if(intrudererror ==1)
{
burglaralarm = 1;
LIGHT_MODE1=0; //EMERGENCY
LIGHT_MODE0=0;
LIGHT_MODE2=1;
//security_enabled = 1;
if (burglaralarm==1)
{security_enabled =1;}
}
}
else if (burglar_enabled == 0)
{
burglaralarm = 0;
}
flag =1;
}
}
void task_door(void)
{
// if (security_enabled ==0)
// {
if(master_lock == 1) // activated
{
door_open = 1; // door will not work
LIGHT_MODE1=0; // lightings in normal mode
LIGHT_MODE0=1; // lightings in normal mode
LIGHT_MODE2=1;
}
else
{
door_open=0;
}
if (fire_system == 1)
{
if (fireerror==1)
{
door_openerror=1;
LIGHT_MODE0=0; // EMERGENCY MODE
LIGHT_MODE1=0;
LIGHT_MODE2=1;
//security_enabled = 1;
}
else if (fireerror==0 )
{
door_openerror =0;// must b in opearatn even wifout activatn
// if (reset==1) {door_openerror=0;lightings=0;
}
}
else
door_openerror =0;
// }
}
void initialize(void)
{
TRISB = 0b11110000; // RB0 - RB3 are outputs for LCD.
TRISA = 0b11110011; // RA2 - RA3 are outputs enable for LCD and A0 is input for sensor.
TRISC = 0b00000000; // RC2 is output for alarm
TRISD = 0b00011111; // RD3 = data A - RD0 are input for keypad encoder
TRISE = 0b00000010; // entra output
ADCON1 = 0b00000111; // All PORTA are digital I/Os.
PORTB = 0b00000000; //Clear PORTS.
PORTA &= 0b11110011; //Clear PORT RA2 n RA3
PORTC = 0b00000000;
// Initialize the LCD.
lcd_init();
lcd_clear();
// Initialize variables
master_lock=0;
security_enabled = 0;
fire_enabled = 0;
burglar_enabled = 0;
//lightings_enabled = 0;
door_open = 0;
fire_system=0;
curr_menu = 8;
//for(i=0; i<4; i++)
//securityCode[i] = i+0x31;
securityCode[0] = '2';
securityCode[1] = '3';
securityCode[2] = '4';
securityCode[3] = '5';
num_entered = 0;
fireerror = 0;
intrudererror = 0;
lightingserror = 0;
door_openerror = 0;
burglaralarm=0;
//initialize tasks timers
second=0;
check=0,
check1=0;
minute=20;
hour=5;
}
void main(void)
{
initialize();
flag=1;
while(1)
{
if (curr_menu==8)
{
security_enabled=0;
check=check+1;
if (check ==3) {check1=check1+1;check=0;}
if (check1 == 2){second=second+1;flag=1;check1=0;}
if (second==60){second=0;minute=minute+1;}
if(minute==60){minute=0;hour=hour+1;}
if(hour==24){hour=0;}
if (flag==1 )
{
lcd_clear();
lcd_goto(0x00);
lcd_puts("IDLE MODE");
lcd_goto(0x40);
if (hour==0){lcd_puts("00:");}
if (hour==1){lcd_puts("01:");}
if (hour==2){lcd_puts("02:");}
if (hour==3){lcd_puts("03:");}
if (hour==4){lcd_puts("04:");}
if (hour==5){lcd_puts("05:");}
if (hour==6){lcd_puts("06:");}
if (hour==7){lcd_puts("07:");}
if (hour==8){lcd_puts("08:");}
if (minute==0){lcd_puts("00:");}
if (minute==1){lcd_puts("01:");}
if (minute==2){lcd_puts("02:");}
if (minute==3){lcd_puts("03:");}
if (minute==4){lcd_puts("04:");}
if (minute==5){lcd_puts("05:");}
if (minute==6){lcd_puts("06:");}
if (minute==7){lcd_puts("07:");}
if (minute==8){lcd_puts("08:");}
if (minute==9){lcd_puts("09:");}
if (minute==10){lcd_puts("10:");}
if (minute==11){lcd_puts("11:");}
if (minute==12){lcd_puts("12:");}
if (minute==13){lcd_puts("13:");}
if (minute==14){lcd_puts("14:");}
if (minute==15){lcd_puts("15:");}
if (minute==16){lcd_puts("16:");}
if (minute==17){lcd_puts("17:");}
if (minute==18){lcd_puts("18:");}
if (minute==19){lcd_puts("19:");}
if (minute==20){lcd_puts("20:");}
if (minute==21){lcd_puts("21:");}
if (minute==22){lcd_puts("22:");}
if (minute==23){lcd_puts("23:");}
if (minute==24){lcd_puts("24:");}
if (minute==25){lcd_puts("25:");}
if (minute==26){lcd_puts("26:");}
if (minute==27){lcd_puts("27:");}
if (minute==28){lcd_puts("28:");}
if (minute==29){lcd_puts("29:");}
if (minute==30){lcd_puts("30:");}
if (second==0){lcd_puts("00");}
if (second==1){lcd_puts("01");}
if (second==2){lcd_puts("02");}
if (second==3){lcd_puts("03");}
if (second==4){lcd_puts("04");}
if (second==5){lcd_puts("05");}
if (second==6){lcd_puts("06");}
if (second==7){lcd_puts("07");}
if (second==8){lcd_puts("08");}
if (second==9){lcd_puts("09");}
if (second==10){lcd_puts("10");}
if (second==11){lcd_puts("11");}
if (second==12){lcd_puts("12");}
if (second==13){lcd_puts("13");}
if (second==14){lcd_puts("14");}
if (second==15){lcd_puts("15");}
if (second==16){lcd_puts("16");}
if (second==17){lcd_puts("17");}
if (second==18){lcd_puts("18");}
if (second==19){lcd_puts("19");}
if (second==20){lcd_puts("20");}
if (second==21){lcd_puts("21");}
if (second==22){lcd_puts("22");}
if (second==23){lcd_puts("23");}
if (second==24){lcd_puts("24");}
if (second==25){lcd_puts("25");}
if (second==26){lcd_puts("26");}
if (second==27){lcd_puts("27");}
if (second==28){lcd_puts("28");}
if (second==29){lcd_puts("29");}
if (second==30){lcd_puts("30");}
if (second==31){lcd_puts("31");}
if (second==32){lcd_puts("32");}
if (second==33){lcd_puts("33");}
if (second==34){lcd_puts("34");}
if (second==35){lcd_puts("35");}
if (second==36){lcd_puts("36");}
if (second==37){lcd_puts("37");}
if (second==38){lcd_puts("38");}
if (second==39){lcd_puts("39");}
if (second==40){lcd_puts("40");}
if (second==41){lcd_puts("41");}
if (second==42){lcd_puts("42");}
if (second==43){lcd_puts("43");}
if (second==44){lcd_puts("44");}
if (second==45){lcd_puts("45");}
if (second==46){lcd_puts("46");}
if (second==47){lcd_puts("47");}
if (second==48){lcd_puts("48");}
if (second==49){lcd_puts("49");}
if (second==50){lcd_puts("50");}
if (second==51){lcd_puts("51");}
if (second==52){lcd_puts("52");}
if (second==53){lcd_puts("53");}
if (second==54){lcd_puts("54");}
if (second==55){lcd_puts("55");}
if (second==56){lcd_puts("56");}
if (second==57){lcd_puts("57");}
if (second==58){lcd_puts("58");}
if (second==59){lcd_puts("59");}
// DelayS(5);
}
flag=0;
}
task_lcd();
task_keypad();
task_burglar();
task_door();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -