导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→C51的一个简单程序总是有问题?请问![study]

 *第16159篇: C51的一个简单程序总是有问题?请问!

  
楼 主:study 2003年9月9日19:56
 C51的一个简单程序总是有问题?请问!
编译没错误,运行出现错误提示:*** error 65: access violation at I:0x81 : no 'write' permission,串行口没有输出。请问大家问题如何解决?为什么?程序附下中:
#include   <stdio.h>  
#include   <reg51.h>  

float average(array,n)
 float array[];
 int n;
 {
  int i;
  float aver,sum;
  sum=array[0];
  for(i=1;i  <n;i++)
    sum=sum+array[i];
  aver=sum/n;
  return(aver);
 }

void main(){
float pot_1[5]={99.9,88.8,77.7,66.6,0};
float pot_2[10]={11.1,22.2,33.3,44.4,55.5,99.9,88.8,77.7,66.6,0};
SCON=0x52;
TMOD=0x20;
TCON=0x69;
TH1=0x0F3;
printf("the average of A is %6.2f\n",average(pot_1,5));
printf("the average of B is %6.2f\n",average(pot_2,10));  
 }

  
2楼:yharbour 2003年9月9日20:02
 是不是没贴全,我试没问题呀!

  
3楼:study 2003年9月9日20:20
 就是书上的那个程序,完整的。
  
4楼:yharbour 2003年9月9日20:36
 我在这试是好的呀,结果如下:
the average of A is 66.60
the average of B is 49.95
  
5楼:study 2003年9月11日09:37
 奇怪?为什么?
对上面的程序进行调试,测试其中的部分程序就发现问题。
程序如下:
#include   <stdio.h>  
#include   <reg51.h>  
main(){
float pot_1[]={99.9,88.8,77.7,66.6,0};
float pot_2[]={11.1,22.2,33.3,44.4,55.5,99.9,88.8,77.7,66.6,0};
SCON=0x52;
TMOD=0x20;
TCON=0x69;
TH1=0x0F3;
printf("the average of A is %6.2f\n",pot_1[0]);
printf("the average of B is %6.2f\n",pot_2[0]);  
 }
输出就不出来。而屏蔽两条语句后,如下所示:
#include   <stdio.h>  
#include   <reg51.h>  
main(){
float pot_1[]={99.9,88.8,77.7,66.6,0};
//float pot_2[]={11.1,22.2,33.3,44.4,55.5,99.9,88.8,77.7,66.6,0};
SCON=0x52;
TMOD=0x20;
TCON=0x69;
TH1=0x0F3;
printf("the average of A is %6.2f\n",pot_1[0]);
//printf("the average of B is %6.2f\n",pot_2[0]);  
 }
输出结果就对了。
奇怪?为什么?

>>>>>>对该主题发表你的看法

本主题贴数5,分页: [第1页]


[上一篇主题]:keil编译器链接问题!就是搞不明白!请各位赐教!

[下一篇主题]:求助