?? lcd+adc0832.lst
字號(hào):
C51 COMPILER V8.05a LCD_ADC0832 03/11/2008 22:20:46 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE LCD_ADC0832
OBJECT MODULE PLACED IN LCD+ADC0832.OBJ
COMPILER INVOKED BY: c:\Keil\C51\BIN\C51.EXE LCD+ADC0832.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /********************************************************
2 壓力測試儀
3 系統(tǒng)描述;輸入 15--115kPA壓力信號(hào)
4 輸出 00h--ffh數(shù)字信號(hào)(adc0832)
5 在LCD上顯示實(shí)際的壓力值,如果超限則報(bào)警
6
7 線性區(qū)間標(biāo)度變換公式: y=(115-15)/(243-13)*X+15kpa
8
9 作者:
10 單位:
11 日期:2008.3.7
12
13 ********************************************************/
14
15 #include<reg51.h>
16 #include<intrins.h>
17 #include <absacc.h>
18 #include <math.h>
19
20 #define uchar unsigned char
21 #define uint unsigned int
22 #define BUSY 0x80 //常量定義
23 #define DATAPORT P0
24
25
26 //ADC0832的引腳
27 sbit ADCS =P3^5; //ADC0832 chip seclect
28 sbit ADDI =P3^7; //ADC0832 k in
29 sbit ADDO =P3^7; //ADC0832 k out
30 sbit ADCLK =P3^6; //ADC0832 clock signal
31
32 sbit LCM_RS=P2^0;
33 sbit LCM_RW=P2^1;
34 sbit LCM_EN=P2^2;
35
36 uchar ad_data; //采樣值存儲(chǔ)
37 sbit Alarm_led_red =P1^5; //超過壓力表量程最大值紅色led報(bào)警定義
38 sbit Alarm_led_green=P1^6; //低于壓力表量程最小值綠色led報(bào)警定義
39 //adc采樣值存儲(chǔ)單元
40 char press_data; //標(biāo)度變換存儲(chǔ)單元
41 unsigned char ad_alarm; //報(bào)警值存儲(chǔ)單元
42 unsigned char press_bai=0; //顯示值百位
43 unsigned char press_shi=0; //顯示值十位
44 unsigned char press_ge=0; //顯示值個(gè)位
45 unsigned char press_dot=0; //顯示值十分位
46
47 uchar code str0[]={"Press: . kpa "};
48 uchar code str1[]={" Check BY Jack "};
49
50 void delay(uint);
51 void lcd_wait(void);
52 void delay_LCM(uint); //LCD延時(shí)子程序
53 void initLCM( void); //LCD初始化子程序
54 void lcd_wait(void); //LCD檢測忙子程序
55 void WriteCommandLCM(uchar WCLCM,uchar BusyC); //寫指令到ICM子函數(shù)
C51 COMPILER V8.05a LCD_ADC0832 03/11/2008 22:20:46 PAGE 2
56 void WriteDataLCM(uchar WDLCM); //寫數(shù)據(jù)到LCM子函數(shù)
57 void DisplayOneChar(uchar X,uchar Y,uchar DData); //顯示指定坐標(biāo)的一個(gè)字符子函數(shù)
58 void DisplayListChar(uchar X,uchar Y,uchar code *DData); //顯示指定坐標(biāo)的一串字符子函數(shù)
59 void display(void); //系統(tǒng)顯示子函數(shù)
60 uchar Adc0832(unsigned char channel);
61 void alarm(void);
62 void data_pro(void);
63
64
65 /**********main funcation************/
66
67 void main(void)
68 {
69 1 delay(500); //系統(tǒng)延時(shí)500ms啟動(dòng)
70 1 // ad_data=0; //采樣值存儲(chǔ)單元初始化為0
71 1 initLCM( );
72 1
73 1 WriteCommandLCM(0x01,1); //清顯示屏
74 1 DisplayListChar(0,0,str0);
75 1 DisplayListChar(0,1,str1);
76 1
77 1 while(1)
78 1 {
79 2 ad_data =Adc0832(0); //采樣值存儲(chǔ)單元初始化為0
80 2
81 2 alarm();
82 2
83 2 data_pro();
84 2
85 2 display();
86 2
87 2 }
88 1 }
89
90
91 /*********延時(shí)K*1ms,12.000mhz**********/
92
93 void delay(uint k)
94 {
95 1 uint i,j;
96 1 for(i=0;i<k;i++)
97 1 {
98 2 for(j=0;j<60;j++)
99 2 {;}
100 2 }
101 1 }
102 /**********寫指令到ICM子函數(shù)************/
103
104 void WriteCommandLCM(uchar WCLCM,uchar BusyC)
105 {
106 1 if(BusyC)lcd_wait();
107 1 DATAPORT=WCLCM;
108 1 LCM_RS=0; // 選中指令寄存器
109 1 LCM_RW=0; // 寫模式
110 1 LCM_EN=1;
111 1 _nop_();
112 1 _nop_();
113 1 _nop_();
114 1 LCM_EN=0;
115 1
116 1 }
117
C51 COMPILER V8.05a LCD_ADC0832 03/11/2008 22:20:46 PAGE 3
118 /**********寫數(shù)據(jù)到LCM子函數(shù)************/
119
120 void WriteDataLCM(uchar WDLCM)
121 {
122 1 lcd_wait( ); //檢測忙信號(hào)
123 1 DATAPORT=WDLCM;
124 1 LCM_RS=1; // 選中數(shù)據(jù)寄存器
125 1 LCM_RW=0; // 寫模式
126 1 LCM_EN=1;
127 1 _nop_();
128 1 _nop_();
129 1 _nop_();
130 1 LCM_EN=0;
131 1 }
132
133 /***********lcm內(nèi)部等待函數(shù)*************/
134
135 void lcd_wait(void)
136 {
137 1 DATAPORT=0xff; //讀LCD前若單片機(jī)輸出低電平,而讀出LCD為高電平,則沖突,Proteus仿真會(huì)有顯示邏輯黃色
138 1 LCM_EN=1;
139 1 LCM_RS=0;
140 1 LCM_RW=1;
141 1 _nop_();
142 1 _nop_();
143 1 _nop_();
144 1 while(DATAPORT&BUSY)
145 1 { LCM_EN=0;
146 2 _nop_();
147 2 _nop_();
148 2 LCM_EN=1;
149 2 _nop_();
150 2 _nop_();
151 2 }
152 1 LCM_EN=0;
153 1
154 1 }
155
156 /**********LCM初始化子函數(shù)***********/
157
158 void initLCM( )
159 {
160 1 DATAPORT=0;
161 1 delay(15);
162 1 WriteCommandLCM(0x38,0); //三次顯示模式設(shè)置,不檢測忙信號(hào)
163 1 delay(5);
164 1 WriteCommandLCM(0x38,0);
165 1 delay(5);
166 1 WriteCommandLCM(0x38,0);
167 1 delay(5);
168 1
169 1 WriteCommandLCM(0x38,1); //8bit數(shù)據(jù)傳送,2行顯示,5*7字型,檢測忙信號(hào)
170 1 WriteCommandLCM(0x08,1); //關(guān)閉顯示,檢測忙信號(hào)
171 1 WriteCommandLCM(0x01,1); //清屏,檢測忙信號(hào)
172 1 WriteCommandLCM(0x06,1); //顯示光標(biāo)右移設(shè)置,檢測忙信號(hào)
173 1 WriteCommandLCM(0x0c,1); //顯示屏打開,光標(biāo)不顯示,不閃爍,檢測忙信號(hào)
174 1 }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -