Timer query mode timer initialization:
1. Set the timer frequency division number, which is (x+1) frequency division
2. Match channel X interrupt and reset TxTC
3. Comparison value (1S timing value)
4. Start and reset TxTC
Such as:
T1PR = 99; // Set timer 0 to divide by 100, get 110592Hz
T1MCR = 0x03; // match channel 0 match interrupt and reset T0TC
T1MR0 = 110592/2; // Comparison value (1S timing value)
T1TCR = 0x03; // Start and reset T0TC
T1TCR = 0x01;
After studying for a long time, the timer of LPC210X, the query mode and timing is very simple as above, but the interrupt mode requires a lot of registers to operate, which is too troublesome and has always been confused. I finally figured out my thoughts, and now paste a section of routine memo.
#include "intrinsics.h"
#include "stdio.h"
#include "iolpc2103.h"
// OSC ï¼»Hzï¼½
#define FOSC 11059200UL
// Core clk ï¼»Hzï¼½
#define FCCLK FOSC
// Per clk ï¼»Hzï¼½
#define PCCLK (FOSC/4)
// TImer TIck per second
#define TICK_PER_SEC (4UL)
#define TIM_PER_S (Val) (PCCLK/Val)
#define MAX_TICK_PER TIM_PER_S (20)
#define MIN_TICK_PER TIM_PER_S (5)
// Timer Delta period [ms]
#define DELTA_PER (50UL)
#define TIM_DPER ((PCCLK*DELTA_PER)/1000UL)
#define LED_MASK 1《》18
/************************************************* ************************
* Function name: irq_handler
* Entry parameters: none
* Return parameter: none
* Description: IRQ handler
************************************************** ***********************/
#pragma vector=IRQV
__irq __arm void irq_handler (void)
{
void (*interrupt_function) ();
unsigned int vector;
vector = VICVectAddr; //Get interrupt vector
interrupt_function = (void(*)()) vector;
if(interrupt_function!= NULL)
{
interrupt_function(); //Call the function pointed to by the interrupt
}
else
{
VICVectAddr = 0; //Clear the interrupt in VIC
}
}
/************************************************* ************************
* Function name: Timer0Handler
* Entry parameters: None
* Return parameters: None
* Description: Timer 0 handler
************************************************** ***********************/
void Timer0Handler (void)
{
// clear interrupt flag
T0IR_bit.MR0INT = 1;
// Change patern
if ((IOSET & LED_MASK) == 0)
IOSET = LED_MASK; //Turn off the LED
else
IOCLR = LED_MASK;
//pNextPattern = pNextPattern-》pNextPattern; //Adjust the current linked list
VICVectAddr = 0;
}
/************************************************* ************************
* Function name: VicInit
* Entry parameters: None
* Return parameters: None
* Description: Init VIC module
************************************************** ***********************/
void VicInit (void)
{
// Assign all interrupt chanels to IRQ
VICIntSelect = 0;
// Diasable all interrupts
VICIntEnClear = 0xFFFFFFFF;
// Clear all software interrutps
VICSoftIntClear = 0xFFFFFFFF;
// VIC registers can be accessed in User or privileged mode
VICProtection = 0;
// Clear interrupt
VICVectAddr = 0;
// Clear address of the Interrupt Service routine (ISR) for non-vectored IRQs.
VICDefVectAddr = 0;
// Clear address of the Interrupt Service routine (ISR) for vectored IRQs.
VICVectAddr0 = VICVectAddr1 = VICVectAddr2 = VICVectAddr3 =\
VICVectAddr4 = VICVectAddr5 = VICVectAddr6 = VICVectAddr7 =\
VICVectAddr8 = VICVectAddr9 = VICVectAddr10 = VICVectAddr11 =\
VICVectAddr12 = VICVectAddr13 = VICVectAddr14 = VICVectAddr15 = 0;
// Disable all vectored IRQ slots
VICVectCntl0 = VICVectCntl1 = VICVectCntl2 = VICVectCntl3 =\
VICVectCntl4 = VICVectCntl5 = VICVectCntl6 = VICVectCntl7 =\
VICVectCntl8 = VICVectCntl9 = VICVectCntl10 = VICVectCntl11 =\
VICVectCntl12 = VICVectCntl13 = VICVectCntl14 = VICVectCntl15 = 0;
}
/************************************************* ************************
* Function name: Init_timer0
* Entry parameters: None
* Return parameters: None
* Description: Init tiner0
************************************************** ***********************/
void Init_timer0 (void)
{
/*
// Init timer
// Reset and stop timer0
T0TCR = 2;
// Set timer counters mode-clock by PCLK
T0CTCR = 0;
// Set timer prescaler
T0PR = 0;
// Set timer period
T0MR0 = PCCLK/TICK_PER_SEC;
// Set mack action-interrupt by MACH0 enable, reset counter
T0MCR = 3;
// No external action
T0EMR = 0;
*/
T0TCR = 2;
T0CTCR = 0;
T0PR = 0;
T0MR0 = PCCLK/TICK_PER_SEC;
T0MCR = 3;
T0EMR = 0;
// Assign to IRQ
VICIntSelect_bit.TIMER0 = 0;
// Set interrupt slots
VICVectAddr0 = (unsigned int) Timer0Handler;
VICVectCntl0_bit.NUMBER = VIC_TIMER0;
VICVectCntl0_bit.ENABLED = 1;
// Timer 0 interrupt enable
VICIntEnable_bit.TIMER0 = 1;
// Enable timer0
T0TCR = 1;
}
/************************************************* ************************
* Function name: Init_Gpio
* Entry parameters: None
* Return parameters: None
* Description: Init GPIO
************************************************** ***********************/
void Init_Gpio(void)
{
// Init GPIO
PINSEL0 = PINSEL1 = 0;
// Disable fast IO
SCS_bit.GPIO0M = 0;
// Set pins connect to LEDs as outputs
IODIR = LED_MASK;
// All LEDs off
IOCLR = LED_MASK;
}
/************************************************* ************************
* Function name: Init_pll
* Entry parameters: None
* Return parameters: None
* Description: Init PLL
************************************************** ***********************/
void Init_pll(void)
{
// Disable PLL
PLLCON = 0;
// Write Feed
PLLFEED = 0xAA;
PLLFEED = 0x55;
// Set periphery divider /4
APBDIV_bit.APBDIV = 0;
// Set MAM fully enable
MAMCR_bit.MODECTRL = 0;
MAMTIM_bit.CYCLES = 3;
MAMCR_bit.MODECTRL = 2;
}
/************************************************* ************************
* Function name: main
* Entry parameters: None
* Return parameters: None
* Description: main
************************************************** ***********************/
void main (void)
{
Init_pll();
// Memory map init flash memory is maped on 0 address
#ifdef FLASH
MEMMAP_bit.MAP = 1;
#else
MEMMAP_bit.MAP = 2;
#endif
__disable_interrupt();
VicInit();
Init_Gpio();
Init_timer0();
__enable_interrupt();
The through-wall terminals can be installed side by side on panels with thicknesses ranging from 1mm to 10mm, and can automatically compensate and adjust the thickness of the panel to form a terminal block with any number of poles. In addition, isolation plates can be used to increase air gaps and creepage distances.
Through-Wall Terminal,Through Wall Terminal Block,Through-Wall Terminal Extender,Through-The-Wall Terminal Block
Sichuan Xinlian electronic science and technology Company , https://www.sztmlchs.com