欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

專注電子技術學習與研究
當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

PIC12F508單片機學習之一—定時器

作者:聽雨心情   來源:聽雨心情   點擊數:  更新時間:2014年06月20日   【字體:

 

 
 
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=0xF5;//分頻器給定時器 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閃爍
        }
       }
    }
}
 
關閉窗口