我准备把红外遥控解码后,写入eeprom,再读出,然后输出。我的程序会在下方列出,我的程序调试后,发现单个程序没错,几个程序和到一块,在运行printf。。。后L107:adress space overflow地址溢出,SPACE:DATA位置在数据处,主要程序下面列出:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "common.h"
#define ADDRWR 0xa0
#define ADDRRD 0xa1
//#define Page 16
void WriteToRom(BYTE *pData,BYTE Address,BYTE cNum);
void ReadFromRom(BYTE *pData,BYTE Address,BYTE cNum);
#define JINGZHEN 48
#define TIME0TH ((65536-100*JINGZHEN/12)&0xff00)>>8 //time0,100us,红外遥控
#define TIME0TL ((65536-100*JINGZHEN/12)&0xff)
#define TIME1TH ((65536-5000*JINGZHEN/12)&0xff00)>>8
#define TIME1TL ((65536-5000*JINGZHEN/12)&0xff)
#define uchar unsigned char
#define uint unsigned int
code uchar BitMsk[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,};
uint IrCount=0,Show=0,Cont=0;
uchar IRDATBUF[32],s[20];
uchar IrDat[5]={0,0,0,0,0};
uchar aa[6]={0,0,0,0,0,0};
int IrStart=0,IrDatCount=0;
int flag=0;
extern void initLCM( void); //LCD初始化子程序
extern void DisplayListChar(uchar X,uchar Y, unsigned char *DData); //显示指定坐标的一串字符子函数
void timer1int (void) interrupt 3 using 3{ //定时器1
EA=0;
TH1 = TIME1TH;
TL1 = TIME1TL;
Cont++;
if(Cont>10)Show=1;
EA=1;
}
void timer0int (void) interrupt 1 using 1{ //定时器0
uchar i,a,b,c,d,j=0;
EA=0;
TH0 = TIME0TH;
TL0 = TIME0TL;
if(IrCount>500)IrCount=0;
if(IrCount>300&&IrStart>0){IrStart=0;IrDatCount=0;IrDat[0]=IrDat[1]=IrDat[2]=IrDat[3]=0;IrCount=0;}
if(IrStart==2)
{
IrStart=3;
for(i=0;i<IrDatCount;i++)
{
if(i<32)
{
a=i/8;//锄禾子喻
b=IRDATBUF[i];
c=IrDat[a];
d=BitMsk[i%8];
if(b>5&&b<14)c|=d;
if(b>16&&b<25)c&=~d;
IrDat[a]=c;
}
}
if(IrDat[2]!=~IrDat[3])
{
IrStart=0;IrDatCount=0;IrDat[0]=IrDat[1]=IrDat[2]=IrDat[3]=0;IrCount=0;
}
else{
if(flag==0)
{ IrStart=0; IrStart=0;IrDatCount=0;IrDat[0]=IrDat[1]=IrDat[2]=IrDat[3]=0;IrCount=0;
aa[j]=IrDat[3];j++;}
if(j<6)flag=0;
else
{ flag=1;
EA=1;
return;}
}}
IrCount++;
EA=1;
}
void int0() interrupt 0 using 0 {
EA=0;
if((IrStart==0||IrStart==3)&&flag==1)
{
IrStart=1;IrCount=0;TH0 = TIME0TH;TL0 = TIME0TL;
IrDatCount=0;EA=1;
return;
}
if(IrStart==1)
{
if(IrDatCount>0&&IrDatCount<33)
IRDATBUF[IrDatCount-1]=IrCount;
if(IrDatCount>31)
{IrStart=2;TH0 = TIME0TH;TL0 = TIME0TL;EA=1;return;}
if(IrCount>114&&IrCount<133&&IrDatCount==0)
{IrDatCount=1;}else if(IrDatCount>0)IrDatCount++;
}
IrCount=0;TH0 = TIME0TH;TL0 = TIME0TL;
EA=1;
}
main()
{
int i;
BYTE SData[6];
BYTE Address=0x70;
TMOD |= 0x011;
TH0 = TIME0TH;
TL0 = TIME0TL;
ET0=1;
TR0=1;
IT0 = 1; //下降沿
EX0 = 1;
EA=1;
while(!flag);
TR1=0;
TR0=0;
ET1=0;
ET0=0;EX0=0;
initUart(); /* 初始化串口 */
WriteToRom(aa,Address,6);
for(i=0;i<6;i++)SData[i]=0;
ReadFromRom(SData,Address,6);
printf("\n AT24C16 adress 0x begin \n");//换行
for(i=0;i<6;i++)
{
if(SData[i]<=0x0f){
printf("0%BX ",SData[i]);
}
else{
printf("%B1X ",SData[i]);
}
}
while(1);
} |