?? 330_keyboard.c
字號:
/******************
Filename:Keyboard.c
Autor: liuyulong
Date: 4-17 2006
Description:Scan the keyboard and save the num of keyboard,then depend on the num of keyboard
operation display and control;
History:
Autor Date Version
liuyulong 2006-08 2.1
************/
//全局變量聲明;
extern unsigned int temp; //溫度轉換緩沖;
extern struct keyboard out;
extern struct screen setdata;
unsigned int pcatime;
extern xdata unsigned char screenkeep; //屏保寄存器;
extern bit powersize; //控制器開關標志位;為1時控制器打開,為0時整個系統關閉;
unsigned char keytimemenu;
/**********************************************
Function:keyboard
Description:Scan keyboard and control the LCD;
Calls:keyscan(),wind(unsigned char x),delay(),del1s(),void write(unsigned char add,unsigned char da,bit d)
tempcheck(),closetemp(),colsewind(),returnsetup(),closemode(),closekind()
numone(unsigned char x),numten(unsigned char x);
Called by:main(),uart0();
***********************************************/
void keyboard()
{
unsigned char keynum,speedh,speedl,temph,templ;
temph=tempmax; //Establish the temperature big limits ;
templ=tempmin; //Establish the temperature less limits ;
speedh=speedmax; //Establish the wind big limits ;
speedl=speedmin; //Establish the wind less limits ;
screenkeep++;
if(screenkeep>50) //If system scan the func keyboard beyond 50 times ;
{
screenkeep = 50; //Clear screenkeep Resigter ;
out.menu = 0; //Menu cell cleared ;
led = 1; //Close LCD light ;
delay10ms(); //Delay 10 ms ;
}
keynum=keyscan(); //Num of keybosrd scaned ;
switch(keynum)
{
case 0:break; //No key ;
case 1: //Menu key is true ;
led=0;
screenkeep = 0;
out.menu++;
if(out.menu > 5) //Out.menu memory the system menu ;
{
out.menu = 0; //If Menu num beyond 5 ,out.menu equal 0 ;
}
break;
case 2: //The key "SUB" is true ;
screenkeep = 0;
led = 0;
if(out.menu == 2) //If menu equal 2,establish temperature memory ;
{
out.temp--; //Establish temperature memory Minus 1;
}
else if(out.menu == 3) //If menu equal 3,establish wind memory ;
{
if(out.wind < 1) //Establish wind less limits is zero,if out.wind big to 1,it will minus 1;
{
out.wind = 0; //If out.wind equal zero ,it will not minus 1;
}
else out.wind--;
}
else if(out.menu == 4) //If menu equal 4,establish ;
{
out.manual = 1; //manual is true ;
out.automode = 0; //auto mode is false ;
}
else if(out.menu == 5) //If menu equal 5,establish
{
out.heat = 1; //heating is true ;
out.cool = 0; //cool is false ;
}
else ;
break;
case 3:screenkeep = 0; //If key "ADD" is true ;
led = 0;
if(out.menu==0x02) //Some to up ;
{
out.temp++;
}
else if(out.menu==0x03)
{
out.wind++;
}
else if(out.menu==0x04)
{
out.manual=0;
out.automode=1;
}
else if(out.menu==0x05)
{
out.heat=0;
out.cool=1; //Some to up ;
}
else ;
break;
case 4:
rstsrc = 0x10 ;
/*
powersize = 1 ; //Power size is true means system is stop ;
while(powersize)
{
ea = 0 ; //Stop AC electrial machinery ;
led = 1 ; //Close LCD light ;
out.wind = 0 ;
closelcd() ; //Close LCD ;
pca0cn = 0x00 ;
while (keynum == 4) //If the key "POWER" is not press,wait for press ;
{
keynum = keyscan ();
}
keynum = 0;
while (keynum != 4) //If the key "POWER" is not press,wait for press ;
{
keynum = keyscan ();
}
while (keynum == 4) //If the key "POWER" is not press,wait for press ;
{
keynum = keyscan ();
}
powersize = 0 ; //Power size is false means system is working ;
} //The system is working ;
keynum = 0 ;
led = false; //LCD light open ;
ea = true; //AC electrial machinery is working ;
out.menu = false; //Menu memory is zero;
out.wind = lastsetupwind; //The wind of Last system end ;
out.automode = lastsetupmode; //The mode of last system end ;
tempcheck(); //Scan the temperature of house ;
display(); //Scan display;
*/
break;
}
if(out.menu == 0) //If out.menu memory is 1,means have key pressed,first press;
{
display (); //Scan display; //Delay 1 second ;
}
if(out.menu == 1) //If out.menu memory is 1,means have key pressed,first press;
{
display (); //Scan display;
led = 0; //Have key pressed ,so LCD light bright ;
del1s (); //Delay 1 second ;
}
if(out.menu == 2) //Temperature established flash ;
{
if(out.temp < templ) //Temperature established less limits ;
{
out.temp = templ;
}
if(out.temp > temph) //Temperature established max limits ;
{
out.temp = temph;
}
closetemp(); //Close temperature display ;
del1s();
write(4,3,1);
numone(out.temp % 10); //Display temperature num one ;
numten(out.temp / 10); //Display temperature num ten ;
del1s();
}
if(out.menu == 3) //Wind flash display ;
{
if(out.wind < 1) //Wind established less limits ;
{
out.wind = 0;
}
if(out.wind > 9) //Wind established max limits ;
{
out.wind = 10;
}
closetemp(); //Close temperature display ;
closewind(); //Close wind display ;
del1s();
write(4,3,0);
numone(out.wind); //Display wind one ;
numten(out.wind / 10); //Display wind ten ;
write(0,0,0);
wind(out.wind); //Display wind size ;
del1s(); //Delay 1 second ;
}
if(out.menu == 4) //Mode flash ;
{
closemode(); //Close mode size ;
del1s();
if(out.manual == 1) //If manual mode is true ;
{
write(3,1,1); //Display manual mode size ;
}
else
{
write(3,2,1); //Else display auto mode size ;
}
del1s();
}
if(out.menu == 5) //Heat and cool size flash ;
{
closekind(); //Close heat and cool size ;
del1s();
if(out.heat == 1) //If heat is true ;
{
write(2,1,1); //Display heat size ;
}
else
{
write(2,2,1); //If cool is true , display cool size ;
}
del1s();
}
}
/**********************************************
Function:tempcheck
Description:Input the analog temperature of house ,then conventers to digital;
Called by:main(),keyboard();
***********************************************/
void tempcheck(void){ //Check temperature of house ;
unsigned int tempaa;
unsigned char time ;
//float f ;
p0mdin = 0xf7 ;
p0mdout = 0xf7 ;
p0skip = 0x08 ; //跳過P0.3 作為A/D模擬輸入
delay10ms() ;
ref0cn = 0x0f ;
amx0p = 0x03 ;
amx0n = 0x11 ;
adc0cf = 0x38;
adc0cn = 0xc0;
temp = 0;
for (time = 0 ;time < 0x02 ;time ++){
adc0cn |= 0x10; //Open the ADC0 conventer
while(ad0int == 0){ //Waiting conventer over;
;
}
tempaa = 0 ; //Clear buffer ;
tempaa = (adc0h << 8); //Adc0h to buffer ;
tempaa += adc0l; //Adc0l to buffer ;
temp += tempaa ;
}
temp = (temp >> 1) ;
setdata.tempnum = temp / 3 ;
p0mdin = 0xff ;
p0mdout = 0xf7 ;
p0skip = 0x00 ; //屏蔽A/D模擬輸入
/*
tempaa = temp % 17; //
if(tempaa > 13){
setdata.tempnum = 22 ;// temp / 17;
// setdata.tempnum++;
}
if (tempaa < 4){
setdata.tempnum = 22 ;//temp / 17; //17:4096/240 is persent 10 microveted;
}
*/
}
/**********************************************
Function:SYSCLK_Init
Description:Choose the clock of system;
Called by:main();
***********************************************/
void SYSCLK_Init (void){
int i; // delay counter
oscxcn = 0x67; // start external oscillator with
// 22.1184MHz crystal
for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
while (!(oscxcn & 0x80)) ; // Wait for crystal osc. to settle
oscicn = 0x87;//0x88 // select external oscillator as SYSCLK
oscxcn=0x00;
pcon=0x80;
// source and enable missing clock
// detector
}
/**********************************************
Function:SYSCLK_Init
Description:Enable crossbar and weak pull-ups;
Called by:main();
***********************************************/
void PORT_Init (void){
p0mdin = 0xf7 ;
p0mdout = 0xf7 ;
p0skip = 0x08 ;
p1mdin = 0xff ;
p1mdout = 0xff ;
p1skip = 0x00 ;
p2mdout = 0x01 ;
xbr0 = 0x01 ;
xbr1 = 0x42 ; // Enable crossbar and weak pull-ups
}
void PCA_Init(void){
unsigned int PCA ;
if(out.wind == 0){
pca0cn = 0x00 ;
}
if (out.wind != 0){
pca0md = 0x03 ;
pca0cpm1 = 0xcb ;
PCA = 2000 * (10 - out.wind) ;
PCA = 14000 + PCA ;
pca0cpl1 = PCA ;
pca0cph1 = (PCA >> 8);
pca0cn = 0x40 ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -