使用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 */ } |