PIC16-bit MCU CAN (7) Timer

Publisher:ZenMaster123Latest update time:2016-08-28 Source: eefocusKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The timer is relatively simple, and there is nothing much to say.
Each timer module is a 16-bit timer/counter consisting of the following readable/writable registers:
? TMRx: 16-bit timer count register
? PRx: 16-bit timer period register associated with the timer
? TxCON: 16-bit timer control register associated with the timer
have to be aware of is:
1: The timer is 16 bits, and can also be configured as 32 bits. Please refer to the document for details. A 16-bit timer is used here.
2: PRx: 16-bit timer period register associated with the timer. That is, an interrupt is generated when the value of TMRx is equal to the value of PRx. 】
 
Let’s look at the program:
/******************************************************************
Initialize Time1 to timer mode
parameter:
none
******************************************************************/
void Time1Init(void)
{
T1CONbits.TON = 0; // Disable Timer
T1CONbits.TCS = 0; // Select internal instruction cycle clock 
T1CONbits.TGATE = 0; // Disable Gated Timer mode
T1CONbits.TCKPS = 0b11; // Select 1:256 Prescaler
TMR1 = 0x00;  // Clear timer register
PR1 =46875; // Load the period value, which is equivalent to generating an interrupt once per second
T1CONbits.TON = 1; // Enable Timer
}
The interrupt handling function is
/******************************************************************
Timer 1 interrupts once every 1s and sends CAN data once
parameter:
none
******************************************************************/
void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
{
IFS0bits.T1IF = 0;  //Clear Timer1 interrupt flag
Ecan1_WriteMessage(AD_Data); //CAN sends data
}

Keywords:PIC Reference address:PIC16-bit MCU CAN (7) Timer

Previous article:PIC16-bit microcontroller CAN (8) watchdog
Next article:PIC16-bit microcontroller CAN (6) external AD

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号