本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
请教高手下
我在一个UART的调试程序中,只加了一个数组(lion1_data[128]),储存模式也该到XDATA下,在output中显示XDATA=198也没有超限。
但是程序无法运行了,删去数组部分就可以,我在程序中只是先定义了这个数组,根本就没去调用的。
如果哪位有兴趣帮助看下的话,我可以发现代码(调试部分很短)。
使用C8051F040,256字节RAM,4kXRAM,应该怎么去使用:有初始化?使能之类的么?
#include <C8051F040.h>
#include <stdio.h>
char SFRPAGE_SAVE;
unsigned char rec_flag,TI0FLAG;
unsigned char rec[8]={0xAA,0x78,0x00,0x00,0xCC,0x33,0xC3,0x3C};
unsigned char timk[15]={0xAA,0x9B,0xFF,0x01,0x03,0xFF,0xFF,0x00,0xD0,0x01,0x94,0xCC,0x33,0xC3,0x3C};
unsigned char timg[7]={0xAA,0x9B,0x00,0xCC,0x33,0xC3,0x3C};
unsigned char xdata lion1_data[128]={0xAA,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0x33,0xC3,0x3C};
unsigned char lion1_draw[20]={0xAA,0xC1,0x03,0x00,0x00,0x01,0xF4,0x01,0x36,0x00,0x3B,0x01,0x03,0x10,0xF8,0x00,0xCC,0x33,0xC3,0x3C};
//红字部分删除就可以正常接收,并且判断回传,但是加入之后即使不调用程序也无法正常云新
void UART0_Init (void); //UART0 与触摸屏连
void OSCILLATOR_Init (void); //振荡初始化 系统时钟为22.1184Mhz
void Uart0_transmit(unsigned char i); //向串口0发送一个字节
void send_str(unsigned char *p,unsigned char s); //向串口0发送一个数组
void UART0_ISR(void); //触控模式返回 0x78指令
void delay_ms(unsigned char n);
void main()
{
char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE;
WDTCN = 0xDE; // 关闭看门狗
WDTCN = 0xAD;
SFRPAGE = CONFIG_PAGE;
IP |= 0x10;
EA=1;
IE=0xB0;
ES0=1; //开中断 总中断EA ,ES,ET2
//开中断 ET3
SFRPAGE = SFRPAGE_SAVE;
OSCILLATOR_Init ();
UART0_Init ();
while(1)
{
if(rec_flag==1)
{
send_str(rec,8);
rec_flag=0;
}
}
}
void OSCILLATOR_Init ()
{
int i;
char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
OSCICN = 0x80; // 先暂时启用内部振荡,不运行编程频率
CLKSEL = 0x00; // 系统时钟选择内部振荡器
OSCXCN = 0x67; //外部振荡方式设置 晶振方式,频率控制位
for (i=0; i < 512; i++);
while (!(OSCXCN & 0x80)); // (判断标志第7位)晶体振荡器正常运行
CLKSEL = 0x01; // 系统时钟选择外部振荡器
SFRPAGE = SFRPAGE_SAVE;
}
void UART0_Init ()
{
char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
XBR0 = 0x04;
XBR2 = 0x40;
P0MDOUT |= 0x01;
SFRPAGE = TMR2_PAGE;
TMR2CN = 0x00;
TMR2CF = 0x08; // 系统时钟不分频
RCAP2H=0xFF ; //在22.1184MHz 系统时钟 115200波特率下计算
RCAP2L=0xF4 ;
TMR2L=0xFF;
TMR2H=0xF4;
TR2=1;
SFRPAGE = UART0_PAGE;
SCON0 = 0x50; // 方式1,并使UART0允许接收
SSTA0 = 0x15; // SMOD,使用定时器2溢出率
SFRPAGE = SFRPAGE_SAVE;
}
//-----------------------------------------------------------------------------
// Uart0_transmit
//-----------------------------------------------------------------------------
void Uart0_transmit(unsigned char i)//向串口0发送一个字节
{
TI0FLAG=0;
SBUF0=i;
while (TI0FLAG==0);
TI0FLAG=0;
}
void send_str(unsigned char *p,unsigned char s)//向串口0发送一个数组
{
unsigned int m;
for(m=0;m<s;m++)
{
Uart0_transmit(*p);
p++;
}
}
//-----------------------------------------------------------------------------
// UART0_ISR
//-----------------------------------------------------------------------------
//e.g:rec[8]={AA 78 xx xx CC 33 C3 3C}
void UART0_ISR() interrupt 4
{
unsigned char temp;
if(RI0)
{
for(temp=0;temp<7;temp++)
{rec[temp]=rec[temp+1];}
rec[7]=SBUF0;
if((rec[0]==0xAA)&&(rec[1]==0x78)&&(rec[4]==0xCC)&&(rec[5]==0x33)&&(rec[6]==0xC3)&&(rec[7]==0x3C))//使用返回1次坐标值模式 每次按下触摸屏仅返回1次AA 73 X_H X_L Y_H Y_L CC 33 C3 3C
{rec_flag=1;}
RI0=0;
}
else
{
TI0=0;
TI0FLAG=1;
}
}
void delay_ms(unsigned char n)
{
int i,j;
for(i=1000;i>0;i--) {
for(j=25*n;j>0;j--) {;}
}
}
[ 此帖被ksnryq在2010-09-29 13:30重新编辑 ] |