?? 7705.lst
字號(hào):
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 /*我的設(shè)計(jì)中ad7705的晶振是用的2.4576,電路中有接口和開發(fā)機(jī)進(jìn)行單片機(jī)信號(hào)聯(lián)接,并將轉(zhuǎn)換結(jié)果顯示在開發(fā)機(jī)的四
-個(gè)數(shù)碼管上。這個(gè)程序是采樣程序,P3口設(shè)置成串口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的信號(hào)引腳
8 sbit ADC_CLK=P3^1; //指定時(shí)鐘引腳
9 sbit ADC_DRDY=P3^2; //指定轉(zhuǎn)換標(biāo)志位
10
11 float voltage; //這個(gè)全局變量是用來給數(shù)顯子程序傳遞采樣到的數(shù)據(jù)的
12
13 unsigned char data display_buffer[5]; //顯示緩沖
14 /*****************************************/
15 void send(unsigned char a) //通過P1口給數(shù)顯發(fā)送8位數(shù)據(jù)
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位數(shù)據(jù)a的順序顛倒后賦給b。
59 因?yàn)榇诎l(fā)送順序和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發(fā)送命令字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到時(shí)鐘寄存器,指定晶振頻率為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到設(shè)置寄存器,指定增益為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); //給通訊寄存器發(fā)0x38,指定下一個(gè)讀數(shù)據(jù)寄存器
147 2 data_out=ReadWord(); //從數(shù)據(jù)寄存器中讀16位數(shù)據(jù)
148 2 voltage=5.0*(data_out/65536.0); //將所讀數(shù)據(jù)轉(zhuǎn)換為電壓值
149 2 display();
150 2
151 2 }
152 1
153 1 }
154
C51 COMPILATION COMPLETE. 0 WARNING(S), 10 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -