📄 16021602.lst
字号:
C51 COMPILER V8.18 16021602 12/09/2009 22:02:05 PAGE 1
C51 COMPILER V8.18, COMPILATION OF MODULE 16021602
OBJECT MODULE PLACED IN 16021602.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 16021602.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include < reg51.h >
2 #include < intrins.h >
3 #define uchar unsigned char
4 #define uint unsigned int
5 sbit DQ = P3^3 ; //定义DS18B20端口DQ
6 sbit BEEP=P3^6 ; //蜂鸣器驱动线
7 bit presence ; //检测18b20是否插好
8 sbit LCD_RS = P2^0 ;
9 sbit LCD_RW = P2^1 ;
10 sbit LCD_EN = P2^2 ;
11 uchar code cdis1[ ] = {" WWW.RICHMCU.COM "} ;
12 uchar code cdis2[ ] = {" WENDU: . C "} ;
13 uchar code cdis3[ ] = {" DS18B20 ERR0R "} ;
14 uchar code cdis4[ ] = {" PLEASE CHECK "} ;
15
16 unsigned char data temp_data[2] = {0x00,0x00} ;
17 unsigned char data display[5] = {0x00,0x00,0x00,0x00,0x00} ;
18 unsigned char code ditab[16] = {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,
19 0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;
20 void beep() ;
21 unsigned char code mytab[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00} ;
22
23 #define delayNOP() ; {_nop_() ;_nop_() ;_nop_() ;_nop_() ;} ;
24
25 /*******************************************************************/
26 void delay1(int ms)
27 {
28 1 unsigned char y ;
29 1 while(ms--)
30 1 {
31 2 for(y = 0 ; y<250 ; y++)
32 2 {
33 3 _nop_() ;
34 3 _nop_() ;
35 3 _nop_() ;
36 3 _nop_() ;
37 3 }
38 2 }
39 1 }
40
41 /******************************************************************/
42 /*检查LCD忙状态 */
43 /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */
44 /******************************************************************/
45 bit lcd_busy()
46 {
47 1 bit result ;
48 1 LCD_RS = 0 ;
49 1 LCD_RW = 1 ;
50 1 LCD_EN = 1 ;
51 1 delayNOP() ;
52 1 result = (bit)(P0&0x80) ;
53 1 LCD_EN = 0 ;
54 1 return(result) ;
55 1 }
C51 COMPILER V8.18 16021602 12/09/2009 22:02:05 PAGE 2
56
57 /*写指令数据到LCD */
58 /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */
59 /*******************************************************************/
60 void lcd_wcmd(uchar cmd)
61 {
62 1 while(lcd_busy()) ;
63 1 LCD_RS = 0 ;
64 1 LCD_RW = 0 ;
65 1 LCD_EN = 0 ;
66 1 _nop_() ;
67 1 _nop_() ;
68 1 P0 = cmd ;
69 1 delayNOP() ;
70 1 LCD_EN = 1 ;
71 1 delayNOP() ;
72 1 LCD_EN = 0 ;
73 1 }
74
75 /*******************************************************************/
76 /*写显示数据到LCD */
77 /*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */
78 /*******************************************************************/
79 void lcd_wdat(uchar dat)
80 {
81 1 while(lcd_busy()) ;
82 1 LCD_RS = 1 ;
83 1 LCD_RW = 0 ;
84 1 LCD_EN = 0 ;
85 1 P0 = dat ;
86 1 delayNOP() ;
87 1 LCD_EN = 1 ;
88 1 delayNOP() ;
89 1 LCD_EN = 0 ;
90 1 }
91
92
93 /* LCD初始化设定 */
94 /*******************************************************************/
95 void lcd_init()
96 {
97 1 delay1(15) ;
98 1 lcd_wcmd(0x01) ; //清除LCD的显示内容
99 1 lcd_wcmd(0x38) ; //16*2显示,5*7点阵,8位数据
100 1 delay1(5) ;
101 1 lcd_wcmd(0x38) ;
102 1 delay1(5) ;
103 1 lcd_wcmd(0x38) ;
104 1 delay1(5) ;
105 1
106 1 lcd_wcmd(0x0c) ; //显示开,关光标
107 1 delay1(5) ;
108 1 lcd_wcmd(0x06) ; //移动光标
109 1 delay1(5) ;
110 1 lcd_wcmd(0x01) ; //清除LCD的显示内容
111 1 delay1(5) ;
112 1 }
113
114 /* 设定显示位置 */
115 /*******************************************************************/
116 void lcd_pos(uchar pos)
117 {
C51 COMPILER V8.18 16021602 12/09/2009 22:02:05 PAGE 3
118 1 lcd_wcmd(pos | 0x80) ; //数据指针=80+地址变量
119 1 }
120
121 /*自定义字符写入CGRAM */
122 /*******************************************************************/
123 void writetab()
124 {
125 1 unsigned char i ;
126 1 lcd_wcmd(0x40) ; //写CGRAM
127 1 for (i = 0 ; i< 8 ; i++)
128 1 lcd_wdat(mytab[ i ]) ;
129 1 }
130
131 /*us级延时函数 */
132 /*******************************************************************/
133
134 void Delay(unsigned int num)
135 {
136 1 while( --num ) ;
137 1 }
138
139 /*初始化ds1820 */
140 /*******************************************************************/
141 Init_DS18B20(void)
142 {
143 1 DQ = 1 ; //DQ复位
144 1 Delay(8) ; //稍做延时
145 1
146 1 DQ = 0 ; //单片机将DQ拉低
147 1 Delay(90) ; //精确延时 大于 480us
148 1
149 1 DQ = 1 ; //拉高总线
150 1 Delay(8) ;
151 1
152 1 presence = DQ ; //如果=0则初始化成功 =1则初始化失败
153 1 Delay(100) ;
154 1 DQ = 1 ;
155 1
156 1 return(presence) ; //返回信号,0=presence,1= no presence
157 1 }
158
159
160 /* 读一个字节 */
161 /*******************************************************************/
162 ReadOneChar(void)
163 {
164 1 unsigned char i = 0 ;
165 1 unsigned char dat = 0 ;
166 1
167 1 for (i = 8 ; i > 0 ; i--)
168 1 {
169 2 DQ = 0 ; // 给脉冲信号
170 2 dat >>= 1 ;
171 2 DQ = 1 ; // 给脉冲信号
172 2
173 2 if(DQ)
174 2 dat |= 0x80 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -