📄 main.lst
字号:
C51 COMPILER V7.20 MAIN 07/21/2004 16:31:42 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------------
2 main.c
3
4 Version:
5 June 2004 Version 1.0 - Initial Version
6
7 Dependencies:
8 upsd_lcd.c - LCD driver.
9 upsd_i2c.c - I2C driver.
10 upsd_timer.c - Timer driver.
11
12
13 Description: Demo for I2C Master
14 The main function of this code is to demonstrate the use of the I2C driver in
15 Master mode. As a master, the uPSD device writes data to a slave device over
16 the I2C bus and reads it back. It compares the received data with the sent data
17 and confirms with a message on the LCD if there is a match.
18
19 It is intended that the I2C slave device this master communicates with is a uPSD
20 device programmed with the I2C Slave demo code. The SCL and SDA lines of the
21 master and slave devices must be connected together and a pull-up is on each
22 signal. The two devices must also have their GNDs tied together. Using two
23 DK3200 boards, no pull-ups are required (they are included on the boards) but
24 the two signals (SCL, SDA) plus GND must be connected.
25
26
27 Copyright (c) 2004 STMicroelectrons Inc.
28
29 This example demo code is provided as is and has no warranty,
30 implied or otherwise. You are free to use/modify any of the provided
31 code at your own risk in your applications with the expressed limitation
32 of liability (see below) so long as your product using the code contains
33 at least one uPSD product (device).
34
35 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
36 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
37 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
38 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
39 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
40 ------------------------------------------------------------------------------*/
41 #include "upsd3200.h"
42 #include "upsd_hardware.h"
43 #include "upsd_i2c.h"
44 #include "upsd_timer.h"
45 #include "upsd_LCD.h"
46
47 #define I2C_ADDR 0x88
48 #define buf_len 0x04
49
50 xdata unsigned char temp_xmit_buf[20]; // message transmit buffer
51 xdata unsigned char temp_rcv_buf[20]; // message receive buffer
52 xdata PSD_REGS PSD8xx_reg _at_ PSD_REG_ADDR;
53
54
55 bit match_buf(unsigned char* a, unsigned char* b, unsigned char length)
C51 COMPILER V7.20 MAIN 07/21/2004 16:31:42 PAGE 2
56 {
57 1 unsigned char i;
58 1 for(i=1;i<=length;i++)
59 1 {
60 2 if(a[i-1]!=b[i-1])
61 2 return 0;
62 2 }
63 1 return 1;
64 1 }
65
66 main()
67 {
68 1 static unsigned char i,temp;
69 1 static unsigned char databuf[4]={0x55, 0xAA, 0x5A, 0xA5};
70 1
71 1 temp = 0x00;
72 1 WDKEY=0x55; // disable watchdog timer
73 1 PSD8xx_reg.VM |= 0x80;
74 1 timer0_init(); // initialize timer0 interrupt
75 1 lcd_init(); // initialize LCD. 8 bits, 2 lines, 5x7 font,
76 1 printfLCD("I2C Master"); // display on LCD
77 1 printfLCD("\nWaiting on Slave\n"); // display on LCD
78 1 delay_1sec();
79 1
80 1 for(i=0;i<20;i++)
81 1 temp_xmit_buf[i]=databuf[i];
82 1
83 1 upsd_i2c_init (833,I2C_ADDR); // I2C initialization
84 1
85 1 while(1)
86 1 {
87 2 EA=0;
88 2 while(temp!=I2C_MX_END)
89 2 temp=upsd_i2c_Master_Xmit(I2C_ADDR,temp_xmit_buf,buf_len);
90 2
91 2 printfLCD("\nTransmit OK \n");
92 2 delay_1sec();
93 2
94 2 for(i=0;i<20;i++)
95 2 temp_rcv_buf[i]=0;
96 2
97 2 while(temp!=I2C_MR_END)
98 2 temp=upsd_i2c_Master_Recv (I2C_ADDR,temp_rcv_buf,buf_len);
99 2
100 2 printfLCD("\nReceive OK \n");
101 2 delay_1sec();
102 2
103 2 if(match_buf(temp_xmit_buf,temp_rcv_buf,buf_len)==1)
104 2 {
105 3 printfLCD("\nMatch OK \n");
106 3 delay_1sec();
107 3 }
108 2 else
109 2 {
110 3 printfLCD("\nNo Match \n");
111 3 delay_1sec();
112 3 }
113 2 }
114 1 }
115
116
C51 COMPILER V7.20 MAIN 07/21/2004 16:31:42 PAGE 3
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 299 ----
CONSTANT SIZE = 106 ----
XDATA SIZE = 40 ----
PDATA SIZE = ---- ----
DATA SIZE = 6 8
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -