以下是我写的程序 用来从AD读出数据再在P0口的数码管显示 可是一直不能通过编译 但是我又真的查不出在哪错了 希望指教 谢谢 程序后面有提示的错误信息
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#include<intrins.h>
uint ad2543work(uchar chunnel_select);
sbit AD_EOC=P2^0; //AD转换器的位定义
sbit AD_IO_CLOCK=P2^1;
sbit AD_DATA_IN=P2^2;
sbit AD_DATA_OUT=P2^3;
sbit AD_CS_2543=P2^4;
void delay(uint N) //延时子函数
{
uint i;
for(i=0;i<N;i++);
}
static ad_chunnel_select[]= //AD通道的选择,因
{0x0c,0x1c} //只用两个通道, 所以。。
uint ad2543work(uchar chunnel_select)
{
uint din;
uint dout,i;
din=0;
dout=ad_chunnel_select[chunnel_select];//控制命令
while(AD_EOC==0); //转换结束 否则一直在这里等待
AD_IO_CLOCK=0;
AD_CS_2543=0;
for(i=0;i<16;i++)
{ if(dout&0x80) AD_DATA_IN=1; //将控制数据写入
else AD_DATA_IN=0;
AD_IO_CLOCK=1;
dout<<=1;
din<<=1;
if(AD_DATA_OUT==1) din|=0x0001;//接收AD数据从MSB_LSB
AD_IO_CLOCK=0;
}
AD_CS_2543=1;//准备下一次的数据转换;
return(din>>4); //12位精度的数据;
}
void main()
{ int shu0,shu1;
uchar i;
for(i=0;i<2;i++)
{
DATA[i]=ad2543work(i);
}
shu0=DATA[0]; //将DATA1的数据提取出来
shu0=shu0&0x00ff; //分离出地八位赋值给P0
P0=0x00; //先清零
delay(5000);
P0=shu0;
delay(50000);
delay(50000);
delay(50000);
delay(50000);
shu1=shu1>>8;
shu1=shu1&0x00ff; //分离出高八位赋值给P0
P0=shu1;
while(1);
}
一下是提示的错误信息
..\CESHI\TEXT1.C(21): 错误 C141: syntax error near 'unsigned'
..\CESHI\TEXT1.C(22): 错误 C231: '_ad2543work': redefinition
..\CESHI\TEXT1.C(22): 错误 C141: syntax error near '{'
..\CESHI\TEXT1.C(26): 错误 C231: 'dout': redefinition
..\CESHI\TEXT1.C(26): 错误 C202: 'chunnel_select': undefined identifier
..\CESHI\TEXT1.C(27): 错误 C141: syntax error near 'while'
..\CESHI\TEXT1.C(27): 错误 C141: syntax error near '==', expected ')'
..\CESHI\TEXT1.C(28): 错误 C231: 'AD_IO_CLOCK': redefinition
..\CESHI\TEXT1.C(28): 错误 C231: 'AD_IO_CLOCK': redefinition
..\CESHI\TEXT1.C(29): 错误 C231: 'AD_CS_2543': redefinition
..\CESHI\TEXT1.C(29): 错误 C231: 'AD_CS_2543': redefinition
..\CESHI\TEXT1.C(30): 错误 C141: syntax error near 'for'
..\CESHI\TEXT1.C(30): 错误 C141: syntax error near '=', expected ')'
..\CESHI\TEXT1.C(30): 错误 C129: missing ';' before '<'
------解决方案--------------------------------------------------------
static ad_chunnel_select[]= //AD通道的选择,因
{0x0c,0x1c} //只用两个通道, 所以。。
没有用;结束?