📄 ad.lst
字号:
C51 COMPILER V8.08 AD 10/20/2008 18:56:04 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE AD
OBJECT MODULE PLACED IN AD.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE AD.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "c8051f020.h"
2 //#include "LCDLong.H"
3 #include "intrins.h"
4 #include "lcd.h"
5 //***************AD_DA配置************************
6 void AD_DA_Config(void)
7 {
8 1
9 1 WDTCN=0X07;
10 1 WDTCN=0XDE;
11 1 WDTCN=0XAD; //关开门狗
12 1
13 1 XBR0=0XAF;
14 1 XBR1=0X0D;
15 1 XBR2=0X44; // 端口分配表见说明文件
16 1
17 1 OSCXCN=0X00;
18 1 OSCICN=0x06; //内部8m晶振
19 1
20 1 REF0CN = 0x03; // Reference Control Register
21 1
22 1 //----------------------------------------------------------------
23 1 // ADC Configuration AMUX0:九通道的可编程模拟多路选择器,ADC0的最高转换速率为100ksps,其转换时钟来源与系统
24 1 //时钟分频,分频值保存在寄存器ADC0CF的ADCSC位.
25 1
26 1 //----------------------------------------------------------------
27 1
28 1 AMX0CF = 0x60; // AMUX Configuration Register 配置寄存器
29 1 AMX0SL = 0x00; // AMUX Channel Select Register AMX0SL =0x00; //选择通道0 AMX0SL通道选择寄存器
30 1 ADC0CF = 0x18; // ADC Configuration Register 配置寄存器
31 1 ADC0CN = 0x80; // ADC Control Register 控制寄存器
32 1
33 1 ADC0LTH = 0x00; // ADC Less-Than High Byte Register ****下限寄存器ADC0GTH
34 1 ADC0LTL = 0x00; // ADC Less-Than Low Byte Register ****下限寄存器ADC0GTL
35 1 ADC0GTH = 0xFF; // ADC Greater-Than High Byte Register
36 1 ADC0GTL = 0xFF; // ADC Greater-Than Low Byte Register
37 1
38 1 /*AMX1SL = 0x00; // AMUX1 Channel Select Register
39 1 ADC1CF = 0xF8; // ADC1 Configuration Register
40 1 ADC1CN = 0x00; // ADC1 Control Register
41 1
42 1
43 1
44 1 DAC0CN = 0x80; // DAC0 Control Register
45 1 DAC0L = 0x00; // DAC0 Low Byte Register
46 1 DAC0H = 0x00; // DAC0 High Byte Register
47 1
48 1 DAC1CN = 0X80;
49 1 DAC1L = 0X00;
50 1 DAC1H = 0X00; */
51 1
52 1
53 1 }
54
55 /****************************************************************
C51 COMPILER V8.08 AD 10/20/2008 18:56:04 PAGE 2
56 DAC0 DAC1 OUTPUT function
57 *****************************************************************/
58
59 void DA0_Out (unsigned int con_volt )
60 {
61 1 unsigned char hbyte,lbyte;
62 1
63 1 hbyte=con_volt/256;
64 1 lbyte=con_volt&0x00ff;
65 1
66 1 DAC0L=lbyte;
67 1 DAC0H=hbyte;
68 1 }
69
70 void DA1_Out (unsigned int con_volt)
71 {
72 1 unsigned char hbyte,lbyte;
73 1
74 1 hbyte=con_volt/256;
75 1 lbyte=con_volt&0x00ff;
76 1
77 1 DAC1L=lbyte;
78 1 DAC1H=hbyte;
79 1 }
80
81 /************************************************************
82 ADC0 ADC1 output function
83 **********************************************************/
84
85 unsigned int AD_Sample ( )
86 {
87 1
88 1 unsigned char hbyte,lbyte;
89 1 unsigned char i;
90 1 unsigned int current_vlot=0;
91 1 unsigned int ret_volt=0;
92 1
93 1 for(i=0;i<8;i++)
94 1 {
95 2 AD0BUSY=1; //start ADC0 convert
96 2
97 2 while(!AD0INT); // waitting
98 2 hbyte=ADC0H;
99 2 lbyte=ADC0L;
100 2
101 2 current_vlot=hbyte*256+lbyte;
102 2
103 2 ret_volt=( current_vlot>>3)+ret_volt;
104 2 }
105 1
106 1 return ret_volt;
107 1
108 1 }
109
110
111 void Delay_ADDA(unsigned int counter)
112 {
113 1 while(counter--);
114 1 }
115
116
117
C51 COMPILER V8.08 AD 10/20/2008 18:56:04 PAGE 3
118
119 main()
120
121 {
122 1 unsigned int i=0;
123 1 unsigned int voltage=0;
124 1 float temp=0;
125 1 AD_DA_Config();
126 1
127 1 while(1)
128 1 {
129 2
130 2 DA0_Out (1000 );
131 2
132 2 DA1_Out (2000 );
133 2
134 2
135 2 Delay_ADDA(10000);
136 2 temp=AD_Sample ( );
137 2 Delay_ADDA(100);
138 2
139 2 temp=(temp*2420)/4096;
140 2
141 2 LCD_WriteCommand(0x0c);
142 2 LCD_Config( );
143 2 LCD_Init( );
144 2 LCD_ChangMode(0);
145 2 LCD_Printf(1,1,"TI_UESTC");
146 2 LCD_PutHZ(1,5,"曹");
147 2 LCD_PutHZ(1,6,"龙");
148 2 LCD_PutHZ(2,1,"第");
149 2 LCD_PutHZ(2,2,"一");
150 2 LCD_PutHZ(2,3,"组");
151 2 LCD_PutAD(3,1,temp);
152 2 LCD_WriteCommand(0x0c);
153 2 //while(1);
154 2
155 2 Delay_ADDA(100);
156 2
157 2 }
158 1 }
159
160
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 375 ----
CONSTANT SIZE = 24 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 8
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -