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闪烁
}
}
}
}
编译器用的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闪烁
}
}
}
}
相关文章推荐
- 嵌入式学习笔记(10)——51单片机之中断(定时器中断)
- STM32单片机学习(5) 定时器中断实验
- 学习笔记 从零开始学单片机(3) 定时器
- 奶爸业余单片机学习之:定时器使用方法——非中断,TF0(TF1)值软件重置法
- 单片机入门学习十四 STM32单片机学习十一 通用定时器二
- 单片机入门学习十三 STM32单片机学习十 通用定时器
- 单片机学习笔记--外部中断,定时器,串口中断
- 单片机学习札记9 定时器模拟PWM呼吸灯
- 奶爸业余单片机学习之:定时器以工作方式1运行时的初值的计算方法(51单片机)
- 单片机定时器学习汇总
- 奶爸业余单片机学习之:定时器中断的使用方法——进入中断TF0(TF1)值硬件自动重置
- 32单片机学习之定时器中断
- [转]学习PIC系列单片机的进来准没错!!(共18篇)
- 电子学习单片机资料光盘
- MCU学习5--利定时器产生中断
- 单片机C51学习心得_02
- C#多线程学习(五) 多线程的自动管理(定时器)
- 单片机学习和应用百问大全
- 学习单片机的8个步骤
- C#多线程学习(五) 多线程的自动管理(定时器)