📄 24c04test.lst
字号:
C51 COMPILER V8.08 24C04TEST 01/04/2008 11:11:58 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE 24C04TEST
OBJECT MODULE PLACED IN 24C04test.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24C04test.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------------------
2 c8051f320读写FM24C02A实验
3 P1.1 -> SDA (SMBus)
4 P1.2 -> SCL (SMBus)
5 ------------------------------------------------------------------------------------*/
6 // Includes
7 //------------------------------------------------------------------------------------
8 #include <c8051f320.h> // SFR declarations
9 #include <intrins.h>
10 //------------------------------------------------------------------------------------
11 // Global CONSTANTS
12 //------------------------------------------------------------------------------------
13
14 #define SYSCLK 24500000 // System clock frequency
15 #define SMB_FREQUENCY 50000 // Target SCL clock rate
16
17 #define WRITE 0x00 // SMBus WRITE command
18 #define READ 0x01 // SMBus READ command
19
20 // Device addresses (7 bits, lsb is a don't care)
21 #define EEPROM_ADDR 0xA0 // Device address for slave target
22 // Note: This address is specified
23 // in the Microchip 24LC02B
24 // datasheet.
25 // SMBus Buffer Size
26 #define SMB_BUFF_SIZE 0x08 // Defines the maximum number of bytes
27 // that can be sent or received in a
28 // single transfer
29
30 // Status vector - top 4 bits only
31 #define SMB_MTSTA 0xE0 // (MT) start transmitted
32 #define SMB_MTDB 0xC0 // (MT) data byte transmitted
33 #define SMB_MRDB 0x80 // (MR) data byte received
34 // End status vector definition
35 //------------------------------------------------------------------------------------
36 // Global VARIABLES
37 //------------------------------------------------------------------------------------
38 unsigned char* pSMB_DATA_IN; // Global pointer for SMBus data
39 // All receive data is written here
40
41 unsigned char SMB_SINGLEBYTE_OUT; // Global holder for single byte writes
42
43 unsigned char* pSMB_DATA_OUT; // Global pointer for SMBus data.
44 unsigned long q; // All transmit data is read from here
45
46 unsigned char SMB_DATA_LEN; // Global holder for number of bytes
47 // to send or receive in the current
48 // SMBus transfer
49
50 unsigned char WORD_ADDR; // Global holder for the EEPROM word
51 // address that will be accessed in
52 // the next transfer
53
54 unsigned char TARGET; // Target SMBus slave address
55 unsigned char temp_char; // temporary variable
C51 COMPILER V8.08 24C04TEST 01/04/2008 11:11:58 PAGE 2
56
57 unsigned char retval;
58 bit SMB_BUSY = 0; // Software flag to indicate when the
59 // EEPROM_ByteRead() or
60 // EEPROM_ByteWrite()
61 // functions have claimed the SMBus
62
63 bit SMB_RW; // Software flag to indicate the
64 // direction of the current transfer
65
66 bit SMB_SENDWORDADDR; // When set, this flag causes the ISR
67 // to send the 8-bit <WORD_ADDR>
68 // after sending the slave address
69
70
71 bit SMB_RANDOMREAD; // When set, this flag causes the ISR
72 // to send a START signal after
73 // sending the word address
74
75 bit SMB_ACKPOLL; // When set, this flag causes the ISR
76 // to send a repeated START until the
77 // slave has acknowledged its address
78
79 // 16-bit SFR declarations
80 sfr16 TMR2RL = 0xca; // Timer2 reload registers
81 sfr16 TMR2 = 0xcc; // Timer2 counter registers
82 sfr16 TMR3RL = 0x92; // Timer2 reload registers
83 sfr16 TMR3 = 0x94; // Timer3 counter registers
84
85 //------------------------------------------------------------------------------------
86 // Function PROTOTYPES
87 //------------------------------------------------------------------------------------
88
89 void SMBus_Init (void);
90 void Timer1_Init (void);
91 void Timer3_Init (void);
92 void Port1_Init (void);
93 void SMBus_ISR (void);
94 void Timer3_ISR (void);
95
96 void EEPROM_ByteWrite(unsigned char addr, unsigned char dat);
97 void EEPROM_WriteArray (unsigned char dest_addr, unsigned char* src_addr,
98 unsigned char len);
99 unsigned char EEPROM_ByteRead(unsigned char addr);
100 void EEPROM_ReadArray (unsigned char* dest_addr, unsigned char src_addr,
101 unsigned char len);
102 unsigned char xdata tab2[16]={0x57,0x72,0x69,0x74,0x65,0x20,0x53,0x4d,0x42,0x55,0x53,0x20,0x30,0x78
103 ,0x43,0x43};
104 //------------------------------------------------------------------------------------
105 // MAIN Routine
106 //------------------------------------------------------------------------------------
107 //
108 // Main routine performs all configuration tasks, then loops forever sending and
109 // receiving SMBus data to the slave F300_SLAVE
110
111 void main (void)
112 {
113 1 char in_buff[8] = {0}; // incoming data buffer
114 1 char out_buff[8] = "ABCD1EFG"; // outgoing data buffer
115 1
116 1 // unsigned char temp_char; // temporary variable
117 1
C51 COMPILER V8.08 24C04TEST 01/04/2008 11:11:58 PAGE 3
118 1 PCA0MD &= ~0x40; // WDTE = 0 (disable watchdog timer)
119 1
120 1 OSCICN |= 0x03; // Set internal oscillator to highest
121 1 // setting (24500000)
122 1 Port1_Init (); // Initialize Crossbar and GPIO
123 1
124 1 Timer1_Init (); // Configure Timer1 for use as SMBus
125 1 // clock source
126 1
127 1 Timer3_Init (); // Configure Timer2 for use with SMBus
128 1 // low timeout detect
129 1
130 1 SMBus_Init (); // Configure and enable SMBus
131 1 EIE1 |= 1; // SMBus interrupt enable
132 1 IE |= 0x20; // Timer2 interrupt enable
133 1 EA = 1; // Global interrupt enable
134 1 while(1)
135 1 // Write the value 0xAA to location 0x25 in the EEPROM
136 1 { int i,j,k;
137 2 EEPROM_ByteWrite(0x26, 0xaa);
138 2
139 2
140 2 temp_char = EEPROM_ByteRead(0x26);
141 2
142 2 // Write the value 0xBB to location 0x25 in the EEPROM
143 2 EEPROM_ByteWrite(0x25, 0xDD);
144 2
145 2 // Write the value 0xCC to location 0x38 in the EEPROM
146 2 EEPROM_ByteWrite(0x38, 0xCC);
147 2
148 2 // Read the value at location 0x25 in the EEPROM
149 2 temp_char = EEPROM_ByteRead(0x25);
150 2
151 2 // Read the value at location 0x38 in the EEPROM
152 2 temp_char = EEPROM_ByteRead(0x38);
153 2
154 2 // Store the outgoing data buffer at EEPROM address 0x50
155 2 EEPROM_WriteArray(0x50, out_buff, sizeof(out_buff));
156 2
157 2 // Fill the incoming data buffer with data starting at EEPROM address 0x50
158 2 EEPROM_ReadArray(in_buff, 0x50, sizeof(in_buff));}
159 1
160 1
161 1
162 1 // while(1);
163 1
164 1 }
*** WARNING C280 IN LINE 136 OF 24C04TEST.C: 'i': unreferenced local variable
*** WARNING C280 IN LINE 136 OF 24C04TEST.C: 'j': unreferenced local variable
*** WARNING C280 IN LINE 136 OF 24C04TEST.C: 'k': unreferenced local variable
165
166 //------------------------------------------------------------------------------------
167 // Functions
168 //------------------------------------------------------------------------------------
169
170 //------------------------------------------------------------------------------------
171 // EEPROM_Write ()
172 //------------------------------------------------------------------------------------
173 //
174 // This function writes the value in <dat> to location <addr> in the EEPROM then polls
175 // the EEPROM until the write is complete.
176 //
C51 COMPILER V8.08 24C04TEST 01/04/2008 11:11:58 PAGE 4
177 void EEPROM_ByteWrite( unsigned char addr, unsigned char dat )
178 {
179 1 while (SMB_BUSY); // Wait for SMBus to be free.
180 1 SMB_BUSY = 1; // Claim SMBus (set to busy)
181 1
182 1 // Set SMBus ISR parameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -