The timer is relatively simple, and there is nothing much to say.
Keywords:PIC
Reference address:PIC16-bit MCU CAN (7) Timer
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
}
Previous article:PIC16-bit microcontroller CAN (8) watchdog
Next article:PIC16-bit microcontroller CAN (6) external AD
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Guess you like
- [Raspberry Pi Pico Review] Power-on initial test
- Free application: Qinheng RISC-V core BLE 5.3 wireless MCU CH582
- Electronic design from scratch
- Is this a filter circuit?
- Rohde & Schwarz JD flagship store is officially launched!
- How difficult is it for Chang'e 5 to "skip in space" and re-enter the atmosphere?
- SHDSL Wired Analog Front-end Design
- Application design of lighting terminal system based on GPRS module and Zigbee network
- The Latest Design in Hearing Aids --- Bluetooth Communication and Embedded
- MT6580 for beginners