亿加合和智能车制作

标题: MC9S12DG128系列例程--RTI [打印本页]

作者: chiusir    时间: 2008-12-2 03:24
标题: MC9S12DG128系列例程--RTI
MC9S12DG128系列例程--RTI

/**************************************************************************************
龙丘MC9S12(DG128)多功能开发板V4.0
Designed by Chiu Sir
E-mail:chiusir@163.com
软件版本:V1.1
最后更新:2008年12月01日
相关信息参考下列地址:
博客:  http://longqiu.21ic.org
淘宝店:http://shop36265907.taobao.com
------------------------------------
Code Warrior 4.6
Target : MC9S12DG128B
Crystal: 16.000Mhz
busclock:16.000MHz
pllclock:32.000MHz
目录路径:F:\IVTech\
============================================
演示程序使用说明:
1.实时时钟的演示:
2.毫秒级计时输出;
3.串口输出速率:9600bps.
4.中断的使用。
*****************************************************************************************/

#i nclude <hidef.h>           /* common defines and macros */
#i nclude <mc9s12dg128.h>     /* derivative information */
#i nclude <stdio.h>
#i nclude "LQprintp.h"
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"   
typedef unsigned char U8;
typedef unsigned int  U16;
typedef unsigned long U32;
typedef signed char   S8;
typedef signed int    S16;
volatile U32 u32_time_cnt=0;     
//====================中断函数==================================   
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 7 RTI_ISR(void) {   // 32.75ms timer overflow   
  ++u32_time_cnt;         
  PORTB_BIT2=~PORTB_BIT2;
  CRGFLG|=0X80;//Write 1 to clear RTIF bit   
}
/*******************************************************************************
*** 函 数 名: void DLY_ms(U16 x)
*** 功能描述: 毫秒级延时;
*** 全局变量: NO !
*** 输  入: U16 x !
*** 输  出: NO !  
*** 修 改 人:           日期:2007-11-28
*** 函数说明:
******************************************************************************/
void DLY_ms(int ms)  //x取值1~255;
{
  int ii,jj;
   if (ms<1) ms=1;
   for(ii=0;ii<ms;ii++)
     for(jj=0;jj<2770;jj++);    //32MHz--1ms
     //for(jj=0;jj<4006;jj++);  //48MHz--1ms
     //for(jj=0;jj<5341;jj++);  //64MHz--1ms  
}
//-----------------------------------------------------
static void Port_Init(void)
{  
    DDRA = 0xff;  
    PORTA= 0x00;         
    DDRB = 0xff;  //LED  PTB0--7,
    PORTB= 0xff;  //LEDs on  
}
//-----------------------------------------------------
static void SCI_Init(void)
{
    SCI0CR2=0x2c; //enable Receive Full Interrupt,RX enable,Tx enable
    SCI0BDH=0x00; //busclk  8MHz,19200bps,SCI0BDL=0x1a
    SCI0BDL=0x68; //SCI0BDL=busclk/(16*SCI0BDL)
                  //busclk  8MHz, 9600bps,SCI0BDL=0x34
                  //busclk 16MHz, 9600bps,SCI0BDL=0x68
                  //busclk 24MHz, 9600bps,SCI0BDL=0x9C
}                 //busclk 32MHz, 9600bps,SCI0BDL=0xD0
// setup of the RTI interrupt frequency     
static void RTI_Init(void)
{   
    RTICTL=0x77;   //8x2^16 =>32,75ms,30.5175Hz                     
    //CRGINT=0X80;   //enable RTI Interrupt
    CRGINT=0X80;   //enable RTI Interrupt
}
// PLL初始化子程序   BUS Clock=16M
void setbusclock(void)
{   
    CLKSEL=0X00;    //disengage PLL to system
    PLLCTL_PLLON=1;   //turn on PLL
    SYNR=1;         
    REFDV=1;          //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
    _asm(nop);          //BUS CLOCK=16M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));   //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;          //engage PLL to system;
}
//-----------------------------------------------------
#pragma CODE_SEG DEFAULT
void Init_Dev(void)
{
    setbusclock();
    Port_Init();
    SCI_Init();      
    RTI_Init();
}
//====================main()==================================
#pragma CODE_SEG DEFAULT     
void main(void)   
{
   
  S8  txtbuf[66]="";
  U8  u8_mintes=0;
  U16 u16_sec=0,u16_ms=0;

   
  Init_Dev();  
  PORTB=0x00;
  putstr("\nLongQiu s.&t.\n");   
  DLY_ms(1000);     
  PORTB=0xFF;
  EnableInterrupts;   
  for(;;)
  {
//----------时钟计时器---------------------------------
    u16_sec=u32_time_cnt*131/4;//理论值为32.75ms,时间计算部分  
    u16_ms=u16_sec%1000;        
    u16_sec=u16_sec/1000;   
    sprintf(txtbuf,"LONGQIU--time elapsed: %d:%02ds-%03dms ",u8_mintes,u16_sec,u16_ms);     
    printp("\n\t%s",txtbuf);           
    if(u16_sec>58)
    {
      u8_mintes++;
      u32_time_cnt=0;
    }
//--------------------------------------------------------   
    PORTB_BIT0=~PORTB_BIT0;        
  }//for(;;)
} //main
下面是完整工程,需要的请点击下载:demoRTI.rar
看帖不回是不道德的!

作者: kknhg14    时间: 2008-12-2 04:29
标题: Re:MC9S12DG128系列例程--RTI
谢谢
作者: whut_wj    时间: 2008-12-2 04:51
标题: Re:MC9S12DG128系列例程--RTI
<>好样的.小顶之.</P>
作者: wxyz0905    时间: 2008-12-7 17:58
标题: Re:MC9S12DG128系列例程--RTI
<>GOOD,</P>
作者: yudongx    时间: 2009-1-17 01:02
标题: Re:MC9S12DG128系列例程--RTI
非常好,谢谢啦!
作者: nilelixp    时间: 2009-2-16 19:05
辛苦
作者: redfox302    时间: 2009-2-20 10:00
very good,good!
作者: wanghuaiyu    时间: 2009-2-20 10:52
ok
作者: Terminator    时间: 2009-2-20 15:56
本帖最后由 Terminator 于 2009-2-20 15:59 编辑

非常好,非常实用, 谢谢
作者: kx20060817    时间: 2009-2-22 20:57
好人
作者: wang-kai-6666    时间: 2009-2-24 21:47
xie xie le
作者: zhangsq32@126    时间: 2009-2-24 22:17
谢谢!!!!!1
作者: big_student    时间: 2009-3-14 15:22
支持!!!!
作者: 飞思卡尔    时间: 2009-3-15 21:41
谢谢楼主!
作者: gjw1373168    时间: 2009-3-25 20:33
:victory:
作者: aijiujiu    时间: 2009-3-29 15:31
ok,顶一个
作者: bingo6234    时间: 2009-4-1 21:58
可以参考一下,感谢
作者: 786892880    时间: 2009-4-5 15:32
非常好
作者: narcsx2008    时间: 2009-4-6 09:55
hao 1~!
作者: rj0725    时间: 2009-4-7 17:26
good
作者: xbsf-写轮眼    时间: 2009-4-7 21:07
thank you so much!
作者: pengzhen_lin    时间: 2009-4-8 20:21
好,多谢
作者: yyjz    时间: 2009-4-9 17:25
ok
作者: yyjz    时间: 2009-4-9 17:25
ok
作者: zhaodong584    时间: 2009-4-10 19:07
辛苦了,谢谢
作者: huahai    时间: 2009-4-10 19:45
谢谢
作者: huahai    时间: 2009-4-10 19:45
谢谢
作者: yangyong1011    时间: 2009-4-17 17:52
谢谢楼主
作者: gnimye    时间: 2009-4-30 20:24
thanks
作者: chuyanliang    时间: 2009-5-9 00:02
xiexie!!!!!!!!!
作者: teng115578215    时间: 2009-5-12 20:17
我们要做有道德的人!!!!!!!!!!!
作者: zxzxy1988    时间: 2009-5-14 14:29
呵呵,谢谢
作者: 刚刚    时间: 2009-5-16 14:31

作者: niujingtao    时间: 2009-5-18 20:06
顶!
作者: abc43412119    时间: 2009-5-25 12:23
谢谢
作者: rong    时间: 2009-6-6 18:51
谢了!
作者: hehaomin    时间: 2009-6-8 18:27
的确很有用,谢啦!
作者: zjcc    时间: 2009-6-19 14:37
:dizzy
作者: zhoujie614    时间: 2009-7-4 15:03
非常感谢
作者: flyawayboy    时间: 2009-7-22 08:20
牛B
作者: flyawayboy    时间: 2009-7-22 08:23
顶啊
作者: sxz_101    时间: 2009-8-6 16:00
好东西,谢谢
作者: dong065235    时间: 2009-8-30 21:06
那我再顶一个
作者: khao    时间: 2009-8-31 20:29
谢谢了
作者: wshsw    时间: 2009-9-8 18:55
xiexie
作者: 黑马    时间: 2009-10-13 10:38
很不错
作者: wangguiqing2008    时间: 2009-10-15 10:18

作者: j01307    时间: 2009-10-26 17:36
谢谢啦
作者: dxldxl1987    时间: 2009-10-26 20:40
学习的好资料,谢谢,谢谢
作者: jothychow    时间: 2009-10-29 10:58
非常感谢
作者: hclfo    时间: 2009-11-8 15:32

作者: chiusir    时间: 2009-12-3 23:45
举手之劳,不言谢!
作者: leaf19881122    时间: 2009-12-5 09:49
ding``
作者: VIP.Choi    时间: 2009-12-5 10:27
BUMP UP!!!
作者: 小雨1111    时间: 2010-1-6 12:48
好的
作者: 山孩子    时间: 2010-1-12 13:12
非常好,谢谢啦!
作者: alex87    时间: 2010-3-4 19:18
辛苦咯 顶
作者: fantasy1722    时间: 2011-3-19 20:32
GOOD!!
作者: LEUNG    时间: 2011-4-9 12:05

作者: 在陌上    时间: 2011-4-9 13:02
不错
作者: zhangshaoye    时间: 2011-4-15 08:59
看看
作者: 云端暮雪    时间: 2011-11-29 22:26
好样的。。。
作者: mc9s12dg单片机    时间: 2011-12-28 12:37
谢谢,拉
作者: guoshunkai521    时间: 2012-2-19 19:46
来转转

作者: TAOBINGJUN    时间: 2012-2-24 23:30
Thanks
作者: keyi011    时间: 2012-2-27 16:30

作者: 水龙吟    时间: 2012-4-9 21:01
非常感谢

作者: 1637557819    时间: 2012-4-13 23:50
楼主 好奸诈啊   
作者: verm    时间: 2012-5-19 08:54

作者: 月嘉愚生    时间: 2012-5-19 15:26
顶你
作者: friendlyboy    时间: 2012-8-11 21:55
非常感谢,帮大忙了
作者: 774960834    时间: 2012-8-14 17:38
好人呐 贡献一直不够用 就怕要贡献的资料.....
作者: wayne_7711    时间: 2012-9-4 15:07
不错!
作者: 雨后青山    时间: 2012-12-8 22:37
看了,顶一个
作者: camphor    时间: 2013-1-16 21:49
谢谢
作者: 王彦杰    时间: 2013-1-21 22:10

作者: メ螢火蟲de淚    时间: 2013-1-30 00:13

作者: dlyt03    时间: 2013-2-1 16:29
谢谢
作者: yyyzrxh    时间: 2013-2-2 21:21
感谢楼主
作者: dlyt03    时间: 2013-2-12 22:01
谢谢
作者: zhangjia    时间: 2013-2-18 15:16

作者: 落叶0805    时间: 2013-2-20 20:41
狂顶!


作者: dlyt03    时间: 2013-2-21 22:02
学习!!!!
作者: 王彦杰    时间: 2013-3-2 22:24

作者: zhangguanghui    时间: 2013-3-6 09:06
果断顶起啊
作者: ≯且行且颠≮    时间: 2013-3-7 09:20

作者: 飞扬or落寞    时间: 2013-3-17 15:33

作者: 胖子小森森    时间: 2013-3-22 19:59
学习了
作者: 平心~~    时间: 2013-8-12 09:29

作者: 凌风傲雪    时间: 2014-2-22 20:30
谢谢
作者: 小猛士    时间: 2014-2-25 23:07
好啊。
作者: coder~dreamer    时间: 2014-4-8 09:40
:):):):):):):)
作者: 六安飞雨    时间: 2015-1-27 15:17
赞一个、、、、、、、、、、




欢迎光临 亿加合和智能车制作 (http://www.znczz.com/) Powered by Discuz! X3.2