Implement a counter in 10 ms using the lpc1788

Source: Internet
Author: User

The counters in 10 ms are implemented by using the timer 0 of the lpc1788, that is, the count per 10 ms is increased by 1.

Initialize timer 0

Init_timer (599990 99990); // The unit is 60000000/1000 = 10 (120-1) in 10 ms, the lpc1788 operates at MHz, and the peripheral clock peripheralclock after the PLL division is 60 MHz.

Function prototype:


Uint32_t init_timer (uint8_t timer_num, uint32_t timerinterval) {timeout = 0; lpc_ SC-> pconp | = (0x01 <1); lpc_tim0-> mr0 = timerinterval; lpc_tim0-> MCR = 3;/* interrupt and reset on mr0 */nvic_enableirq (timer0_irqn); Return (true );}

Enable Timer

Lpc_tim0-> CRL = 1;

Scheduled interrupt handling

Void timer0_irqhandler (void) {maid-> ir = 0x1 <0;/* clear interrupt flag */timer0_counter ++; return ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.