📄 upsd_st85.lst
字号:
C51 COMPILER V7.00 UPSD_ST85 11/13/2002 09:49:12 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE UPSD_ST85
OBJECT MODULE PLACED IN upsd_st85.OBJ
COMPILER INVOKED BY: E:\KEIL\C51\BIN\C51.EXE upsd_st85.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*----------------------------------------------------------------------------
2 Title: upsd_st85.c
3 Date: October 8, 2002
4 Author: Alec Bath
5 Description: ST85 Read/Write Routines for DK3200 Board
6 10/18/02 PCL Modified to utlize Switches 1 and 2 to set the clock on the DK3200 board
7
8 Copyright 2002 ST Microelectronics
9 This example demo code is provided as is and has no warranty,
10 implied or otherwise. You are free to use/modify any of the provided
11 code at your own risk in your applications with the expressed limitation
12 of liability (see below) so long as your product using the code contains
13 at least one uPSD products (device).
14
15 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
16 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
17 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
18 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
19 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
20 ----------------------------------------------------------------------------*/
21
22 #pragma CODE // include assembly in .lst file
23
24 #include "upsd3200.h"
25 #include "upsd_hardware.h"
26 #include "upsd_st85.h"
27 #include "upsd_i2c.h"
28 #include "lcd_io.h"
29 #include "upsd_timer.h" // timer fns for timeout, etc.
30
31 extern xdata unsigned char i2c_xmit_buf[256]; // message xmit buffer
32 extern xdata unsigned char i2c_rcv_buf[256]; // message rcv buffer
33 unsigned int j; // array pointer
34 extern bit i2c_init_flag; // callable status flag bits
35
36
37
38 //--------------------------------
39 // Test M41ST85 I2C interface
40 //--------------------------------
41
42 void uPSD_st85_write (void){ // set up xmit buffer, and send chars via i
-2c
43 1 i2c_xmit_buf[0] = 0x00; // ST85 msecs=00
44 1 i2c_xmit_buf[1] = 0x00; // ST85 secs=00
45 1 // i2c_xmit_buf[2] = 0x42; // ST85 mins
46 1 // i2c_xmit_buf[3] = 0x12; // ST85 hours
47 1 i2c_xmit_buf[4] = 0x03; // ST85 dow
48 1 i2c_xmit_buf[5] = 0x15; // ST85 date
49 1 i2c_xmit_buf[6] = 0x10; // ST85 month
50 1 i2c_xmit_buf[7] = 0x02; // ST85 year
51 1 i2c_xmit_buf[8] = 0x00; // ST85 control=00
52 1 i2c_xmit_buf[9] = 0x00; // ST85 watchdog=0x00
53 1 i2c_xmit_buf[10] = 0x1f; // ST85 alm month=0x1f (enable alarm int.)
54 1 i2c_xmit_buf[11] = 0xff; // ST85 alm date=0x3f
C51 COMPILER V7.00 UPSD_ST85 11/13/2002 09:49:12 PAGE 2
55 1 i2c_xmit_buf[12] = 0x3f; // ST85 alm hour=0x3f (clr HT bit)
56 1 i2c_xmit_buf[13] = 0x7f; // ST85 alm min=0x7f
57 1 i2c_xmit_buf[14] = 0x7f; // ST85 alm sec=0x7f
58 1 upsd_i2c_xmit (0xD0,0x00,15); // send 15 bytes for st85: addr 0xD0, @ 0x00
--0x0E
59 1 }
60
61 void uPSD_read_clock_init (void){
62 1 int init_hour;
63 1 int init_mins;
64 1 int init_secs;
65 1
66 1 upsd_i2c_rcv (0xD0, 0x01, 3);
67 1 init_secs = i2c_rcv_buf[1];
68 1 if ((init_secs & 0x80) != 0) {
69 2 i2c_xmit_buf[1] = i2c_rcv_buf[1] & 0x00; // Clear the Stop bit if set
70 2 upsd_i2c_xmit (0xD0,0x01, 1);
71 2 }
72 1 i2c_xmit_buf[12] = i2c_rcv_buf[12] & 0xBF; // Start the clock by clear HT bit in buff
-er
73 1 upsd_i2c_xmit (0xD0,0x0C, 1);
74 1
75 1 init_hour = Conv_BCD_to_Int(i2c_rcv_buf[3]); // read current hour setting, conver BCD to
- integer
76 1 init_mins = Conv_BCD_to_Int(i2c_rcv_buf[2]); // read current minutes setting
77 1
78 1 if((init_hour >23) || (init_mins >59)){
79 2 i2c_xmit_buf[2] = 0x00; // Set minute to 0
80 2 i2c_xmit_buf[3] = 0x00; // Set hour to 0
81 2 uPSD_st85_write(); // Write to ST85
82 2 timer0_delay(1000);
83 2 }
84 1 uPSD_i2c_st85_read_clock(); // Read & Print ST85
85 1 }
86
87
88 void uPSD_i2c_st85_read_clock (void){
89 1 upsd_i2c_rcv (0xD0, 0x00, 16);
90 1 printfLCD("Current Time Is:\n"); // display on LCD
91 1 printfLCD(" ");
92 1 print_hex(i2c_rcv_buf[3]); // print Hours
93 1 printfLCD(":");
94 1 print_hex(i2c_rcv_buf[2]); // print Mins
95 1 printfLCD(":");
96 1 print_hex(i2c_rcv_buf[1]); // print Secs
97 1 printfLCD("\n");
98 1 }
99
100
101 void set_hour(void)
102 {
103 1 int tmp_hour;
104 1
105 1 tmp_hour = Conv_BCD_to_Int(i2c_rcv_buf[3]); // read current hour setting, conver BCD to
-integer
106 1
107 1 if (tmp_hour >= 23)
108 1 tmp_hour = 0;
109 1 else
110 1 tmp_hour = tmp_hour + 1;
111 1
112 1 i2c_xmit_buf[3] = Conv_Int_to_BCD(tmp_hour); // Write the updated hours to ST85
C51 COMPILER V7.00 UPSD_ST85 11/13/2002 09:49:12 PAGE 3
113 1 uPSD_st85_write();
114 1 }
115
116 void set_minutes(void)
117 {
118 1 int tmp_mins;
119 1
120 1 tmp_mins = Conv_BCD_to_Int(i2c_rcv_buf[2]); // read current minutes setting
121 1
122 1 if (tmp_mins >= 59)
123 1 tmp_mins = 0;
124 1 else
125 1 tmp_mins = tmp_mins+1;
126 1 i2c_xmit_buf[2] = Conv_Int_to_BCD(tmp_mins); // Write the updated minutes to ST85
127 1 uPSD_st85_write();
128 1 }
129
130 /******************************************************************************/
131 /* function: Conv_Int_to_BCD */
132 /* descripition: Convers an integer number to timekeeper BCD format */
133 /* input: int integ */
134 /* output: unsigned char */
135 /******************************************************************************/
136 unsigned char Conv_Int_to_BCD(int integ)
137 {
138 1 char tmp_buf;
139 1 tmp_buf = (unsigned char)(integ);
140 1 if (integ <=9) return(tmp_buf);
141 1 if ((integ >= 10) & (integ <= 19)) return (tmp_buf+0x06);
142 1 if ((integ >= 20) & (integ <= 29)) return (tmp_buf+0x0c);
143 1 if ((integ >= 30) & (integ <= 39)) return (tmp_buf+0x12);
144 1 if ((integ >= 40) & (integ <= 49)) return (tmp_buf+0x18);
145 1 if ((integ >= 50) & (integ <= 59)) return (tmp_buf+0x1E);
146 1 }
147
148 /******************************************************************************/
149 /* function: Conv_BCD_to_Int */
150 /* descripition: Convers BCD format to an integer number */
151 /* input: unsigned char BCD */
152 /* output: integer */
153 /******************************************************************************/
154 int Conv_BCD_to_Int(unsigned char BCD)
155 {
156 1 int tmp_buf1;
157 1 tmp_buf1 = (int)(BCD);
158 1 if (BCD <=0x9) return(tmp_buf1);
159 1 if ((BCD >= 0x10) & (BCD <= 0x19)) return (tmp_buf1-6);
160 1 if ((BCD >= 0x20) & (BCD <= 0x29)) return (tmp_buf1-12);
161 1 if ((BCD >= 0x30) & (BCD <= 0x39)) return (tmp_buf1-18);
162 1 if ((BCD >= 0x40) & (BCD <= 0x49)) return (tmp_buf1-24);
163 1 if ((BCD >= 0x50) & (BCD <= 0x59)) return (tmp_buf1-30);
164 1 if ((BCD >= 0x60) & (BCD <= 0xFF)) return (60);
165 1 }
C51 COMPILER V7.00 UPSD_ST85 11/13/2002 09:49:12 PAGE 4
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION uPSD_st85_write (BEGIN)
; SOURCE LINE # 42
; SOURCE LINE # 43
0000 E4 CLR A
0001 900000 E MOV DPTR,#i2c_xmit_buf
0004 F0 MOVX @DPTR,A
; SOURCE LINE # 44
0005 A3 INC DPTR
0006 F0 MOVX @DPTR,A
; SOURCE LINE # 47
0007 900000 E MOV DPTR,#i2c_xmit_buf+04H
000A 7403 MOV A,#03H
000C F0 MOVX @DPTR,A
; SOURCE LINE # 48
000D A3 INC DPTR
000E 7415 MOV A,#015H
0010 F0 MOVX @DPTR,A
; SOURCE LINE # 49
0011 A3 INC DPTR
0012 7410 MOV A,#010H
0014 F0 MOVX @DPTR,A
; SOURCE LINE # 50
0015 A3 INC DPTR
0016 7402 MOV A,#02H
0018 F0 MOVX @DPTR,A
; SOURCE LINE # 51
0019 E4 CLR A
001A A3 INC DPTR
001B F0 MOVX @DPTR,A
; SOURCE LINE # 52
001C A3 INC DPTR
001D F0 MOVX @DPTR,A
; SOURCE LINE # 53
001E A3 INC DPTR
001F 741F MOV A,#01FH
0021 F0 MOVX @DPTR,A
; SOURCE LINE # 54
0022 A3 INC DPTR
0023 74FF MOV A,#0FFH
0025 F0 MOVX @DPTR,A
; SOURCE LINE # 55
0026 A3 INC DPTR
0027 743F MOV A,#03FH
0029 F0 MOVX @DPTR,A
; SOURCE LINE # 56
002A A3 INC DPTR
002B 747F MOV A,#07FH
002D F0 MOVX @DPTR,A
; SOURCE LINE # 57
002E A3 INC DPTR
002F F0 MOVX @DPTR,A
; SOURCE LINE # 58
0030 7B0F MOV R3,#0FH
0032 E4 CLR A
0033 FD MOV R5,A
0034 7FD0 MOV R7,#0D0H
0036 020000 E LJMP _upsd_i2c_xmit
; FUNCTION uPSD_st85_write (END)
C51 COMPILER V7.00 UPSD_ST85 11/13/2002 09:49:12 PAGE 5
; FUNCTION uPSD_read_clock_init (BEGIN)
; SOURCE LINE # 61
; SOURCE LINE # 66
0000 7B03 MOV R3,#03H
0002 7D01 MOV R5,#01H
0004 7FD0 MOV R7,#0D0H
0006 120000 E LCALL _upsd_i2c_rcv
; SOURCE LINE # 67
0009 900000 E MOV DPTR,#i2c_rcv_buf+01H
000C E0 MOVX A,@DPTR
;---- Variable 'init_secs' assigned to Register 'R6/R7' ----
; SOURCE LINE # 68
000D 30E70E JNB ACC.7,?C0002
; SOURCE LINE # 69
0010 E4 CLR A
0011 900000 E MOV DPTR,#i2c_xmit_buf+01H
0014 F0 MOVX @DPTR,A
; SOURCE LINE # 70
0015 7B01 MOV R3,#01H
0017 7D01 MOV R5,#01H
0019 7FD0 MOV R7,#0D0H
001B 120000 E LCALL _upsd_i2c_xmit
; SOURCE LINE # 71
001E ?C0002:
; SOURCE LINE # 72
001E 900000 E MOV DPTR,#i2c_rcv_buf+0CH
0021 E0 MOVX A,@DPTR
0022 54BF ANL A,#0BFH
0024 900000 E MOV DPTR,#i2c_xmit_buf+0CH
0027 F0 MOVX @DPTR,A
; SOURCE LINE # 73
0028 7B01 MOV R3,#01H
002A 7D0C MOV R5,#0CH
002C 7FD0 MOV R7,#0D0H
002E 120000 E LCALL _upsd_i2c_xmit
; SOURCE LINE # 75
0031 900000 E MOV DPTR,#i2c_rcv_buf+03H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -