请教一下各位老手,我这个是什么原因啊?百思不得其解。代码如下:
//程序目的:1)按下KEY,单片机采集AN2的电压,存在0X10(HIGHT),0X11 (LOW),同时把0X10和0X11的内容复制一份到0X20,0X21
// 2)LED起指示作用
#include <pic.h>
__CONFIG(0X0384);//4MHZ FOSC
#define UCHAR unsigned char
#define UINT unsigned int
#define LED GPIO1
#define KEY GPIO5
#define POWER GPIO4
UCHAR ADRESULT_H,ADRESULT_L;
void Delay_ms(UCHAR x)
{
UCHAR y,z;
for(y=x;y>0;y--)
for(z=200;z>0;z--);
}
void Sys_Init()
{
CMCON0=0X07; //关闭比较器
ANSEL=0X54; //FOSC/16 0100
TRISIO=0XED; //1110 1101
OSCTUNE=0X00;
OSCCON=0X61; //4MHZ INTRCOSC
OPTION=0X00;
WPU=0X20; //0010 0000 GP5 PULL UP
IOC=0X00; //0000 0000 DISABLE ALL LEVEL INTERRUPT
INTCON=0X00; //0000 0000 DISABLE ALL INTERRUPT
CCP1CON=0X00;
POWER=1;
GIE=0;
PIE1=0;
ADRESL=0;
ADRESH=0;
}
void main()
{
UCHAR temp,count;
Sys_Init();
Delay_ms(220);
if(KEY==0)
{
GPIO=0X3D;
while(KEY==0);
GPIO=0X3F;
ADCON0=0X89; //CH2 RIGHT ON
Delay_ms(1);
GODONE=1;
while(GODONE==1);
ADRESULT_L=ADRESL;
ADRESULT_H=ADRESH;
EEPROM_WRITE(0X10,ADRESULT_H);
Delay_ms(0x02);
temp=EEPROM_READ(0X10);
EEPROM_WRITE(0X20,temp); //奇怪的问题就在这里,当把读0X10和0X11的语句去掉,工作是正常的
//当加上读0X10和0X11再写入到0X20和0X21的时候,4个单元的值都是0X00
//很奇怪!
EEPROM_WRITE(0X11,ADRESULT_L);
temp=EEPROM_READ(0X11);
EEPROM_WRITE(0X21,temp);
GPIO=0X3D;
Delay_ms(220);
Delay_ms(220);
GPIO=0X3F;
while(1);
}
} |