51µ¥Æ¬»ú+ds1302+DS18b20ζÈʱÖÓ(µç·ͼ+CÓïÑÔ³ÌÐò) ÏÂÔØ±¾ÎÄ

void get_ds1302();//¶ÁÈ¡µ±Ç°Ê±¼ä

void w_1byte_ds1302(uchar t);//ÏòDS1302дһ¸ö×Ö½ÚµÄÊý¾Ý uchar r_1byte_ds1302();//´ÓDS1302¶ÁÒ»¸ö×Ö½ÚµÄÊý¾Ý

//***********************************************************************

//DS18B20²âκ¯Êý¶¨Òå

void w_1byte_ds18b20(uchar value);//ÏòDS18B20дһ¸ö×Ö½Ú uchar r_1byte_ds18b20(void);//´ÓDS18B20¶Áȡһ¸ö×Ö½ÚµÄÊý¾Ý void rest_ds18b20(void);//DS18B20¸´Î»³ÌÐò void readtemp_ds18b20(void);//¶ÁÈ¡ÎÂ¶È void dis_temp();//ζÈÏÔʾº¯Êý

//¹²ÑôÊýÂë¹Ü¶ÏÂë±í

const uchar tabl1[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92, // 0 1 2 3 4 5

0x82,0xf8,0x80,0x90,0x86,0x87,0xFF, //6 7 8 9 E T B 0xc6,0xbf,0xff}; // C - const uchar tabl3[]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09}; uchar t0_crycle;

uchar hour_count,minute_count,second_count,msecond_count; uchar clock_hour,clock_minute; uchar countdown_second;

uchar countdown_hour,countdown_minute;

uchar clock_en;//ÄÖÖӹرպͿªÆôµÄ±êÖ¾£¬1¿ªÆô£¬0¹Ø±Õ uchar flag1,second_flag,zancun1,zancun2,zancun3; uchar zancun4,zancun5,zancun6,zancun7; uchar clock_flag,countdown_flag;

uchar msecond_minute,msecond_second,msecond_msecond,msecond_flag;//Ãë±íÏà¹Ø²ÎÊý

uint speak_count;

uchar templ,temph,temp_flag;

uchar t_b,t_s,t_g,t_x,temp_flag2;//´Ó×óµ½ÓÒ·Ö±ð´æ´¢Î¶ȰÙλ£¬Ê®Î»£¬¸öλ£¬Ð¡Êýλ

uchar tab23[3];//={0x40,0x59,0x23,0x28,0x11,0x06,0x09};//ÉϵçʱĬÈϵÄʱ¼ä //Ö÷³ÌÐò void main()

{

P3=0x00; flag1=0; zancun3=0;

msecond_minute=0;//ÖÃÃë±íÏà¹Ø²ÎÊýΪ0 msecond_second=0; msecond_msecond=0; speak=1;//¹Ø±Õ·äÃùÆ÷ speak_count=0; clock_hour=0; clock_minute=0; clock_flag=0;

countdown_flag=0;//µ¹¼ÆÊ±±ê־λΪ0 clock_en=0;//¿ª»úʱĬÈϹرÕÄÖÖÓ init_t0(); TR0=1;//

// set_ds1302();//ÉèÖÃDS1302µÄ³õʼʱ¼ä //½ÓÏÂÀ´¿ªÊ¼±àдÈÃÊýÂë¹ÜÏÔʾµÄ³ÌÐò while(1) {

get_ds1302();

judge_dis();//ÏÔʾ´¦Àí judge_s1(); judge_s2(); judge_s3();

judge_clock();//ÄÖÖÓ´¦Àí³ÌÐò } }

void timer0() interrupt 1 {

TH0=(65536-50000)/256; TL0=(65536-50000)%6; t0_crycle++;

if(t0_crycle==2)// 0.1Ãë {

t0_crycle=0;

msecond_flag=1; msecond_count++;

if(msecond_count==10)//1Ãë {

msecond_count=0; second_flag=1; } }

}

//************************************************** //ÏÔʾ´¦Àíº¯Êý void judge_dis() {

if(flag1==0) {

if(second_flag==1) {

zancun7++; second_flag=0; }

if(zancun7<1) {

if(temp_flag2==1) {

readtemp_ds18b20();//¶ÁÈ¡ÎÂ¶È temp_flag2=0; }

dis_temp();//ζÈÏÔʾº¯Êý }

if(zancun7>=1) {

temp_flag2=1;

zancun4=hour_count&0xf0; zancun4>>=4;

zancun5=minute_count&0xf0; zancun5>>=4;

zancun6=second_count&0xf0; zancun6>>=4;

dis(zancun4,hour_count&0x0f,zancun5,minute_count&0x0f,zancun6,second_count&0x0f);

dis_led();

if(zancun7==5)zancun7=0; } }

if(flag1!=0) {

switch(flag1) {

case 1:

dis(5,10,11,1,12,12);//ÏÔʾSET1

led1_bit=1; led2_bit=1; break; case 2:

dis(5,10,11,2,12,12);//ÏÔʾSET2 break; case 3:

dis(5,10,11,3,12,12);//ÏÔʾSET3 break; case 4:

dis(5,10,11,4,12,12);//ÏÔʾSET4 break; case 5:

dis(5,10,11,5,12,12);//ÏÔʾSET5 break; case 6:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,1); break; case 7:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,2); break; case 8:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,3); break;

case 9://½øÈëÐÞ¸Äʱ¼ä£¬Ê±¼ä·Öλ¸öλÉÁ˸

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,4); break;

case 10://½øÈëÐÞ¸ÄÄÖÖÓ£¬ÄÖÖÓСʱʮλÉÁ˸

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,1); break;

case 11://½øÈëÐÞ¸ÄÄÖÖÓ£¬ÄÖÖÓСʱ¸öλÉÁ˸

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,2); break;

case 12://½øÈëÐÞ¸ÄÄÖÖÓ£¬ÄÖÖÓСʱʮλÉÁ˸

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,3); break;

case 13://½øÈëÐÞ¸ÄÄÖÖÓ£¬ÄÖÖÓСʱ¸öλÉÁ˸