⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hw_627a.c

📁 627A的应用
💻 C
字号:
/*********************************************************************/
/*公司名称: 成都旭光安全技术有限责任公司                             */
/*程序名:  红外火焰探测器监控程序(控制芯片PIC16F627A)             */
/*编 制 人:杨海燕                     日期:2007-01-15              */
/*功能描述:应急抗电磁场辐射                                         */
/*版    本:V1.0                                                     */ 
/*********************************************************************/
#include<pic16f62xa.h>
#include<math.h> 
//#include <absacc.h>
#define  uchar unsigned char
#define  unint unsigned int

//#define FIREH  RA0     // fire hige
//#define FIREL  RB5     // fire low 

#define RUN_FIRE  RB3  // run and fire display

uchar times=0,total_times=0,run=0,dog_con=0;
unint count=0,total_count=0; 
 
bit  fire_bit=0;    //fire_con=0;

void init_pic16f627A();

void init_pic16f627A()
{  
    CMCON=0x07;
    RA0=0;RB5=1;
    RA2=1;RB4=1;
    TMR1H=0;TMR1L=0;                       
    // OPTION_REG SET
    RBPU=1;	   // 禁止PORTB的弱上拉。 
    T0CS=0;    // 定时器计数器选择位,=0为定时器;=1为计数器;
    PSA=0;     // 预分频器分配控制位,=0分配给T0模块;=1分配给WDT。
    PS2=0;
    PS1=1;
    PS0=0;
    
    // PIE1
    PIE1=0x00;
    // PIR1
    PIR1=0x00;
    // PCON
    OSCF=1;      // 4MHZ

    // T1CON
    T1CKPS1=0;T1CKPS0=0;
    T1OSCEN=0;   // 0=RB6;1=RB7
    T1SYNC=0;    // 同步
    TMR1CS=1;    // 计数器 
    TMR1ON=1;    // 开启T1

    // INCON SET  
    TMR0=0x5A;
    PEIE=0;      // 关闭外设中断。
    INTE=0;
    RBIE=0;
    T0IE=1;      // 开启T0中断。
    GIE=1;       // 开启总中断。
}

void interrupt zd(void)   
{
    if(T0IE&&T0IF)        // 监测T0是否中断允许和中断标志位是否为1。T0中断函数。
        {
            run++; 
            TMR0=0x5A;
            T0IF=0;               // T0中断标志位清零,以便下一次中断。
            dog_con=1;

            if(run>200)           // 250ms
                {
                   if(fire_bit==0) RUN_FIRE=!RUN_FIRE; 
	               run=0;
	               times++;
                } 
	  	
            if(times>=4)          //  1s
                {
                   count=256*TMR1H+TMR1L;
                   TMR1H=0;TMR1L=0;
	               times=0;
                   RA3=!RA3;

                   if(RB0==1)
                       {	 		  
	                       if(count>29||count<2)  //大于30Hz或小于2Hz no fire
	                           {
                                   count=0;
	                               total_count=0;
	                               total_times=0;
                                   RB5=1;	   
                                   RB4=1;
                                   RA0=0;
	                             //  FIREH=0;FIREL=1;  
                                   fire_bit=0;
	                           }
                           else
	                           {
	                               total_count=total_count+count;
	                               total_times++;
	                               count=0;	   	   
	                           }

                           if(total_times>=9)       //10s
                               {
                                   total_times=0;              
                                   if(total_count<25)  //<=2.5Hz no fire
                                       {
                                           RB5=1;
                                           RB4=1;
                                           RA0=0;
                                         //  FIREH=0;FIREL=1;
                                           total_count=0;
                                           fire_bit=0;
                                       }
                                   else
                                       {
                                          
		                                 //  FIREH=1;FIREL=0;
                                           total_count=0;
                                           fire_bit=1;
                                           RUN_FIRE=0;
                                           RB5=0;RB4=0;RA0=1;
                                       }
                               }
	                   }
                    else                           //强光干扰
  	                   {	   
                           count=0;
	                       total_count=0;
	                       total_times=0;
                           
                           RB5=1;	
                           RB4=1; 
                           RA0=0;  
	                  //    FIREH=0;FIREL=1;
                           fire_bit=0;
	                   }	      
   
                }
        }   	        
}
      
void main()
{
     // A口设定
    CMCON=0x07;
    TRISA=0x20;   // A口输入、输出设定,o=对应口输出,1=对应口输入。
    PORTA=0x00; 
    TRISA0=0;TRISA2=0;TRISA3=0; 
    RA0=0;RA2=1;RA3=1;
     // B口设定
    TRISB=0x41;   
    PORTB=0x71;
    TRISB4=0;TRISB5=0;   
    RB5=1;RB3=1;RB4=1;
 
    init_pic16f627A();
   
    while(1)     
      {
          if(dog_con==1) {asm("clrwdt");dog_con=0;} 
      }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -