#include"STC15.h"
#include "intrins.h"
//#include "Display.h"
#define Display
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define ADC_POWER 0x80 //ADCµçÔ´¿ØÖÆλ
#define ADC_FLAG 0x10 //ADCÍê³É±êÖ¾
#define ADC_START 0x08 //ADCÆðʼ¿ØÖÆλ
#define ADC_SPEEDLL 0x00 //540¸öʱÖÓ
#define ADC_SPEEDL 0x20 //360¸öʱÖÓ
#define ADC_SPEEDH 0x40 //180¸öʱÖÓ
#define ADC_SPEEDHH 0x60 //90¸öʱÖÓ
sbit baiwei=P1^3;
sbit shiwei=P1^2;
sbit gewei=P1^1;
sbit danwei=P1^0;
//sbit dian=P3^4;
/*sfr P1M0=0x0f;
sfr P1M1=0x00;
sfr P3M0=0xff;
sfr P3M1=0x00; */
sbit up=P1^0;
sbit down=P1^1;
sbit heat=P1^7;
//sbit s2=P1^2;
uchar makesure;//S3¼ü ¡°È·Èϼü¡°
uchar tp=0;
uchar num=0;
uchar ad=0;
char s1,s2,s3,temp;[code]uchar code LED[]={0xCF,0x0C,0xEA,0xE3,0xAC,0x67,0xE7,0x0E,0xEF,0x6F,0x5e}; //¶¨ÒåÊýÂë¹Ü0-9Êý×éºÍСÊýµãµ¥Î»¡°C"[code]const ulong KT_1[14][101]=
{
/*-100 0*/
{ 3568,3523,3492,3461,3430,3399,3368,3337,3305,3274,
3242,3211,3179,3147,3115,3082,3050,3018,2985,2953,
2920,2887,2854,2821,2788,2754,2721,2687,2654,2620,
2586,2552,2518,2484,2450,2416,2381,2347,2312,2277,
2243,2208,2173,2137,2102,2067,2032,1996,1961,1925,
1889,1853,1817,1781,1745,1709,1673,1636,1600,1563,
1527,1490,1453,1416,1379,1342,1305,1268,1231,1193,
1156,1118,1081,1043,1005, 968, 930, 892, 854, 816,
777 ,739 , 701, 662, 624, 585, 547, 508, 469, 431,
392 ,353 , 314, 275, 236, 197, 157, 118, 79, 39,
0
},
/*0 100*/
{ 0, 39, 79, 119, 158, 198, 238, 277, 317, 357,
397, 437, 477, 517, 557, 597, 637, 677, 718, 758,
798, 838, 879, 919, 960,1000,1041,1081,1122,1162,
1203,1244,1285,1325,1366,1407,1448,1489,1529,1570,
1611,1652,1693,1734,1776,1817,1858,1899,1940,1981,
2022,2064,2105,2146,2188,2229,2270,2312,2353,2394,
2436,2477,2519,2560,2601,2643,2684,2726,2767,2809,
2850,2892,2933,2975,3016,3058,3100,3141,3183,3224,
3266,3307,3349,3390,3432,3473,3515,3556,3598,3639,
3681,3722,3764,3805,3847,3888,3930,3971,4012,4054,
4095
},
/*100 200 */
{
4095,4137,4178,4219,4261,4302,4343,4384,4426,4467,
4508,4549,4590,4632,4673,4714,4755,4796,4837,4878,
4919,4960,5001,5042,5083,5124,5164,5205,5246,5287,
5327,5368,5409,5450,5490,5531,5571,5612,5652,5693,
5733,5774,5814,5855,5895,5936,5976,6016,6057,6097,
6137,6177,6218,6258,6298,6338,6378,6419,6459,6499,
6539,6579,6619,6659,6699,6739,6779,6819,6859,6899,
6939,6979,7019,7059,7099,7139,7179,7219,7259,7299,
7338,7378,7418,7458,7498,7538,7578,7618,7658,7697,
7737,7777,7817,7857,7897,7937,7977,8017,8057,8097,
8137
},
/*200 300 */
{
8137, 8177, 8216, 8256, 8296, 8236, 8376, 8416, 8456, 8497,
8537, 8577, 8617, 8657, 8697, 8737, 8777, 8817, 8857, 8898,
8938, 8978, 9018, 9058, 9099, 9139, 9179, 9220, 9260, 9300,
9341, 9381, 9421, 9462, 9502, 9543, 9583, 9624, 9664, 9705,
9745, 9786, 9826, 9867, 9907, 9948, 9989,10029,10070,10111,
10151,10192,10233,10274,10315,10355,10396,10437,10478,10519,
10560,10600,10641,10682,10723,10764,10805,10846,10887,10928,
10969,11010,11051,11093,11134,11175,11216,11257,11298,11239,
11381,11422,11463,11504,11546,11587,11628,11669,11711,11752,
11793,11835,11876,11918,11959,12000,12042,12083,12125,12166,
12207
}
};
/*****************ÑÓʱ×Ó³ÌÐò*****************/
void delayus(uint xus)
{
uint i,j;
for(i=0;i<xus;i++)
for(j=0;j<10;j++);
}
void delay1ms(unsigned int i)
{
uchar j;
while(i--)
{
for(j=0;j>115;j++);
{;}
}
}[code]/*********¶Ë¿Ú³õʼ»¯********/
/*void Init()
{
P1M1&=~0X40;
P1M0|=0Xf3;
P3M1=0X00;
P3M0=0XFF;
P1M0&=~0X40;//P1^6¸ß×èÊäÈë
P1M1|=0X40;
ADC_CONTR=0X80;//Æô¶¯
ADC_START=0X08;
delay1ms(2);
AUXR1&=~0X04;//ADÖµ´¢´æ·½Ê½
ADC_CONTR=0XE1;
} */
void Init()
{
P1M0= 0x0f;
P1M1= 0x00;
P3M0=0xff;
P3M1=0x00;
P1ASF=0x20; //ÉèÖÃP1µÄµÚ6ͨµÀ¶Ë¿Ú×÷ΪģÄâÊäÈë
ADC_RES=0; //Çå³ýADC_RES´æ´¢Æ÷ÒÔÇ°µÄ½á¹û
ADC_RESL=0; //Çå³ýADC_RESL´æ´¢Æ÷ÒÔÇ°µÄ½á¹û
ADC_CONTR=ADC_POWER|ADC_SPEEDLL; //ADC ¿ªÆôµçÔ´¡¢×ª»»ËÙ¶È
delay1ms(2); //ÉϵçÑÓʱ1ms
}
/****¼üÅ̼ì²â*****/
void Keyboardset(void)
{
if((s1+s2+s3)!=0)
{
if(s1==1)
num=num-1;
Display(num,tp);
}
if(s2==1)
{
num=num+1;
Display(num,tp);
if(num>=99)num=99;
}
if(s3==1)
{
if(num>tp)
makesure=1;
return;
}
}
/********°´¼üɨÃ躯Êý**********/
void Keyask(void)
{
uchar tepm;
s1=0;
s2=0;
s3=0;
P1=0x30;
P5=0xff;
tepm=P1&0X30;
if(temp!=0x30)
{
delay1ms(10);
if(temp!=0x30)
switch(temp)
{
case(0x20):s1=1;
while(!(P1&0X10));
break;
case(0x10):s2=1;
while(!(P1&0x20));
break;
}
}
P1=0X70;
if(temp!=0x30)
{
delay1ms(10);
if(temp!=0x30)
switch(temp)
{
case(0x20):s3=1;
while(!(P1&0X10));
}
}
}
/**********AD³õʼ»¯²¢²É¼¯**************/
/*uchar getAD(void)
{
uchar i;
uint sum=0;
for(i=0;i<8;i++)
{
ADC_CONTR|=0X08;
BIT3=0x08(ADC_STARTAD)
delay(1);
P1ASF=0x40;
while((ADC_CONTR&0x10)==0x00);//µÈ´ýת»»½áÊø
ADC_CONTR&=~0x10;
sum+=ADC_RES;
}
sum>>=3;
return(uchar)sum; //Ç¿ÖÆת»»ÎªucharÐÎʽ
} */
uint get_ad_result(uchar channel)
{
uchar ad_finished=0;//´æ´¢A/Dת»»±êÖ¾
uchar i;
uint sum=0;
for(i=0;i<8;i++)
{
ADC_RES=0;//¸ß8λÇåÁã
ADC_RESL=0;//µÍ2λÇåÁã
channel&=0x07;//0000 0111 ÇåÁã¸ß5λ
ADC_CONTR=0x60;//ת»»ËÙÂÊΪ70¸öʱÖÓÖÜÆÚת»»1´Î
_nop_();
ADC_CONTR=channel;//Ñ¡ÔñA/Dµ±Ç°Í¨µÀ
_nop_();
ADC_CONTR|=0x80;//Æô¶¯A/DµçÔ´
delay1ms(2);//ÑÓʱһÏÂʹÊäÈëµçѹ´ïµ½Îȶ¨
ADC_CONTR|=0x08;//0000,1000 Áî ADCS = 1, Æô¶¯A/Dת»»,
ad_finished=0;
while(ad_finished==0)//µÈ´ýA/Dת»»½áÊø
{
ad_finished=(ADC_CONTR&0x10); //0001,0000 ²âÊÔA/Dת»»½áÊø·ñ
}
ADC_CONTR&=0xE7;//1111,0111 Çå ADC_FLAG λ, ¹Ø±ÕA/Dת»», sum+=ADC_RES;
sum+=ADC_RES;
}
sum>>=3; //Çóȡƽ¾ùÖµ
return(uchar)sum; //Ç¿ÖÆת»»ÎªucharÐÎʽ
return(ADC_RES*256+ADC_RESL);//·µ»Ø A/D ¸ß8λ+µÍ2λת»»½á¹û
}
/*************ÊýÂë¹ÜÏÔʾ*****************/
void Display(num,tp)
{
P3=0x00;
baiwei=0;
P3=LED[num/10];
baiwei=1;
delay5ms();
shiwei=0;
P3=LED[num%10];
shiwei=1;
delay5ms();
gewei=0;
P3=LED[tp%10];
gewei=1;
delay5ms();
dianwei=0;
P3=0x5e;
dianwei=1;
delay5ms();
}
/*uchar ge,shi,bai;
bai=num/100%10;
shi=num/10%10;
ge=num%10;
P3=0x00; //ÏûÒþ
baiwei=0;
P3=LED[bai];//°Ùλ
baiwei=1;
delay5ms(2);
shiwei=0;
P3=LED[shi];//ʮλ
shiwei=1;
delay5ms(2);
gewei=0;
P3=LED[ge];//¸öλ
gewei=1;
delay5ms(2);
dianwei=0;
P3=0xe5; //ÏÔʾµ¥Î»¡±C"
dianwe=1;
delay5ms(2);
} */
/***********Ö÷³ÌÐò***********/
void main()
{
Init();
while(1)
{
Keyboardset();
ad=get_AD();
tp=KT_1[ad/2];
if(makesure==1)
{
if(num>=tp)
{
heat=1;
}
if(tp>num)
{
heat=0;
}
}
display(num,tp);
}
}
[/code][/code][/code]