📄 bits2.lst
字号:
C51 COMPILER V6.21 BITS2 01/23/2002 17:16:48 PAGE 1
C51 COMPILER V6.21, COMPILATION OF MODULE BITS2
OBJECT MODULE PLACED IN bits2.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE bits2.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 Bits2.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 Reading and writing individual port pins.
8
9 NOTE: Both pins on the same port
10
11 --- Generic version ---
12
13 COPYRIGHT
14 ---------
15
16 This code is associated with the book:
17
18 EMBEDDED C by Michael J. Pont
19 [Pearson Education, 2002: ISBN: 0-201-79523-X].
20
21 This code is copyright (c) 2001 by Michael J. Pont.
22
23 See book for copyright details and other information.
24
25 -*------------------------------------------------------------------*/
26
27 #include <reg52.H>
28
29 // Function prototypes
30 void Write_Bit_P1(const unsigned char, const bit);
31 bit Read_Bit_P1(const unsigned char);
32
33 /* ............................................................... */
34
35 void main (void)
36 {
37 1 bit x;
38 1
39 1 while(1)
40 1 {
41 2 x = Read_Bit_P1(0); // Read Port 1, Pin 0
42 2 Write_Bit_P1(1,x); // Write to Port 1, Pin 1
43 2 }
44 1 }
45
46 /* --------------------------------------------------------------- */
47
48 void Write_Bit_P1(const unsigned char PIN, const bit VALUE)
49 {
50 1 unsigned char p = 0x01; // 00000001
51 1
52 1 // Left shift appropriate number of places
53 1 p <<= PIN;
54 1
55 1 // If we want 1 output at this pin
C51 COMPILER V6.21 BITS2 01/23/2002 17:16:48 PAGE 2
56 1 if (VALUE == 1)
57 1 {
58 2 P1 |= p; // Bitwise OR
59 2 return;
60 2 }
61 1
62 1 // If we want 0 output at this pin
63 1 p = ~p; // Complement
64 1 P1 &= p; // Bitwise AND
65 1 }
66
67 /* --------------------------------------------------------------- */
68
69 bit Read_Bit_P1(const unsigned char PIN)
70 {
71 1 unsigned char p = 0x01; // 00000001
72 1
73 1 // Left shift appropriate number of places
74 1 p <<= PIN;
75 1
76 1 // Write a 1 to the pin (to set up for reading)
77 1 Write_Bit_P1(PIN, 1);
78 1
79 1 // Read the pin (bitwise AND) and return
80 1 return (P1 & p);
81 1 }
82
83 /*------------------------------------------------------------------*-
84 ---- END OF FILE -------------------------------------------------
85 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 68 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -