|
/*------------------------------------
Mask Option;
---------------------------------------
sysvolt: 5v
SysFreq: 4m
Package: 24-sop
wake-up pa0-7: none-wake-up
Pull-high pa0-7: pull-high
Pull-high pb0-7: pull-high
Pull-high pd0-7: pull-high
WDT clock source: WDTOSC(12kh)
WDT : enable
clr wdt; one
LVR: disable
LVR voltage: 3.8v
pwm: disable
OSC mode: rc
INTO trigger edge:disable
--------------------------------------*/
//------------------------------------------------------
//Product: ksq0001
//Designer: likangfei
//Date: 2011-05-15
//------------------------------------------------------
#include <ht46r22.h>
#pragma vector TmrInt @0x8
#define WaterB _pa0
#define WaterH _pa1
#define WaterM _pa2
#define WaterL _pa3
#define WaterIn _pb0
#define WaterIn1 _pb1
#define Ledstb _pb2
#define Ledda _pb4
#define Ledclk _pb3
#define Jdq1 _pb5
#define Jdq2 _pb6
#define MaDa _pb7
#define Leda _pd0
#define _pbc0 _15_0
#define _pbc1 _15_1
#define _pbc2 _15_2
#define _pbc3 _15_3
#define _pbc4 _15_4
#define _pbc5 _15_5
#define _pbc6 _15_6
#define _pbc7 _15_7
#define _pac0 _13_0
#define _pac1 _13_1
#define _pac2 _13_2
#define _pac3 _13_3
#define _pac4 _13_4
#define _pac6 _13_6
#define _pac5 _13_5
#define _pac7 _13_7
#define _pdc0 _19_0
#define uchar unsigned char
//-------------------------------
//------------------------------------------------------
//uchar KeyBuf @0x40;
uchar DispBuf1 @0x41;
uchar DispBuf2 @0x42;
uchar LedBuf @0x44;
//uchar IrBuf @0x45;
uchar Time @0x46;
//#define Key1 _40_0
//#define Key2 _40_1
//#define Key3 _40_2
#define Leda1 _44_0
uchar TmrCnt;
//uchar KeyCnt;
//uchar BeepCnt;
uchar ErrCnt;
uchar r1;
uchar Adcnt;
uchar Adavr;
uchar Adavr1;
uchar Temp,Temp1,Temp2;
uchar Cnt1,Cnt2;
uchar TooHighCnt;
uchar Leddata;
uchar L1,L2,L3,L4,L5,L6,L7,L8,L9;
uchar a,b,k,j,z,reg1,reg2;
uchar hrl,hrh;
uchar BeepTimes;
uchar Time1;
//uchar IrbitBuf;
unsigned long Adsum;
bit Flag2ms,Flag2ms1;
bit KeyValid;
bit PowerFlag,EnBeep;
bit Flag05s,Flag05s1,Flag05s2,Flag05s3,Flag05s4;
bit Buf,TempFlag;
//bit Irbit,y,x;
bit Key1Flag,Key1Flag1;
bit Key2Flag,Key2Flag1;
bit work,k2,TooHigh;
bit Error,TimeF1;
bit ErrorCode,k4,k5,k6;
//bit IrFlag,yingdaoFlag;
void TmrInt(); // timer/event 0
//void KeyProcess();
//void Keycan();
void TimeCreate();
void AdSub();
void GetTemperature();
void BeepControl();
void ErrorDetect();
void Seg2Port(uchar dbuf);
void Led();
void Display();
void Display1();
void Led1();
//void Ircontrol();
void Led3();
void baowen();
void Led2();
//void dingshi();
void baojing();
void ErrorDetect();
void red_pa();
const unsigned char LEDTAB1[12]=
{
0xE0, // 0
0x00, // 1
0xD0, // 2
0x90, // 3
0x30, // 4
0xB0, // 5
0xF0, // 6
0x00, // 7
0xF0, // 8
0xB0, // 9
0xF0, // E
0x00, // OFF
};
const unsigned char LEDTAB2[12]=
{
0x0F, // 0
0x03, // 1
0x0A, // 2
0x0B, // 3
0x03, // 4
0x09, // 5
0x09, // 6
0x0B, // 7
0x0B, // 8
0x0B, // 9
0x08, // E
0x00, // OFF
};
const unsigned char LEDTAB3[9]=
{
0xC0,
0xC1,
0xC2,
0xC3,
0xC4,
0xC5,
0xC6,
0xC8,
0xCA,
};
const unsigned char LEDTAB4[3]=
{
0x08,
0x04,
0x02,
};
const unsigned char TempTAB2[191]=
{
0,// 165.6061 021
1,// 157.2916 022
2,// 149.4431 023
3,// 142.0318 024
3,// 025
4,// 135.0309 026
5,// 128.4156 027
6,// 122.1623 028
7,// 116.2494 029
7,// 030
8,// 110.6564 031
9,// 105.3643 032
10,// 100.3553 033
10,// 034
11,// 95.6128 035
12,// 91.121 036
12,// 037
13,// 86.8654 038
14,// 82.8323 039
14,// 040
15,// 79.009 041
16,// 75.3833 042
16,// 043
17,// 71.9441 044
17,// 045
18,// 68.6807 046
18,// 047
19,// 65.5832 048
20,// 62.6424 049
20,// 050
21,// 59.8495 051
21,// 052
22,// 57.1963 053
22,// 054
23,// 54.675 055
23,// 056
24,// 52.2786 057
25,// 058
25,// 50 059
25,// 060
26,// 47.833 061
26,// 062
27,// 45.7714 063
27,// 064
28,// 43.8097 065
28,// 066
29,// 41.9425 067
29,// 068
30,// 069
30,// 40.1647 070
30,// 071
31,// 38.4716 072
31,// 073
32,// 36.8589 074
32,// 075
33,// 35.3221 076
33,// 077
33,// 078
34,// 33.8575 079
34,// 080
35,// 32.4612 081
35,// 082
36,// 31.1297 083
36,// 084
36,// 085
37,// 29.8597 086
37,// 087
38,// 28.6481 088
38,// 089
39,// 27.4918 090
39,// 091
39,// 092
40,// 26.3881 093
40,// 094
41,// 25.3344 095
41,// 096
41,// 097
42,// 24.3281 098
42,// 099
43,// 23.3669 100
43,// 101
43,// 102
44,// 22.4485 103
44,// 104
45,// 21.5708 105
45,// 106
46,// 20.7319 107
46,// 108
46,// 109
47,// 19.9298 110
47,// 111
48,// 19.1627 112
48,// 113
48,// 114
49,// 18.4289 115
49,// 116
50,// 17.7269 117
50,// 118
50,// 119
51,// 17.0551 120
51,// 121
52,// 16.412 122
52,// 123
52,// 124
53,// 15.7964 125
53,// 126
54,// 15.2069 127
54,// 128
54,// 129
55,// 14.6422 130
55,// 131
56,// 14.1013 132
56,// 133
57,// 13.583 134
57,// 135
57,// 136
58,// 13.0862 137
58,// 138
59,// 12.61 139
59,// 140
60,// 12.1534 141
60,// 142
60,// 143
61,// 11.7155 144
61,// 145
62,// 11.2956 146
62,// 147
63,// 10.8926 148
63,// 149
63,// 150
64,// 10.506 151
64,// 152
65,// 10.1349 153
65,// 154
66,// 9.7786 155
66,// 156
67,// 9.4366 157
67,// 158
68,// 9.1081 159
68,// 160
69,// 8.7926 161
69,// 162
70,// 8.4895 163
70,// 164
70,// 165
71,// 8.1983 166
71,// 167
72,// 7.9184 168
72,// 169
73,// 7.6494 170
74,// 7.3907 171
74,// 172
75,// 7.142 173
75,// 174
76,// 6.9028 175
76,// 176
77,// 6.6727 177
77,// 178
78,// 6.4513 179
78,// 180
79,// 6.2382 181
79,// 182
80,// 6.0332 183
81,// 5.8359 184
81,// 185
82,// 5.6458 186
82,// 187
83,// 5.4629 188
84,// 5.2866 189
84,// 190
85,// 5.1169 191
86,// 4.9533 192
86,// 193
87,// 4.7958 194
88,// 4.6439 195
88,// 196
89,// 4.4975 197
90,// 4.3564 198
90,// 199
91,// 4.2203 200
92,// 4.0891 201
92,// 202
93,// 3.9625 203
94,// 3.8404 204
95,// 3.7226 205
96,// 3.6089 206
96,// 207
97,// 3.4992 208
98,// 3.3932 209
99,// 3.291 210
100// 3.1923 211
};
//---------------------------------------------
void main()
{
_emi=0; //(1,2)
_eti=0;
_pac=0b00001111;
_pbc=0b00000011;
_pdc=0;
_pa=0b00001111;
_pb=0b00000011;
_pd=0;
_eadi=0;
_eei=0;
//-------------ramClear------------------- //(3)
for (_mp=0x40;_mp!=0x80;_mp++){_iar=0;};
//BeepCnt=0; //(4)
_acsr=0;
_adcr=0b00001000;
_adcr=0b00001001;
_tmrc=0x92; //0x1001 0010 sys/4,time0
_tmr=0x05;
_eti=1;
_emi=1;
_pbc0=1;
_pbc1=1;
_pac0=1;
_pac1=1;
_pac2=1;
_pac3=1;
_pac4=1;
_pac5=1;
_pac6=1;
_pac7=1; //io in
Adcnt=255;
ErrCnt=16;
Leddata=0;
Jdq1=0;
Jdq2=0;
a=0;
//Irbit=x=1;
//y=0;
b=0;
k=0;
L7=0xF0;
Temp1=75;
ErrorCode=0;
//IrFlag=0;
while(1){ //(5)
_clrwdt();
if(Flag2ms)
{Flag2ms=0;
//Keycan();
Led();
//KeyProcess();
//BeepControl();
//Ircontrol();
GetTemperature();
AdSub();
TimeCreate();
Led2();
//dingshi();
Led3();
baowen();
baojing();
ErrorDetect();
red_pa();
}
}
}
//------------------------------------------------------
void Display1()
{ uchar i;
for(i=0;i<8;i++)
{
Ledclk=0;
if(Leda1)
{Ledda=1;}
else{Ledda=0;}
LedBuf>>=1;
Ledclk=1;
_delay(1);
}
}
//------------------------------------------------------
void Display()
{
Ledclk=1;
_delay(1);
Ledstb=1;
_delay(1);
Ledstb=0;
_delay(1);
Display1();
}
//------------------------------------------------------
void Led()
{
Led1();
LedBuf=0b01000100;
Display();
if(Leddata>=9){Leddata=0;}
LedBuf=LEDTAB3[Leddata];
Display();
switch(Leddata)
{
case 0: LedBuf=L1;break;
case 1: LedBuf=L2;break;
case 2: LedBuf=L3;break;
case 3: LedBuf=L4;break;
case 4: LedBuf=L5;break;
case 5: LedBuf=L6;break;
case 6: LedBuf=L7;break;
case 7: LedBuf=L8;break;
case 8: LedBuf=L9;break;
}
Display1();
LedBuf=0b00000010;
Display();
if(work==0){LedBuf=0b10000011;}
else {LedBuf=0b10001011;}
Display();
Leddata++;
Ledstb=1;
}
/* /------------------------------------------------------BeepCtl
void BeepControl()
{
if (BeepCnt||k6){BeepCnt--;EnBeep=1;}
else {EnBeep=0;}
if(Flag05s4)
{
Flag05s4=0;
if(BeepTimes){BeepTimes--;k6=!k6;}
else
{k6=0;}
}
} */
//----------------------------------------------------
void TmrInt()
{
/* if(Irin)
{Irbit=1;}
else{Irbit=0;}
if(Irbit)
{IrbitBuf++;}
else
{IrbitBuf=0;}
if(IrbitBuf>=50)
{yingdaoFlag=1;}
if(x==1&&Irbit==0&&yingdaoFlag)
{ x=0;
if(y==0){y=1;b=0;}
else
{
b++;
if(b>5&&b<13)
{
if(a<4){IrBuf|=0x01;}else {IrBuf&=0xfe;}IrBuf<<=1;
}
a=0;
if(b>=12)
{
y=0;
if(IrBuf)
{IrFlag=1;}
else
{IrFlag=0;}
yingdaoFlag=0;
}
}
}
else
{if(Irbit)
{x=1;}
else
{x=0;}
if(y==1&&x==1)
{a++;}
}
if(EnBeep){Buzzer=!Buzzer;}
else {Buzzer=0;}*/
TmrCnt++;
if(++TmrCnt>=8){TmrCnt=0;Flag2ms=1;Flag2ms1=1;} //250us*8=2000(2msok)
}
//------------------------------------------------------Keycan
/*void Keycan()
{
if(IrFlag==0)
{ KeyBuf=0;
_pac0=1;_pac2=1;_pac3=1;
_pa0=1;_pa2=1;_pa3=1;
_delay(10);
if(!_pa0){Key2=1;}
if(!_pa3){Key3=1;}
if(!_pa2){Key1=1;}
_pac0=0;_pac2=0;_pac3=0;}
} */
//------------------------------------------------------Keyprocess
/* void KeyProcess()
{ if (KeyBuf==0)
{ KeyValid=0;
KeyCnt=10;
}
else
{
if (KeyCnt!=0){KeyCnt--;}
else if(KeyValid==0)
{
KeyValid=1;
if(Key3&&ErrorCode==0) //PowerOff
{ Rly=!Rly;
Buf=!Buf;
work=!work;
BeepCnt=100;
Time=0;
k2=0;
Key2Flag=0;
reg1=0;
reg2=0;
k5=0;
IrFlag=0;
}
if(Key1&&Buf) //Inc
{
if(Key1Flag==0){Key1Flag=1;}
else
{
if(Temp1<30||Temp1>=75){Temp1=30;}
else
{Temp1+=5;}
}
k2=0;
Key1Flag1=1;
BeepCnt=100;
if(reg1==0){Temp2=Temp1;}
reg1=8;
IrFlag=0;
}
if(Key2&&Buf) //dec
{
if(Key2Flag==0){Key2Flag=1;}
else
{
if(Time>=24){Time=0;}
else {Time+=1;}
}
Key2Flag1=1;
BeepCnt=100;
if(reg2==0){Time1=Time;}
reg2=8;
IrFlag=0;
}
}
}
} */
//------------------------------------------------------Timecreate
void TimeCreate()
{
//if(BeepCnt){BeepCnt--;}
if(++Cnt1==0)
{
Flag05s=1;
Flag05s1=1;
Flag05s2=1;
Flag05s3=1;
Flag05s4=1;
}
}
//------------------------------------------------------
/*void Ircontrol()
{
if(IrBuf&&IrFlag)
{
if(IrBuf==0x08)
{Key3=1;}
if(IrBuf==0x04)
{Key2=1;}
if(IrBuf==0x10)
{Key1=1;}
IrBuf=0;
}
} */
//----------------------------------------- A/Dsub
void AdSub()
{ _adcr=0b00001000;
_start=0;_delay(2);_start=1;_delay(2);_start=0;
while(_eocb){;}
Adsum=Adsum+_adrh;
if(++Adcnt>=64){Adcnt=0;Adavr=Adsum/64;Adsum=0;}
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_adcr=0b00001001;
_start=0;_delay(2);_start=1;_delay(2);_start=0;
while(_eocb){;}
Adsum=Adsum+_adrh;
if(++Adcnt>=64){Adcnt=0;Adavr1=Adsum/64;Adsum=0;}
}
//------------------------------------------------------A/D
void GetTemperature()
{
if(Adavr>=16&&Adavr<206&&Flag05s==1&®1==0&®2==0&&Adavr1>=16&&Adavr<206)
{
Flag05s=0;
Temp=TempTAB2[Adavr-16];
DispBuf1=Temp/10;
DispBuf2=Temp%10;
//Key1Flag=0;
//Key1Flag1=1;
//Key2Flag1=1;
}
else if(Adavr>206&&Adavr1>=16&&Adavr<206)
{
Flag05s=1;
DispBuf1=DispBuf2=11;
}
else if(Adavr1>206&&Adavr>=16&&Adavr<206)
{
Flag05s=1;
DispBuf1=DispBuf2=11;
}
return;
}
//------------------------------------------------------xianshi
void Led1()
{
if(Buf&&k2==0&&ErrorCode==0)
{
L1=LEDTAB1[DispBuf1];
L2=LEDTAB2[DispBuf1];
L3=LEDTAB1[DispBuf2];
L4=LEDTAB2[DispBuf2];
if(TempFlag)
{
if(reg2){L5=0x30;L6=0x08;}
else {L5=0x20;L6=0x09;}
L8=LEDTAB4[k];
if(Flag05s2&&k<3){k++;}
if(k>=3){k=0;}
if(Flag05s2)
{
L7>>=1;
if(++z==8){z=0;L7=0xF0;}
Flag05s2=0;
}
L9=0x01;
}
else
{if(reg1==0&®2==0)
{L5=0x00;
L6=0x03;
L7=0x00;
L8=0x00;
L9=0x01;}
if(Key2Flag)
{
L5=0x10;
L6=0x00;
}
}
}
}
//------------------------------------------------------flash
void Led2()
{
if(reg1&&Flag05s1==1&&k5==0)
{ Flag05s1=0;
if(reg2==0)
{
if(reg1<6){Key1Flag1=!Key1Flag1;}
if(Key1Flag1==0){DispBuf1=DispBuf2=11;}
else
{
Temp=Temp1;
DispBuf1=Temp/10;
DispBuf2=Temp%10;
reg1--;
}
}
else
{Temp1=Temp2;reg1=0;}
}
if(reg2&&Flag05s1==1)
{Flag05s1=0;k5=1;
if(reg1==0)
{
L5=0x10;
L6=0x00;
if(reg2<6){Key2Flag1=!Key2Flag1;}
if(Key2Flag1==0){DispBuf1=DispBuf2=11;}
else
{
DispBuf1=Time/10;
DispBuf2=Time%10;
reg2--;
}
}
else
{Time=Time1;reg2=0;k5=0;}
L1=LEDTAB1[DispBuf1];
L2=LEDTAB2[DispBuf1];
L3=LEDTAB1[DispBuf2];
L4=LEDTAB2[DispBuf2];
}
}
//------------------------------------------------------dingshixianshi
void Led3()
{
if(reg2==0&&Key2Flag&&ErrorCode==0)
{
k2=1;
if(Key1Flag==0)
{
DispBuf1=Time/10;
DispBuf2=Time%10;
if(TimeF1){L5=0x10;}
else
{L5=0;}
L6=0x00;
}
else
{if(reg1>=6)
{
DispBuf1=Temp/10;
DispBuf2=Temp%10;
L5=0x00;
L6=0x01;
}
}
L1=LEDTAB1[DispBuf1];
L2=LEDTAB2[DispBuf1];
L3=LEDTAB1[DispBuf2];
L4=LEDTAB2[DispBuf2];
L7=0x00;
L8=0x00;
}
}
//------------------------------------------------------dingshi
/*void dingshi()
{
if(Time>0&®2==0)
{
k5=0;
if(Flag05s3==1)
{hrl++;TimeF1=!TimeF1;Flag05s3=0;}
if(hrl==10)
{hrl=0;hrh+=1;}
if(hrh==2)
{
Time--;
hrh=0;
}
}
if(Time==0&®2==0)
{ k2=0;
Key2Flag=0;
}
}*/
//------------------------------------------------------baowen
void baowen()
{
if(reg1==0&®2==0&&ErrorCode==0&&Time==0)
{
if(TempTAB2[Adavr-16]>=Temp1)
{ if(k4==0){k4=1;BeepTimes=6;}
TempFlag=0;
Jdq1=0;
Jdq2=0;
}
else
{if(TempTAB2[Adavr-16]+3<Temp1)
{
TempFlag=1;
Jdq1=1;
Jdq2=1;
k4=0;
}
}
}
}
//-----------------------------------------------------
void red_pa()
{
unsigned char i;
_pac=0x0f;
_pa=0x0f;
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
_nop();
i=_pa;
switch (i)
{
case 0 : if(Adavr>=16&&Adavr<206&&Adavr1>=16&&Adavr<206)
{
MaDa=0;
Jdq1=1;
Jdq2=1;
}
break;
case 2 :
if(Adavr>=16&&Adavr<206&&Adavr1>=16&&Adavr<206)
{
MaDa=1;
Jdq1=1;
Jdq2=1;
}
break;
case 6 :
if(Adavr>=16&&Adavr<206&&Adavr1>=16&&Adavr<206)
{MaDa=0;Jdq1=1;Jdq2=1;}
break;
case 14 :
MaDa=0;
if(Adavr>=16&&Adavr<206&&Adavr1>=16&&Adavr<206)
{Jdq1=1;Jdq2=1;}
break;
case 15 :
if(Adavr>=16&&Adavr<206&&Adavr1>=16&&Adavr<206)
{MaDa=0;Jdq1=0;Jdq2=0;}
break;
}
}
//------------------------------------------------------
void baojing()
{
if(work&&(TooHigh||ErrorCode))
{
//Key2Flag=0;
//k2=1;
Jdq1=0;
Jdq2=0;
Buf=0;
if(Flag05s1)
{
Error=!Error;
Flag05s1=0;
}
if(Error)
{
DispBuf1=10;
if(TooHigh)
{DispBuf2=1;}
else
{DispBuf2=2;}
L5=0xc0;
}
else
{
DispBuf1=DispBuf2=11;
L5=0x80;
}
L1=LEDTAB1[DispBuf1];
L2=LEDTAB2[DispBuf1];
L3=LEDTAB1[DispBuf2];
L4=LEDTAB2[DispBuf2];
L6=0;
L7=0;
L8=0;
L9=0;
}
}
//------------------------------------------------------
void ErrorDetect()
{
if((Adavr<=3||Adavr>253)&&work){if(ErrCnt!=0){ErrCnt--;}}
else{ErrCnt=120;}
if(ErrCnt==0&&ErrorCode==0)
{ErrorCode=1;BeepTimes=10;}
if(Temp>=98&&work){if(TooHighCnt!=0){TooHighCnt--;}}
else { TooHighCnt=255;}
} |
|