打印

用QY4内部振荡器做时钟时定时问题

[复制链接]
1295|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
谭可|  楼主 | 2007-5-21 18:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用QY4时,采用了内部振荡器。做定时功能的时候发现误差很大,超过了20%。各位大侠帮我看看我哪个地方没有设置好。今天才用Freescale的单片机。相关程序如下:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

typedef    unsigned char   UINT8;
typedef int                    INT16;
typedef unsigned int      UINT16;
typedef unsigned long   UINT32;
typedef long                 INT32;


void Init_Device(void)
{
    /* init the mcu register*/
    DisableInterrupts;
    CONFIG1 = 0x01;                                      
    CONFIG2 = 0x00;                                      
    OSCTRIM = *(unsigned char*far)0xFFC0; /* Initialize OSCTRIM register from a non volatile memory */
    DDRB = 0x3F;                        /*portb 0 to 5 as 2s,15m,1h,2h,3h,5h*/                
    DDRA = 0x10;                        /*porta4 as LED output*/
    TSC = 0x30;                          /* Stop and reset counter */
    TMOD = 0x2710;                    /* Period value setting */
    TSC = 0x45;                          /* Int. flag clearing (2nd part) and timer contr. register setting */
  PTA = 0x00;
  PTB = 0x00;
    EnableInterrupts;                    /* Enable interrupts */
}
void main(void) 
{
    Init_Device();
    EnableInterrupts; /* enable interrupts */
    /* include your code here */
    for(;;) 
    {
        __RESET_WATCHDOG(); /* feeds the dog */
    } /* loop forever */
    /* please make sure that you never leave main */
}

相关帖子

沙发
张明峰| | 2007-5-21 21:40 | 只看该作者

注意校准值

出厂时FFC0处会有一校准值,但用简单的调试工具进行芯片擦除时也会将该值一起擦除。

调试时先将空芯片的内容读出来,记下出厂的校准值,软件直接赋值进行校准。批量生产时选用能保留此校准值的工具(先读出来,然后擦除芯片,再一起烧写)。

使用特权

评论回复
板凳
谭可|  楼主 | 2007-5-22 09:01 | 只看该作者

请教张明峰

FFC0地址是属于Flash中的地址,可以直接赋值吗?

使用特权

评论回复
地板
afanti| | 2007-5-22 10:20 | 只看该作者

re

const byte strName[] @0xFFC0 = {0x55};可以这样。
FSL的校正值太麻烦了~~~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

3

帖子

1

粉丝