源程序:EM78P372N
#include "EM78P372N.H" //EM78P372N的头文件
#define DISI() _asm{disi}
#define WDTC() _asm{wdtc}
#define NOP() _asm{nop}
#define ENI() _asm{eni}
#define SLEP() _asm{slep}
#define uchar unsigned char
#define uint unsigned int
extern int IntVecIdx; //occupied 0x10:rpage 0
extern unsigned int m=0,dataerr=0;
extern unsigned int data[10];
unsigned int datacom;
void wakeup();
void Delayms(uint ms);
void Delayus(uint us);
void main()
{
uint i,MAX,DATAR=0;
WDTC();
DISI();
SCR=0X7F; //选择4MHz
_asm
{
mov A,@0X80
contw
}
WDTCR=0X40; //使能P60作为外部中断输入口
ISR2=0; //中断标志位清零
IMR=0X04; //使能外部中断
ENI(); //开总中断
while(1)
{
wakeup();
TMRCON=0X1B; //PWM1,PWM2预分频为1:8
PWMCON=0X06; //16bit 选择PWM2通道
PRD1=169; //110HZ period设置
PRD2=27;
DT2=63; //PWM2占空比
T2EN=1; //打开PWM2
data[m-1]=datacom;
if(m=9)
{
MAX=data[0];
for(i=0;iMAX)
DATAR=0;
else
DATAR=1;
MAX=data;
}
}
while(DATAR)
{
P5CR=0X0; //PORT5设为输出
P5PDCR=0XF6; //P50,P53设为下拉
PORT5=0X09; //P50,P53输出高电平
Delayms(3);
PORT5=0X0; //P50,P53输出低电平
}
}
}
void wakeup()
{
P5CR=0X04; //PORT5 设为输入
P6CR=0X0; //PORT6 设为输出
PORT6=0X0; //P67输出低
P5PDCR=0XFB; //PORTW5设为下拉
P67=0; //默认输出0
ISR1=0X02; //使能PORT5状态改变唤醒功能
PORT5=PORT5; //读取PORT5状态
IDLE=0;
NOP();
NOP();
SLEP(); //进入睡眠
NOP();
WDTC();
NOP();
NOP();
PORT6^=128; //P67取反
}
void _intcall ALLInt(void) @ int
{
switch(IntVecIdx)
{
case 0x04:
if (EXIF==1) //有外部中断吗?
{
ISR2&=0XFB; //清外部中断标志
DT2=TMR2;
if(DT263)
dataerr=1;
while(!dataerr)
{
datacom=DT2;
if(m>9)
m=0;
m++;
}
}
break;
}
}
void _intcall Ext_l(void) @ 0x03:low_int 0
{
_asm{MOV A,0x2};
}
void Delayms(uint ms)
{
uint i,j;
for(i=0;i for(j=0;j<120;j++)
NOP();
}
void Delayus(uint us)
{
uint i,j;
for(i=0;i NOP();
}
发射110HZ波,脉宽需要是:MAX=127us MIN=17us.所以我用了16位PWM功能。
错误提示是:Error LNK:(1045) Symbol \'_data\' undefined.
"_data"我在程序中就没用过,怎么会提示未定义呢?[52RD.com] |