大家好,下面的代码是我从三星单片机论坛copy过来的,哪位哥懂这款MCU ,我想问:我若想选择外部时钟的话,应该怎样设置,PDF资料说要设置 smartOption ,它的地址为0X003C/0X003F,但是,我在头文件里找不到此地址,更找不到smartOption;我在想,这款MCU的头文件是不是不全啊?
“我现在用的是94c8的芯片,程序和原理图请见附件,现在程序为最简单的2ms进入一次中断,P00取反,但是实际用示波器看是不到3ms进入一次中断,请问这是什么原因。还有就是再用仿真器仿真时,总是刚reset就提示堆栈溢出,请问这是什么原因。”
#include "ioS3f94c8.h"
#include "intrinsics.h"
#include "HeaderFile.h"
//#define uchar unsigned char
//#define uint unsigned int
__root const unsigned char smartOption[4] @ 0x003C ={0x00,0x00,0xe7,0x03}; /*ÔÊÐíLVR¸´Î»,ʹÓÃÄÚ²¿3.2MHZ¾§Ìå*/
//static __tiny UINT8 flag_2ms = CLR;
static __tiny UINT8 ADtimeCNT = CLR;
static __tiny UINT16 voltageADvalue = 30;
static __tiny UINT16 voltageADvalueBuf = 30;
static __tiny UINT8 timeCount = 0;
static __tiny UINT8 flagPulseFinished = CLR;
static void CalSampleAD_Value(void);
//static __tiny UINT8 timeCount100ms = CLR;
void InitSfr(void)
{
BTCON = 0x02; /*ÔÊÐí¿´ÃŹ·*/
CLKCON = 0x18; //CPUʱÖÓΪFosc
P0CONH = 0xAA; // output
P0CONL = 0xB2;// P00 pulse output,p01 ¹ýÁã¼ì²â,p02 voltage AD input,P03 -> RELAY ,
// P0PND = 0x08; // enable p0.1 interruput
P0PND = 0x00;
P1CON = 0xAA;
P2CONH = 0xAA;
P2CONL = 0xAA;//P20,P23 output,P21,p22 input P21-> K2 key,P22-> K1 key
P1=0x00;//0xff;
P0 = 0x00;
P2 = 0x00;
ADCON = 0x27;
}
void main()
{
__disable_interrupt();
SP=0xc0;
SYM=0x00;
InitSfr();
// FTSTCON = 0x00;
// InitMcuSystem();
T0DATA = 20; //20*2.5us = 50us
T0CON = 0x8A; //3.2Mhz /8 = 0.4Mhz; 1/0.4Mhz = 2.5us
// T0CON = T0CON &0xFD;
__enable_interrupt();
while(1)
{
BTCON = 0x02;
/*
ADtimeCNT++;
if(ADtimeCNT > 100)
{
ADtimeCNT = CLR;
if((ADCON&0x08) != CLR)
{
ADCON = ADCON &0xF7;
voltageADvalueBuf = ADDATAH;
voltageADvalueBuf = voltageADvalueBuf<< 8;
voltageADvalueBuf = voltageADvalueBuf |ADDATAL;
voltageADvalue = voltageADvalueBuf;
}
}
*/
}
}
#pragma vector = 0x00
__interrupt void Interrupts(void)
{
static __tiny UINT8 timer10msCnt = CLR;
static __tiny UINT8 FlagFirstStart = CLR;
__disable_interrupt();
T0CON =T0CON&0xFE;
timer10msCnt++;
if(timer10msCnt >= 40)
{
timer10msCnt = CLR;
P0_P00 = ~P0_P00;
}
__enable_interrupt();
return;
}
转载
|