您的位置:首页 > 其它

PIC12F508单片机学习之一——定时器

2016-12-16 17:05 141 查看
PIC12F508单片机是没有中断的,定时器只能是查询方式。

编译器用的XC8,编译环境IDE用的是MPLAB X IDE。

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

//             __________________

//             VDD-| 1            8 |-VSS

//             GP5-| 2           27 |-GP0/DAT

//             GP4-| 3           26 |-GP1/CLK

//GP3/RMCLR--| 4           25 |-GP2

//             |________________|

//               12F508

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


//定时器模式试用

#include

#include


// #pragma config statements
should precede project file includes.

// Use project enums instead of #define for ON and OFF.


// CONFIG

#pragma config OSC = IntRC      // Oscillator Selection bits (internal RC oscillator)

#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled)

#pragma config CP = OFF         // Code Protection bit (Code protection off)

#pragma config MCLRE = OFF      // GP3/MCLR Pin Function Select bit (GP3/MCLR pin function is digital input, MCLR internally tied to VDD)


#define uchar unsigned char

#define uint unsigned int

uchar  count;

//uchar  GP3_F;

void Init()

{

   TRIS=~0x3F;  //GP3输入,其它输出

  //GPWU = 0;//引脚中断唤醒使能;引脚中断要引起复位的,可以查询复位原因,这样就可以知道是谁的中断了

  //GPPU=0;/弱上拉使能

     OPTION=0xC5;//分频器给定时器 64 4MHz        x=257-tJ/4F

     TMR0=0x63;   //10ms x=257-tJ/4F

}

 void  main()

{  

 Init();  

 while(1)

      if(TMR0==0xFF)

      {

       TMR0=0x63;   //

       if(++count==50)//1s

        {

         count=0;

         GP2=~GP2;//LED闪烁

        }

       }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: