zoukankan      html  css  js  c++  java
  • LPC2138微控制器之定时器、看门狗、VIC实例

    本实例使用LPC2138微控制器,Keil+Proteus模拟实现。

    本实例使用定时器计数,当计数值到达时触发定时器中断,在定时器中断程序中喂狗,涉及模块包括晶振、PLL、定时器、看门狗和VIC。

    每次喂狗的同时,将P0.1 GPIO输出电平取反,外接一个LED灯作为Active信号灯。

    直接贴代码:

    main.c

    int main(void)
    {

    /* Fosc & CCLK is 60MHz */ /* FPCLK is 30MHz */ VPBDIV = 0x02; watch_dog_init(); timer0_init(); while(1); return 0; }

    watchdog.c

    #include <lpc213x.h>
    #include "watchdog.h"
    
    #define WDOG_INTREVAL_TIME 0x01FFFFFF
    
    void watch_dog_init(void)
    {
        /* Configure WDOG Timeout Interval */
        WDTC = WDOG_INTREVAL_TIME;
    
        /* Enable WDOG, reset the CPU while WDOG timeout */
        WDMOD = 0x3;
    }
    
    void watch_dog_feed()
    {
        /* reload WDOG by WDTC */
        WDFEED = 0xAA;
        WDFEED = 0x55;
    }

    timer.c

    #include <lpc213x.h>
    #include "timer.h"
    #include "watchdog.h"
    
    void timer0_isr(void) __irq
    {
        if ((VICIRQStatus & 0x10) && (T0IR & 0x01))
        {
            /* Clear MR0 Interrupt */
            T0IR = 0x01;
    
            /* ACT LED Blink */
            if (IOSET0 & 0x01)
            {
                IOCLR0 = 0x01;
            }
            else
            {
                IOSET0 = 0x01;
            }
    
            /* feed the WDOG */
            watch_dog_feed();
    
        }
    
    }
    
    void timer0_init(void)
    {
        /* ACT LED Initialization */
        IODIR0 |= 0x1;
        IOSET0 |= 0x1;
    
        /* Timer0 Timer Mode */
        T0CTCR = 0x00;
    
        /* Clear Timer0 Counter & Prescale Counter */
        T0TC = 0x00;
        T0PC = 0x00;
        
        /* Interrupt & Reset on MR0 */
        T0MCR = 0x03;
        T0MR0 = 0x5FF;
        T0PR = 0x5FF;
    
        /* Enable Timer0 */
        T0TCR = 0x01;
    
        /* Timer0 VIC */
        VICIntSelect = 0x00;
        VICVectCntl0 = 0x20 | 4;
        VICVectAddr0 = (unsigned int)timer0_isr;
    
        /* Enable Timer0 VIC */
        VICIntEnable |= 0x10;
    
    }
  • 相关阅读:
    Maven 简单配置gpg
    航天七三一医院护理电子病历的设计与实施
    境外聚合支付中,微信和支付宝的不同理念
    技术人员如何面试?
    跨境支付中的“灰色”产业链
    用ionic快速开发hybird App(已附源码,在下面+总结见解)
    离职有感(CVTE,创业公司,求职...)
    Objective C ARC 使用及原理
    iOS开发阶段技能总结
    ubuntu12.04 gitlab搭建
  • 原文地址:https://www.cnblogs.com/justin-y-lin/p/12340632.html
Copyright © 2011-2022 走看看