iic20080107.lst
来自「VB环境下的串口通讯设计」· LST 代码 · 共 188 行
LST
188 行
C51 COMPILER V8.05a IIC20080107 01/07/2008 20:48:16 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE IIC20080107
OBJECT MODULE PLACED IN IIC20080107.OBJ
COMPILER INVOKED BY: C:\Keilc51\C51\BIN\C51.EXE IIC20080107.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /************************************************/
2 #include <REG52.H>
3 #define uchar unsigned char
4 #define uint unsigned int
5 #define ulong unsigned long
6 sbit I2C_SDA= P1^5;
7 sbit I2C_SCK= P1^4;
8 sbit I2C_WP= P1^3;
9 sbit GRE=P1^7;
10
11 //===============================================
12
13 //=============================
14 //延时10US
15 //内部调用函数
16 void Delay_10_uS(void)
17 {
18 1 char i=10;
19 1 while(i--);
20 1 }
21
22 //延时n_milisecond MS
23 //供内部调用函数
24 void delay_n_ms( uint n_milisecond) /* n mS delay */
25 {
26 1 uchar i;
27 1 while(n_milisecond--)
28 1 {
29 2 i=37;
30 2 while(i--);
31 2 }
32 1 }
33
34 //开始位
35 //内部调用函数
36 bit I2C_Start(void)
37 {
38 1 Delay_10_uS();
39 1 I2C_SDA =1;
40 1 Delay_10_uS();
41 1 I2C_SCK =1;
42 1 Delay_10_uS();
43 1 if ( I2C_SDA == 0) return 0;
44 1 if ( I2C_SCK == 0) return 0;
45 1 I2C_SDA = 0;
46 1 Delay_10_uS();
47 1 I2C_SCK = 0;
48 1 Delay_10_uS();
49 1 return 1;
50 1 }
51
52 //停止位
53 //内部调用函数
54 void I2C_Stop(void)
55 {
C51 COMPILER V8.05a IIC20080107 01/07/2008 20:48:16 PAGE 2
56 1 Delay_10_uS();
57 1 I2C_SDA = 0;
58 1 Delay_10_uS();
59 1 I2C_SCK = 1;
60 1 Delay_10_uS();
61 1 I2C_SDA = 1;
62 1 Delay_10_uS();
63 1 }
64
65
66 //写单字节数据
67 //内部调用函数
68 bit I2C_Send_Byte( uchar d)
69 {
70 1 uchar i = 8;
71 1 bit bit_ack;
72 1 while( i-- )
73 1 {
74 2 Delay_10_uS();
75 2 if ( d &0x80 ) I2C_SDA =1;
76 2 else I2C_SDA =0;
77 2 Delay_10_uS();
78 2 I2C_SCK = 1;
79 2 Delay_10_uS();
80 2 I2C_SCK = 0;
81 2 d = d << 1;
82 2 }
83 1 Delay_10_uS();
84 1 I2C_SDA = 1;
85 1 Delay_10_uS();
86 1 I2C_SCK = 1;
87 1 Delay_10_uS();
88 1 bit_ack = I2C_SDA;
89 1 I2C_SCK =0;
90 1 Delay_10_uS();
91 1 return bit_ack;
92 1 }
93
94
95
96 //写多字节数据
97 //供外部调用函数
98 void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
99 {
100 1
101 1 while(count--)
102 1 {
103 2 I2C_Start();
104 2 /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/ /* 24C16 USE */
105 2 I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
106 2 I2C_Send_Byte( AT24C64_address/256 );//写存储器页地址
107 2 I2C_Send_Byte( AT24C64_address %256 );//写存储器字节地址
108 2 I2C_Send_Byte( *(uchar*)mcu_address );//写MCU地址指针指数据到存储单元
109 2 I2C_Stop();
110 2 delay_n_ms(10); /* waiting for write cycle to be completed */
111 2 ((uchar*)mcu_address)++;
112 2 AT24C64_address++;
113 2 }
114 1 }
115
116 //读多字节数据
117 //供外部调用函数
C51 COMPILER V8.05a IIC20080107 01/07/2008 20:48:16 PAGE 3
118
119 void write1()
120 {
121 1 //uchar i,j;
122 1 //bit kbit;
123 1 uchar xdata tab[96]=
124 1 {
125 1 0x8,0x0,0x7,0xf0,0x0,0x0,0xf,0xfc,0x4,0x10,0x1f,0xf0,0x10,0x80,0x4,0x10,0x10,0x10,0x10,0x80,0x4,0x10,0x10,
-0x10,0x20,0x80,0x7,0xf0,0x10,0x10,0x4f,0xf8,0x4,0x10,0x10,0x10,0x88,0x80,0x4,0x10,0x1f,0xf0,0x8,0x80,0x4,0x10,0x10,0x10,
-0x8,0x80,0x7,0xf0,0x10,0x10,0x8,0x80,0x4,0x10,0x10,0x10,0xff,0xfe,0x8,0x10,0x10,0x10,0x0,0x80,0x8,0x10,0x10,0x10,0x0,0x8
-0,0x10,0x10,0x1f,0xf0,0x0,0x80,0x20,0x50,0x10,0x10,0x0,0x80,0x40,0x20,0x0,0x0,0x0,0x80,0x0,0x0,0x0,0x0
126 1 };
127 1 AT24C64_W(tab,0x120,0x60);
128 1
129 1 }
130
131 //void write2()
132 //{
133 //uchar tab[2][16]={
134 // {0x10,0x40,0x1A,0x40,0x13,0x40,0x32,0x40,0x23,0xFC,0x64,0x40,0xA4,0x40,0x28,0x40},
135 // {0x2F,0xFE,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40}/*"件",2*/
136 // };
137 // AT24C64_W(tab,0x0040,0x20);
138 //}
139 //=====================================
140 void main()
141 {
142 1
143 1 //uchar i,j;
144 1 //P1=0;
145 1 //P2=0;
146 1 P3=0;
147 1 GRE=0;
148 1 write1();
149 1 // write2();
150 1 GRE=1;
151 1 }
152
153
154
155
156
157
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 263 ----
CONSTANT SIZE = 96 ----
XDATA SIZE = ---- 96
PDATA SIZE = ---- ----
DATA SIZE = ---- 7
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?