您的位置 首页 软件

PIC16F877A TIMER1计数操作

/**********************Title:PIC16F877ATIMER1计数操作Author:hnrainDate:2010-12-28使用前置分频器T1CKPS1T1CKPS100

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

Title:PIC16F877A TIMER1计数操作
Author:hnrain
Date:2010-12-28

运用前置分频器
T1CKPS1 T1CKPS1
0 0 1 分频 TMR1时钟为晶振时钟/(4*1)
0 1 2 分频 TMR1时钟为晶振时钟/(4*2)
1 0 4 分频 TMR1时钟为晶振时钟/(4*4)
1 1 8 分频 TMR1时钟为晶振时钟/(4*8)
TMR1是16位宽度的TMR1由2个8位的可读写的寄存器TMR1H和TMR1L组成。

TMR1有专门的启停操控位TMR1ON,经过软件能够恣意发动或暂停TMR1计数功用。

T1CON:TIMER1 CONTROL REGISTER

bit7-6 unimplemented :Read as ‘0’

bit5-4 T1CKPS1:T1CKPS0:Timer1 input Clock Prescale Select bits

11=1:8 prescale value

10=1:4 prescale value

01=1:2 prescale value

00=1:1 prescale value

bit3 T1OSCEN:Timer1 Oscillator Enable Control bit

1 = Oscillator is enable

0 = Oscillator is shut-off

bit2 T1SYNC:Timer1 External Clock Input Synchronization Control bit

when TMR1CS = 1

1= Do not synchronize external clock input

0= Synchronize external clock input

when TMR1CS = 0

This bit is ignored .Timer1 uses the internal clock when TMR1CS = 0.

bit1 TMR1CS:Timer1 Clock Source Select bit

1 = External clock from pin RC0/T1OSO/T1CKI

0 = Internal clock

bit0 TMR1ON:Timer1 on bit

1 = enables timer1

0 = stops timer1
阐明:作用在TMR1的计数状况,计数信号从RC0/T1CKI输入,
当来一个上升沿时,收集到一个有用的信号,计数到TMR1L,TMR1H中。
当计满时就会发生中止信号。
***********************/
#include #include “../head/config.h”

__CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);

void main(void)
{
T1CKPS0 = 0;
T1CKPS1 = 0;//不分频

TMR1L = (65536 – 1)%256;//TMR1L,TMR1H赋初值
TMR1H = (65536 – 1)/256;
T1SYNC = 1;//TMR1异步计数器
TMR1CS = 1;
GIE = 1;//翻开大局中止
PEIE = 1;//翻开外部中止
TMR1IE = 1;//TMR1中止翻开
TMR1ON = 1;
PORTD = 0x00;
TRISD = 0x00;
while(1){}
}

void interrupt ISR(void)
{
TMR1L = (65536 – 1)%256;//从头赋值
TMR1H = (65536 – 1)/256;
if(TMR1IE && TMR1IF)
{
TMR1IF = 0;
PORTD = ~PORTD;
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/ruanjian/274884.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部