📄 7705.lst
字号:
C51 COMPILER V7.08 7705 10/14/2007 17:29:32 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE 7705
OBJECT MODULE PLACED IN 7705.OBJ
COMPILER INVOKED BY: E:\软件安装\kc\C51\BIN\C51.EXE 7705.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*我的设计中ad7705的晶振是用的2.4576,电路中有接口和开发机进行单片机信号联接,并将转换结果显示在开发机的四
-个数码管上。这个程序是采样程序,P3口设置成串口0方式*/
2
3 #include<reg51.h>
4 #include<absacc.h>
5 #include<intrins.h>
6 #include<math.h>
7 sbit ADC_DIN=P3^0; //这一段是指定ad7705的信号引脚
8 sbit ADC_CLK=P3^1; //指定时钟引脚
9 sbit ADC_DRDY=P3^2; //指定转换标志位
10
11 float voltage; //这个全局变量是用来给数显子程序传递采样到的数据的
12
13 unsigned char data display_buffer[5]; //显示缓冲
14 /*****************************************/
15 void send(unsigned char a) //通过P1口给数显发送8位数据
16 {
17 1 unsigned char i;
18 1 for(i=0;i<8;i++)
19 1 {
20 2 if(_crol_(a,i)&0x80)
21 2 D_DAT=1;
*** ERROR C202 IN LINE 21 OF 7705.C: 'D_DAT': undefined identifier
22 2 else
23 2 D_DAT=0;
*** ERROR C202 IN LINE 23 OF 7705.C: 'D_DAT': undefined identifier
24 2 D_CLK=0;
*** ERROR C202 IN LINE 24 OF 7705.C: 'D_CLK': undefined identifier
25 2 D_CLK=1;
*** ERROR C202 IN LINE 25 OF 7705.C: 'D_CLK': undefined identifier
26 2 }
27 1 }
28 /*****************************************/
29 void DISP_DLEAY(void) //显示延迟子程序
30 {
31 1 unsigned char i,j;
32 1 for(i=0;i<10;i++)
33 1 for(j=0;j<5;j++);
34 1 }
35 /****************************************************************/
36 void process(long x)
37 {
38 1 as_0[5]=x/100000;
*** ERROR C202 IN LINE 38 OF 7705.C: 'as_0': undefined identifier
39 1 x=x%100000;
40 1 as_0[4]=x/10000;
*** ERROR C202 IN LINE 40 OF 7705.C: 'as_0': undefined identifier
41 1 x=x%10000;
42 1 as_0[3]=x/1000;
*** ERROR C202 IN LINE 42 OF 7705.C: 'as_0': undefined identifier
43 1 x=x%1000;
44 1 as_0[2]=x/100;
*** ERROR C202 IN LINE 44 OF 7705.C: 'as_0': undefined identifier
45 1 x=x%100;
46 1 as_0[1]=x/10;
C51 COMPILER V7.08 7705 10/14/2007 17:29:32 PAGE 2
*** ERROR C202 IN LINE 46 OF 7705.C: 'as_0': undefined identifier
47 1 as_0[0]=x%10;
*** ERROR C202 IN LINE 47 OF 7705.C: 'as_0': undefined identifier
48 1 }
49 void a3310dis()
50 {
51 1 display1(22,0,number[as_0[5]]);
52 1 display1(30,0,number[as_0[4]]);
53 1 display1(38,0,number[as_0[3]]);
54 1 display1(46,0,number[as_0[2]]);
55 1 display1(54,0,number[as_0[1]]);
56 1 display1(62,0,number[as_0[0]]);
57 1 }
58 unsigned char rearrange(unsigned char a) /*将8位数据a的顺序颠倒后赋给b。
59 因为串口发送顺序和ad7705的接收顺序刚好相反*/
60 {
61 1 unsigned char i,b;
62 1 b=a&0x01;
63 1 for(i=1; i<8; i++)
64 1 {
65 2 b=b<<1;
66 2 a=a>>1;
67 2 b=b+(a&0x01);
68 2 }
69 1 return(b);
70 1 }
71
72 /****************************************************************/
73
74 void WriteToReg_ADC(unsigned char a) //通过串口给ad7705发送命令字a
75 {
76 1
77 1 SCON=0;
78 1
79 1 TI=0;
80 1 SBUF=a;
81 1 while(!TI);
82 1
83 1 }
84
85 /*************************************************************/
86
87 void MX7705_Init() //ad7705初始化
88 {
89 1 unsigned char i;
90 1
91 1 ADC_CLK=1; //防止接口迷失
92 1 ADC_DIN=1;
93 1 for(i=0;i<100;i++)//prevent interface from losting
94 1 {
95 2 ADC_CLK=0;
96 2 ADC_CLK=1;
97 2 }
98 1
99 1 WriteToReg_ADC(0x04); //write 0x20 to communication register to choose channel 0
100 1 //and clock register for the next one to write
101 1
102 1 WriteToReg_ADC(0x20); //写0x04到时钟寄存器,指定晶振频率为2.4576MHz,采样率为50Hz.
103 1 WriteToReg_ADC(0x08); //write 0x10 to communication register to choose channel 0
104 1 //and setup register for the next one to write
105 1
106 1 WriteToReg_ADC(0x22); //写0x44到设置寄存器,指定增益为1, buffer off, FSYNC=0, and self-calibration
C51 COMPILER V7.08 7705 10/14/2007 17:29:32 PAGE 3
107 1
108 1 }
109
110 /*************************************************************/
111
112 unsigned int ReadWord()
113 {
114 1 unsigned char high8,low8;
115 1 unsigned int out;
116 1
117 1 SCON=0;
118 1
119 1 REN=1; //allow serial port to recieve data
120 1 RI=0;
121 1 while(!RI); //waiting the end of recieve of 8 bit
122 1 high8=SBUF;
123 1
124 1 ADC_CLK=1;
125 1
126 1 RI=0;
127 1 while(!RI);
128 1 low8=SBUF;
129 1 REN=0;
130 1 out=rearrange(high8);
131 1 out=out<<8;
132 1 out=out+rearrange(low8);
133 1 return(out);
134 1
135 1 }
136 main()
137 {
138 1 unsigned int data_out;
139 1
140 1
141 1 MX7705_Init();
142 1
143 1 while(ADC_DRDY==0)
144 1 {
145 2
146 2 WriteToReg_ADC(0x1C); //给通讯寄存器发0x38,指定下一个读数据寄存器
147 2 data_out=ReadWord(); //从数据寄存器中读16位数据
148 2 voltage=5.0*(data_out/65536.0); //将所读数据转换为电压值
149 2 display();
150 2
151 2 }
152 1
153 1 }
154
C51 COMPILATION COMPLETE. 0 WARNING(S), 10 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -