这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 为什么定时器2只能使用一次,第二次就不产生中断了?__高手指点下

共3条 1/1 1 跳转至

为什么定时器2只能使用一次,第二次就不产生中断了?__高手指点下

菜鸟
2009-04-01 23:37:09     打赏

#include "reg52.h"
#include "math.h"
#include "intrins.h"
/********************************************************/
typedef unsigned char  uint8;                                   /* 定义可移植的无符号8位整数关键字            */
typedef signed   char  int8;                                    /* 定义可移植的有符号8位整数关键字            */
typedef unsigned int   uint16;                                  /* 定义可移植的无符号16位整数关键字           */
typedef signed   int   int16;                                   /* 定义可移植的有符号16位整数关键字           */
typedef unsigned long  uint32;                                  /* 定义可移植的无符号32位整数关键字           */
typedef signed   long  int32;                                   /* 定义可移植的有符号32位整数关键字  
/***********************************************************/
/**********************************************************/
/************ vfd    ************************************/
//unsigned char code disp_0[]={0x15,0x10,0x51,0x51,0x54,0x45,0x45,0x11,0x55,0x55 };
//unsigned char code disp_1[]={0x15,0x04,0x11,0x14,0x04,0x14,0x15,0x04,0x15,0x14 };
//unsigned char code disp_2[]={0x2a,0x20,0xa2,0xa2,0xa8,0x8a,0x8a,0x22,0xaa,0xaa};
//unsigned char code disp_3[]={0x2a,0x08,0x22,0x28,0x08,0x28,0x2a,0x08,0x2a,0x28 };
/***************************************************************************************/
unsigned char code disp_0[]={0x15,0x04,0x51,0x45,0x44,0x45,0x55,0x04,0x55,0x45,0x54,0x55,0x11,0x55,0x51,0x50,0x15,0x54 };
unsigned char code disp_1[]={0x15,0x01,0x11,0x11,0x05,0x14,0x14,0x11,0x15,0x15,0x15,0x04,0x14,0x01,0x14,0x14,0x05,0x04 };
unsigned char code disp_2[]={0x2a,0x08,0xa2,0x8a,0x88,0x8a,0xaa,0x08,0xaa,0x8a,0xa8,0xaa,0x22,0xaa,0xa2,0xa0,0x2a,0xa8};
unsigned char code disp_3[]={0x2a,0x02,0x22,0x22,0x0a,0x28,0x28,0x22,0x2a,0x2a,0x2a,0x08,0x28,0x02,0x28,0x28,0x0a,0x08};
/**********************************************************************************/
/**********************************************************************************/
/**********************************************************************************/
unsigned char code disp_4[]={0x2a,0x20,0xa2,0xa2,0xa8,0x8a,0x8a,0x22,0xaa,0xaa,0xaa,0x88,0x0a,0xa0,0x8a,0x8a,0x88,0x28};
unsigned char code disp_5[]={0x2a,0x08,0x22,0x28,0x08,0x28,0x2a,0x08,0x2a,0x28,0x0a,0x2a,0x22,0x2a,0x22,0x02,0x0a,0x2a};
unsigned char code disp_6[]={0x15,0x10,0x51,0x51,0x54,0x45,0x45,0x11,0x55,0x55,0x55,0x44,0x05,0x50,0x45,0x45,0x44,0x14};
unsigned char code disp_7[]={0x15,0x04,0x11,0x14,0x04,0x14,0x15,0x04,0x15,0x14,0x05,0x15,0x11,0x15,0x11,0x01,0x05,0x15};
unsigned char code disp1[]={0x01,0x57,0x18,0x50,0x46,0x60,0x20,0x55,0x00,0x40,0x04,0x22,0x29,0x12,0x28,0x2c};
uint8 bdata set1;
 uint8 vfd_disp[16];
uint8 disp_a[8];
uint8 disph[3];
uint8 bdata vfd_data;
uint8 disp_count,disp_count1;
uint8 buffer_uv,buffer_liang,buffer_size,buffer_chong;
uint8 b,c;
sbit vfd_data0=vfd_data^0;
void data_write(void);
void write_task(void);
void convert(void);
void convert1(void);
void xiaoyan(void);
void xiaoyan1(void);
void rtc_xiaoyan(void);
/********************************************************/
void WDT(void);
/**********************************************************/
void delay(void);
void check_uv(void);
void check_mg(void);
void check_size(void);
void func(void);
void minus(void);
void ji_count(void);
void ji_batch(void);
void jishu(void);
void anjin(void);
void jincao(void);
void xianshi(void);
void jishu(void);
void chushi(void);
void weicao(void);
void shiwei(void);
void zhijin(void);
void send_jishu(void);
void cuv(void);
void jczt(void);
void key_add(void);
void key_mg(void);
void key_uv(void);
void key_size(void);
void key_preset(void);
void key_preset_add(void);
void key_preset_dec(void);
void frist(void);
/*****************1302******************************************/

/**********************************************************/
sbit sw_mg=P3^6;
sbit sw_uv=P0^7;
sbit sw_size=P0^6;
sbit sw_add=P1^4;
sbit sw_preset=P3^5;
sbit sw_fuwei=P3^5;
sbit sw_preset_add=P0^1;
sbit sw_add1=P0^1;
sbit sw_preset_dec=P0^2;
sbit sw_dec=P0^2;
/********************************************************/
sbit  a_sda=P2^2;
sbit  a_scl=P2^3;
sbit  chong_a=P2^4;
sbit  chong_b=P2^6;
sbit cheshi =P2^2;
sbit beep=P1^6;
sbit T2_PORTE=P1^2;
sbit motor_b=P1^3;
sbit motor_s=P1^5;
sbit input_c=P2^0;
sbit output_c=P2^1;
sbit count_ca=P3^0;
sbit count_cb=P3^1;
sbit da_chi=P3^2;
sbit VIO=P2^5;
sbit right_mg=P3^7;
sbit  disp_clk = P1^0;
sbit  disp_cs = P1^2;
sbit  disp_out = P1^1;
sbit  disp_clk1 = P0^4;
sbit  disp_cs1 = P0^3;
sbit  disp_out1 = P0^5;
/************************************************************/

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

/**********************************************************/
uint8 bdata set;
uint8 batch1[3];
uint8 bdata count;
uint8 bdata tiao;
sbit tiao0=tiao^0;
sbit tiao1=tiao^1;
sbit tiao2=tiao^2;
sbit tiao3=tiao^3;
sbit tiao4=tiao^4;
sbit tiao5=tiao^5;
sbit tiao6=tiao^6;
sbit tiao7=tiao^7;
uint8 bdata biao;
sbit biao0=biao^0;
/****************************************************/
uint8 uv_zhi,mg_zhi,liang_zhi1,fu_zhi,jishu_zhi,chong_a_data,chong_b_data,chong_zhi,chong_zhi1,shou_zhi,shoudong;
uint8 yanshi,yanshi1,yanshi2,yanshi5;
uint8 fu_can;
uint16 fu_can1;
uint8 huan0,huan1,huan2;
uint8 dachi,huan3;
uint8 idata k,che_mapan;
uint8 uv;
uint8 ma_pan;
uint8 fu_huan;
uint8 banhuan,vfd_huan,vfd_huan1;
uint8  motor_zuan,beep_du;
uint8 weima,i,n;
uint8 set_led,set_led1,mapanl,beep_huan,motor_huan,motor_s_yanshi;
unsigned char bdata ok;
sbit  data7=ok^7;
/***************************************************/
 /***************************************************/
/*************************************************************/
void start(void);
void stop(void);
void receive(void);
void send(void);
void read2401a(void);
void write2401a(void);
void ack(void);
void noack(void);
void delayms(void);
/***************************************************/
/***************************************************/
//at2401a寄存//
uint8 bdata huan_2401;
uint8 bdata huan1_2401;
sbit huan_2401_7=huan_2401^7;
sbit huan1_2401_7=huan1_2401^7;
uint8 bdata a_ack;
sbit ack0=a_ack^0;
uint8 m;
/***************************************************/

/***************************************************/
void chushi(void){
    P2=0xff;
    TMOD=0x02; 
 TCON=0x00;
 TH0=0;
 TL0=0;
    TH1=0;
    TL1=0;

    T2CON=0;
 TL2=0x00;
 TH2=0Xff;
 RCAP2L=0x00;
    RCAP2H=0Xff;   //c6


    IE=0x2F; 
    IP=1;
 TR0=1;
    disp_a[0]=0;
    disp_a[1]=0;
    disp_a[2]=0;
    disp_a[3]=0;
    disp_a[4]=0;
    disp_a[5]=0;
    disp_a[6]=0;
 beep=0;
 beep_huan=0x02;
 motor_huan=0x02;
 motor_b=1;
 motor_s=0;

 EA=1;
 TR2=1;
 }
                            void main(void)

      _nop_();
      _nop_();
      _nop_();
      _nop_();
     chushi();
  while(1){
     _nop_();
     _nop_();
     _nop_();
     _nop_();
     _nop_();
     _nop_();
     _nop_();
     _nop_();
  }

}
//**************************************************************
/************************************************************************/
/***********************************************************************/
/************************************************************************/
/***********************        VFD  *********************************/
/************************************************************************/
                           void xianshi (void)
{      
      convert();
      convert1();
      xiaoyan();
      xiaoyan1();
//      rtc_xiaoyan();
      disp_cs=0;
   vfd_data=0X38;
   data_write();
   disp_cs=1;
      _nop_();
   disp_cs=0;
   vfd_data=0X70;
   data_write();
   disp_cs=1;
      _nop_();
      disp_cs=0;
   vfd_data= 0xc0;
      data_write();
        _nop_();
     c=9;
   b=0;
   while(c>0){
   vfd_data= vfd_disp[b];
      data_write();
   b=b+1;
   vfd_data=vfd_disp[b];
      b=b+1;
   data_write();
   vfd_data=0;
   data_write();
     c=c-1;
     }
     disp_cs=1;
     _nop_();
     disp_cs=0;
     vfd_data=0XBF;
     data_write();
     disp_cs=1;
     /******************外显**************************************/
      disp_cs1=0;
      disp_clk1=0;
      ok=weima;
       ok=~ok;
      for (n=0;n<8;n++){
         disp_out1=data7;
         disp_clk1=1;
         _nop_();
         _nop_();
         disp_clk1=0;
         ok<<=1;
      }
      ok=disph[i];
      ok=~ok;
      for (n=0;n<8;n++){
         disp_out1=data7;
         disp_clk1=1;
         _nop_();
         _nop_();
         disp_clk1=0;
         ok <<=1;
      }
      disp_cs1=1;
      _nop_();
      _nop_();
      disp_cs1=0;
      weima>>=1;
      i=i+1;
      if(i==3){
       i=0;
       weima=0x40;
      } 
  /******************外显**************************************/
}
void data_write (void) {
  disp_out=1;
  for (k=0;k<8;k++){
  disp_clk=0;
  disp_out=vfd_data0;
  disp_clk=1;
  vfd_data >>=1;
  }
}
void convert(void){
/**************************************************/
 //16511G1=vfdG8,16511G3=VFDG6
/***************************************************/
    vfd_disp[0]=0;
    vfd_disp[1]=0;
    vfd_disp[2]=0;
    vfd_disp[3]=0;
    vfd_disp[4]=set_led;
    vfd_disp[5]=0x00;
    vfd_huan=disp_6[disp_a[0]];
    vfd_huan1=disp_4[disp_a[1]];
    vfd_disp[6]=vfd_huan|vfd_huan1;
    vfd_huan=disp_7[disp_a[0]];
    vfd_huan1=disp_5[disp_a[1]];
    vfd_disp[7]=vfd_huan|vfd_huan1;
    vfd_huan=disp_6[disp_a[2]];
    vfd_huan1=disp_4[disp_a[3]];
    vfd_disp[8]=vfd_huan|vfd_huan1;
    vfd_huan=disp_7[disp_a[2]];
    vfd_huan1=disp_5[disp_a[3]];
    vfd_disp[9]=vfd_huan|vfd_huan1;
    vfd_disp[10]=(motor_huan<<4)|set_led1|0x10;
    vfd_disp[11]=beep_huan|(motor_huan>>4);
    vfd_huan=disp_2[disp_a[6]];
    vfd_disp[12]=vfd_huan;
    vfd_huan=disp_3[disp_a[6]];
    vfd_disp[13]=vfd_huan;
    vfd_huan=disp_2[disp_a[4]];
    vfd_huan1=disp_0[disp_a[5]];
    vfd_disp[14]=vfd_huan|vfd_huan1;
    vfd_huan=disp_3[disp_a[4]];
    vfd_huan1=disp_1[disp_a[5]];
    vfd_disp[15]=vfd_huan|vfd_huan1;
}
void convert1(void){
    disph[0]=disp1[disp_a[3]];
    disph[1]=disp1[disp_a[2]];
    disph[2]=disp1[disp_a[1]];
}
void xiaoyan(void){
  if(disp_a[0]==0){
    vfd_disp[6]=vfd_disp[6]&0xaa;
    vfd_disp[7]=vfd_disp[7]&0x2a;
    if (disp_a[1]==0){
      vfd_disp[6]=vfd_disp[6]&0x55;
      vfd_disp[7]=vfd_disp[7]&0x15;
      if (disp_a[2]==0){
         vfd_disp[8]=vfd_disp[8]&0xaa;
         vfd_disp[9]=vfd_disp[9]&0x2a;
      }
   }
  }
  if (disp_a[4]==0){
     vfd_disp[14]=vfd_disp[14]&0x55;
     vfd_disp[15]=vfd_disp[15]&0x15;
     if (disp_a[5]==0){
        vfd_disp[14]=vfd_disp[14]&0xaa;
        vfd_disp[15]=vfd_disp[15]&0x2a;
     }
  }

}
void xiaoyan1(void){
  if (disp_a[1]==0){
      disph[2]=0xff;
     if (disp_a[2]==0){
      disph[1]=0xff;
     }
  }
}

void TIME2(void) interrupt 5
{
  TF2=0;
        beep=0;
 motor_b=0;
 motor_s=1;
    disp_a[0]=disp_a[0]+1;
    disp_a[1]=disp_a[1]+1;
    disp_a[2]=disp_a[2]+1;
    disp_a[3]=disp_a[3]+1;
    disp_a[4]=disp_a[4]+1;
    disp_a[5]=disp_a[5]+1;
    disp_a[6]=disp_a[6]+1;
 xianshi();

}


void ji_count(void){
    batch1[3]=batch1[3]+1;
   if(batch1[3]>9){
        batch1[3]=0;
  batch1[2]=batch1[2]+1;
  if(batch1[2]>9){
         batch1[2]=0;
   batch1[1]=batch1[1]+1;
   if(batch1[1]>9){
           batch1[1]=0;
     batch1[0]=batch1[0]+1;
     if(batch1[0]>9){
            batch1[0]=0;
     }
   }
  }
   }
      disp_a[3]=disp_a[3]+1;
      if (disp_a[3]>9){
       disp_a[3]=0;
       disp_a[2]=disp_a[2]+1;
       if (disp_a[2]>9){
        disp_a[2]=0;
        disp_a[1]=disp_a[1]+1;
        if (disp_a[1]>9){
          disp_a[1]=0;
          disp_a[0]=disp_a[0]+1;
            if(disp_a[0]>9){
              disp_a[0]=0;
            }
        }
       }
       }   
}




关键词: 为什么     定时器     只能     使用     一次     第二次     就不         

专家
2009-04-20 11:33:14     打赏
2楼

我也想学习一下,等高手了!


菜鸟
2009-05-16 03:37:32     打赏
3楼

懒得看了,自己有没有重置哦


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]