基本信息
源码名称:PIC16F887 基础实例
源码大小:0.07M
文件格式:.zip
开发语言:C/C++
更新时间:2022-02-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
PIC16F887 基础实例

/*********************************************************************************************************
** Function name:           static void interrupt isr(void)
** Descriptions:            中断函数处理
** input parameters:        none
** output parameters:       none
** Returned value:          none
*********************************************************************************************************/
static void interrupt isr(void)
{    
    // 定时器1中断执行函数
    if(PIE1bits.TMR1IE & PIR1bits.TMR1IF)   // 判断是否满足定时中断
    {    
      PIR1bits.TMR1IF = 0;    // TMR1 寄存器溢出(必须由软件清零)   
      TMR1 = 0xf63c;         // 初值 = 65536 -(fose/4/分频值)*定时时间  预设定时为10ms
      if ( time_flag == 1) 
      { 
            time_count ;
           if(time_count>=100){time_count = 50;}
      }
      else {time_count = 0;}
   
     }
}
/*********************************************************************************************************
** Function name:           main
** Descriptions:            主函数
** input parameters:        none
** output parameters:       none
** Returned value:          none
*********************************************************************************************************/
void main (void)
{
// 时钟配置    
    OSCCONbits.IRCF = 0x06; // 默认4M主频(内部时钟)
    OSCCONbits.OSTS = 0x00; // 器件依靠内部振荡器 (HFINTOSC 或 LFINTOSC)运行
    OSCCONbits.SCS = 0x01;  // 内部振荡器用作系统时钟
    NOP(); 
    
 //看门狗配置  
    WDTCONbits.SWDTEN = 1;   // 使能看门狗
    WDTCONbits.WDTPS = 0x0B; // 65536/512 *17 =2.176S
    NOP(); 
    
 // 定时器1配置初始化   
    T1CONbits.T1CKPS0 = 0; // 10 = 1:4 预分频比
    T1CONbits.T1CKPS1 = 1;
    T1CONbits.TMR1CS = 0;  // 内部时钟源(FOSC/4)
    TMR1 = 0xf63c;         // 初值 = 65536 -(fose/4/分频值)*定时时间  预设定时为10ms  
    T1CONbits.TMR1ON = 1;  // 使能Timer1
    
    PIR1bits.TMR1IF = 0;   // TMR1 寄存器溢出(必须由软件清零)
    PIE1bits.TMR1IE =1;    // 允许Timer1 溢出中断
    NOP(); 
         
 // 全局中断使能
    INTCONbits.PEIE = 1;   // Enables all unmasked peripheral interrupts   
    INTCONbits.GIE = 1;    //  Enables all unmasked interrupts  
    NOP(); NOP(); NOP();    
       
 // 初始化PORTB端口  
     IOCB = 0x00;          // 初始化禁止PORTB 电平变化中断
     WPUB = 0x00;          // 初始化禁止PORTB 弱上拉
    TRISB = 0X00;          // PORTB 初始化为输出端口 (FET CONTROL) 
    PORTB = 0X00;          // 初始化PORTB,默认输出低电平   
   ANSELH = 0X00;          // 初始化成I/O 端口
   
 // 初始化PORTA端口
 //   TRISA = 0X00;
 //   PORTA = 0X00;
    TRISA0 =0x01; // 设置RA0 是输入
    ANSEL = 0x00; // 初始化成I/O口
    
     EN_OFF;
   time_count = 0x00;      // 初始化定时计数器 
   time_flag = 0;          // 按键按下计数器flag
   time_over = 0;          // 超时flag
    while(1)
    {
        CLRWDT();           // 复位看门狗
        if(RA0 == 0)        // 有按键按下
         {
              __delay_ms(25);
              time_flag = 1;    // 开始计数标识
              
              if(time_count>= 50) // 计数大于500ms 认为已经按下
              {                
                 if(time_over == 0) // 每次必须有松开才开启
                 {  
                   time_over = 1;
                    EN_ON;
                    __delay_ms(27);  
                  }                 
               }
              if( time_over == 1)EN_OFF; // 如果一直按着不开启
        }else {time_flag = 0;EN_OFF; time_over = 0;} // 无按键按下,关闭开关
          
    }
}


.
├── PIC16F887 基础实例
│   ├── Makefile
│   ├── User
│   │   ├── config.h
│   │   └── main.c
│   ├── build
│   │   └── default
│   │       └── production
│   │           └── User
│   │               ├── main.p1
│   │               ├── main.p1.d
│   │               └── main.pre
│   ├── code
│   ├── debug
│   │   └── default
│   ├── dist
│   │   └── default
│   │       └── production
│   │           ├── Burn_In_load.X.production.cmf
│   │           ├── Burn_In_load.X.production.elf
│   │           ├── Burn_In_load.X.production.hex
│   │           ├── Burn_In_load.X.production.hxl
│   │           ├── Burn_In_load.X.production.lst
│   │           ├── Burn_In_load.X.production.map
│   │           ├── Burn_In_load.X.production.mum
│   │           ├── Burn_In_load.X.production.obj
│   │           ├── Burn_In_load.X.production.rlf
│   │           ├── Burn_In_load.X.production.sdb
│   │           ├── Burn_In_load.X.production.sym
│   │           └── memoryfile.xml
│   └── nbproject
│       ├── Makefile-default.mk
│       ├── Makefile-genesis.properties
│       ├── Makefile-impl.mk
│       ├── Makefile-local-default.mk
│       ├── Makefile-variables.mk
│       ├── Package-default.bash
│       ├── configurations.xml
│       ├── private
│       │   ├── configurations.xml
│       │   └── private.xml
│       └── project.xml
└── 好例子网_PIC16F887 基础实例.zip

14 directories, 29 files