📄 main.lst
字号:
C51 COMPILER V7.08 MAIN 01/21/2007 16:37:38 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND TABS(8)
line level source
1 // Khai bao cac file header
2 #include <AT89X52.H>
3 #include <Kit8051.h>
4
5 // Khai bao cac bien toan cuc
6 unsigned char code string1[] = "8051 Starter Kit";
7 unsigned char code string2[] = "Dien ap = ";
8 unsigned char voltage,digit1,digit2;
9
10 // Khai bao cac ham
11 void InitSystem(void);
12 void Delay(unsigned int n);
13 void DelayShort(void);
14 void InitLCD(void);
15 void WriteCommand(unsigned char command);
16 void WriteCharacter(unsigned char character);
17 void WriteLCD(unsigned char x);
18 void SendString2LCD(unsigned char code *p);
19 void DisplayText(void);
20 void DisplayVoltage(void);
21 void Convert();
22 void Calculate();
23
24 // Dinh nghia cac ham
25 void InitSystem(void)
26 {
27 1 // Cam LCD
28 1 LCD_E = 0;
29 1 // Sang den backlight
30 1 LCD_BL = 0;
31 1 // Tre de LCD tu khoi tao ben trong (it nhat 15ms)
32 1 Delay(100);
33 1 // Tat den backlight
34 1 LCD_BL = 1;
35 1 InitLCD();
36 1 }
37 void Delay(unsigned int n)
38 {
39 1 unsigned int i,j;
40 1 for(i=0;i<n;i++)
41 1 for(j=0;j<100;j++);
42 1 }
43 void DelayShort(void)
44 {
45 1 unsigned char i;
46 1 for(i=0;i<10;i++);
47 1 }
48 void InitLCD(void)
49 {
50 1 WriteCommand(0x30);
51 1 WriteCommand(0x30);
52 1 WriteCommand(0x30);
53 1
54 1 // 8 bit, 2 lines, font 5x7
55 1 WriteCommand(0x38);
C51 COMPILER V7.08 MAIN 01/21/2007 16:37:38 PAGE 2
56 1 // Display on, hide cursor
57 1 WriteCommand(0x0C);
58 1
59 1 // Xoa man hinh
60 1 WriteCommand(0x01);
61 1 }
62 void DisplayText(void)
63 {
64 1 // Dich con tro den dau dong thu nhat
65 1 WriteCommand(0x80);
66 1 SendString2LCD(string1);
67 1 // Dich con tro den dau dong thu hai
68 1 WriteCommand(0xC1);
69 1 SendString2LCD(string2);
70 1 // Dich con tro den vi tri don vi do
71 1 WriteCommand(0xCE);
72 1 WriteCharacter('V');
73 1 }
74 void WriteLCD(unsigned char x)
75 {
76 1 LCD_RW = 0;
77 1 LCD_DATA = x;
78 1
79 1 LCD_E = 1;
80 1 LCD_E = 0;
81 1 Delay(5);
82 1 }
83 void WriteCommand(unsigned char command)
84 {
85 1 LCD_RS = 0;
86 1 WriteLCD(command);
87 1 }
88 void WriteCharacter(unsigned char character)
89 {
90 1 LCD_RS = 1;
91 1 WriteLCD(character);
92 1 }
93 void SendString2LCD(unsigned char code *p)
94 {
95 1 unsigned char i=0;
96 1 while(p[i]!=0)
97 1 {
98 2 WriteCharacter(p[i]);
99 2 i++;
100 2 Delay(50);
101 2 }
102 1 }
103 void Convert(void)
104 {
105 1 ADC_CS = 0;
106 1 DelayShort();
107 1 ADC_WR = 0;
108 1 DelayShort();
109 1 ADC_WR = 1;
110 1 DelayShort();
111 1 ADC_CS = 1;
112 1
113 1 // Tre cho chuyen doi xong
114 1 Delay(10);
115 1 // Chuyen Port thanh cong vao de chuan bi doc du lieu
116 1 ADC_DATA = 0xFF;
117 1 ADC_CS = 0;
C51 COMPILER V7.08 MAIN 01/21/2007 16:37:38 PAGE 3
118 1 DelayShort();
119 1 ADC_RD = 0;
120 1 DelayShort();
121 1 // Doc du lieu vao
122 1 voltage = ADC_DATA;
123 1 ADC_RD = 1;
124 1 DelayShort();
125 1 ADC_CS = 1;
126 1 }
127 void Calculate(void)
128 {
129 1 unsigned int temp;
130 1 temp = (voltage*10);
131 1 temp = temp/52;
132 1 // tinh ra dien ap tu gia tri ADC dua ve
133 1 // tach phan nguyen va phan thap phan
134 1 digit1 = (unsigned char) (temp/10);
135 1 digit2 = (unsigned char)(temp%10);
136 1 // chuyen sang ma ASCII
137 1 digit1 = digit1 + 0x30;
138 1 digit2 = digit2 + 0x30;
139 1 }
140 void DisplayVoltage(void)
141 {
142 1 // Dua con tro den vi tri can hien thi
143 1 WriteCommand(0xCB);
144 1 WriteCharacter(digit1);
145 1 WriteCharacter('.');
146 1 WriteCharacter(digit2);
147 1 }
148 // Chuong trinh chinh
149 void main(void)
150 {
151 1 // Khoi tao he thong
152 1 InitSystem();
153 1 DisplayText();
154 1 // Vong lap vo tan
155 1 while(1)
156 1 {
157 2 Convert();
158 2 Calculate();
159 2 DisplayVoltage();
160 2 }
161 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 321 ----
CONSTANT SIZE = 28 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 2
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 + -