求助,找了快一天的错了,没有解决,关于xdata类型
时间:10-02
整理:3721RD
点击:
定义一个较大的数组,储存在xdata中,要对该数组进行赋值,一直赋不上去,用指针也赋不上去。
究竟该怎样对xdata中的数据进行调用及赋值?纠结致死。恳请各位帮忙。下面是主要部分的代码:
#include<reg52.h>
#include<stdio.h>
#include<adc0804.h>
#include<lcd1602.h>
#define uint unsigned int
#define uchar unsigned char
#include<intrins.h>
uint xdata str[100];
void main()
{ int a,b,c,j=0;
uint xdata *pstr=str;
float num=0;
unsigned int adc_data;
char temp[16];
LCD_Init();
LCD_Write_String(0,0,"hello world!");
while(j<=9)
{
start_adc0804();
DelayMs(100);
adc_data=read_ad();
num=(float)100*adc_data*10/255;
a=(int)num/100;
b=(int)num%100/10;
c=(int)num%10;
str[0]=a*100+b*10+c;
pstr=str;
sprintf(temp,"Var:%d",*pstr);//若改为sprintf(temp,"Var:%d",str[0]);且同时把上面一行的pstr=str注释掉就可以显示str[0]的值。
//想通过指针或者int i ;利用str[i]=....这样给str数组赋一系列值,可是因为其储存在xdata中,不知道怎搞的一直赋不上去。
LCD_Write_String(0,1,temp);
j=j+1;
}
while(1)
{
sprintf(temp,"Var:%d",str[9]);
LCD_Write_String(0,1,temp);
}
}
谢谢各位了!
究竟该怎样对xdata中的数据进行调用及赋值?纠结致死。恳请各位帮忙。下面是主要部分的代码:
#include<reg52.h>
#include<stdio.h>
#include<adc0804.h>
#include<lcd1602.h>
#define uint unsigned int
#define uchar unsigned char
#include<intrins.h>
uint xdata str[100];
void main()
{ int a,b,c,j=0;
uint xdata *pstr=str;
float num=0;
unsigned int adc_data;
char temp[16];
LCD_Init();
LCD_Write_String(0,0,"hello world!");
while(j<=9)
{
start_adc0804();
DelayMs(100);
adc_data=read_ad();
num=(float)100*adc_data*10/255;
a=(int)num/100;
b=(int)num%100/10;
c=(int)num%10;
str[0]=a*100+b*10+c;
pstr=str;
sprintf(temp,"Var:%d",*pstr);//若改为sprintf(temp,"Var:%d",str[0]);且同时把上面一行的pstr=str注释掉就可以显示str[0]的值。
//想通过指针或者int i ;利用str[i]=....这样给str数组赋一系列值,可是因为其储存在xdata中,不知道怎搞的一直赋不上去。
LCD_Write_String(0,1,temp);
j=j+1;
}
while(1)
{
sprintf(temp,"Var:%d",str[9]);
LCD_Write_String(0,1,temp);
}
}
谢谢各位了!
xdata 的变量是存储外部扩展RAM中,首先要看你的芯片支持xdata不?
xdata修饰的访问速度会很慢的,所以在函数里面和经常用到的变量最好不要用xdata
谢谢,用的是proteus仿真的,芯片是stc89c52,支持xdata的,直接给str[0]赋值是可以的,但i=0,str=1;或者用指针给该数组赋值就出错,搞不懂这是为什么。请问如果不用xdata的话,怎样定义一个int str[100];这样的数组呢?之前想的是数组太大,因此用的是xdata,可是赋值总出错,好纠结。非常感谢您的回答!谢谢!
