zoukankan      html  css  js  c++  java
  • xs128 双定时器PIT0和PIT1

        /***************************************************************** 
    ** 函数说明:xs128 双定时器PIT0和PIT1
    ** 版 本:V1.00
    ** 修 改:庞辉 芜湖联大飞思卡尔工作室
    ** 修改日期:2011年09月19日
    **
    ** 说 明:PLL倍频到80Mhz,PB0口灯1s闪烁,PB1口灯2s闪烁
    **
    ** 版本更新:详见readme.txt
    **
    ******************************************************************
    **注意: LED1灯 PORTB0
    ** LED2灯 PORTB1
    *****************************************************************
    */

    #include <hidef.h> /* common defines and macros */
    #include "derivative.h" /* derivative-specific definitions */

    /***********************************************************
    ** 名 称:void PLL_Init(void)
    ** 功 能:PLL锁相环模块初始化
    ** 入口参数:无
    ** 出口参数:无
    ** 使用说明:80MHz
    ***********************************************************
    */
    void PLL_Init(void)
    {
    CLKSEL = 0X00;

    PLLCTL_PLLON = 1;


    SYNR =0xc0 | 0x09; //80M
    REFDV=0x80 | 0x01;
    //SYNR =0xc0 | 0x04; //40M
    //REFDV=0x80 | 0x01;

    POSTDIV = 0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz;
    //BUS CLOCK=80M
    _asm(nop); //空操作,进行简单的延时,等待锁相环的相应
    _asm(nop);

    while(!(CRGFLG_LOCK==1))
    {
    _asm(nop);
    }

    CLKSEL_PLLSEL = 1;
    }

    /***********************************************************
    ** 名 称:void PIT_Init(void)
    ** 功 能:PIT定时模块初始化
    ** 入口参数:无
    ** 出口参数:无
    ** 使用说明:PIT0 1ms定时
    ** PIT1 8ms定时
    ***********************************************************
    */
    void PIT_Init(void)
    {
    PITCFLMT_PITE=0; //关闭PIT

    //微定时器的装载寄存器
    PITMTLD0= 80-1;//8位定时器初值设定。80分频,在80MHzBusClock下,为1MHz,即1us
    //PITMTLD1= 160-1;//8位定时器初值设定,160分频,在16MHz的总线时钟频率下,为0.1MHz,即10us

    //定时器的装载寄存器
    PITLD0 = 1000 - 1 ;//1ms
    PITLD1 = 8000 - 1 ;//定时8ms

    PITCE_PCE0=1;//使能通道0
    PITCE_PCE1=1;//使能通道1

    PITMUX_PMUX0=0;//0:相应16位定时器与微时基0连接
    //PITMUX_PMUX1=1;//1:相应16位定时器与微时基1连接

    PITINTE_PINTE0=1;//开通PIT0定时器的溢出中断
    PITINTE_PINTE1=1;//开通PIT1定时器的溢出中断

    PITCFLMT_PITE=1; //使能PIT
    }

    /***********************************************************
    ** 名 称:void main(void)
    ** 功 能:主函数
    ** 入口参数:无
    ** 出口参数:无
    ** 使用说明:无
    *********************************************************
    */
    void main(void)
    {
    DDRB = 0xff;
    PORTB = 0xff;

    EnableInterrupts;
    PLL_Init();
    PIT_Init();

    for(;;)
    {

    }

    }


    int i = 0, j = 0;

    #pragma CODE_SEG __NEAR_SEG NON_BANKED //指示该程序在不分页区

    //定时器0
    void interrupt 66 PIT0(void)
    {
    DisableInterrupts;

    //清中断标志位
    PITTF = 0x01;
    i++;

    //1s
    if(i == 1000)
    {
    PORTB_PB0 = ~PORTB_PB0;
    i = 0;
    }


    EnableInterrupts;
    }


    //定时器1
    void interrupt 67 PIT1(void)
    {
    DisableInterrupts;

    //清中断标志位
    PITTF = 0x02;
    j++;

    //2s
    if(j == 250)
    {
    PORTB_PB1 = ~PORTB_PB1;
    j = 0;
    }

    EnableInterrupts;
    }

    #pragma CODE_SEG DEFAULT



  • 相关阅读:
    Atitit.Java exe bat  作为windows系统服务程序运行
    Atitit. Object-c语言 的新的特性  attilax总结
    Atitit. Object-c语言 的新的特性  attilax总结
    Atitit。Time base gc 垃圾 资源 收集的原理与设计
    Atitit。Time base gc 垃圾 资源 收集的原理与设计
    Atitit.go语言golang语言的新的特性  attilax总结
    Atitit.go语言golang语言的新的特性  attilax总结
    Atitit.pdf 预览 转换html attilax总结
    Atitit.pdf 预览 转换html attilax总结
    Atitit.office word  excel  ppt pdf 的web在线预览方案与html转换方案 attilax 总结
  • 原文地址:https://www.cnblogs.com/pang123hui/p/2309853.html
Copyright © 2011-2022 走看看