2023-03-23 17:00:05 +08:00

226 lines
9.7 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.60.0.0 TM1650 03/23/2023 15:55:27 PAGE 1
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE TM1650
OBJECT MODULE PLACED IN .\Objects\tm1650.obj
COMPILER INVOKED BY: d:\Keil_v5\C51\BIN\C51.EXE mycode\tm1650.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\myinc) DEBUG OBJECTEXT
-END PRINT(.\Listings\tm1650.lst) TABS(2) OBJECT(.\Objects\tm1650.obj)
line level source
1 #include "tm1650.h"
2 #include "delay.h"
3 #include "timer.h"
4 // 往一个指定的数码管位写入指定的显示数据
5 // 共阴数码管段码表:
6 // const unsigned char TUBE_TABLE_0[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- //共阴0~9的数字
7 const unsigned char TUBE_TABLE_0[16] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77,
-0x7c, 0x39, 0x5e, 0x79, 0x71}; // 共阴0~9~A~F
8 const unsigned char TUBE_TABLE_1[16]={0x01,0x21,0x30,0x18,0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x08,0x0
-c,0x06,0x03};
9 // 产生IIC总线起始信号
10 static void TM1650_IIC_start(void)
11 {
12 1 scl = 1; // SCL=1
13 1 sda = 1; // SDA=1
14 1 Delay4us();
15 1 sda = 0; // SDA=0
16 1 Delay4us();
17 1 scl = 0; // SCL=0
18 1 }
19 // 产生IIC总线结束信号
20 static void TM1650_IIC_stop(void)
21 {
22 1 scl = 0; // SCL=0
23 1 sda = 0; // SDA=0
24 1 Delay4us();
25 1 scl = 1; // SCL=1
26 1 Delay4us();
27 1 sda = 1; // SDA=1
28 1 }
29 // 通过IIC总线发送一个字节
30 static void TM1650_IIC_write_byte(unsigned char dat)
31 {
32 1 unsigned char i;
33 1 scl = 0;
34 1 for (i = 0; i < 8; i++)
35 1 {
36 2 do
37 2 {
38 3 if (dat & 0x80)
39 3 sda = 1; // SDA=1
40 3 else
41 3 sda = 0;
42 3 } while (0);
43 2 dat <<= 1;
44 2 Delay2us();
45 2 scl = 1;
46 2 Delay2us();
47 2 scl = 0;
48 2 Delay2us();
49 2 }
50 1 }
51 // 通过IIC总线接收从机响应的ACK信号
C51 COMPILER V9.60.0.0 TM1650 03/23/2023 15:55:27 PAGE 2
52 static unsigned char TM1650_IIC_wait_ack(void)
53 {
54 1 unsigned char ack_signal = 0;
55 1 sda = 1; // SDA=1
56 1 Delay2us();
57 1 ack_signal = sda;
58 1 scl = 1;
59 1 Delay2us();
60 1 // if(sda == 0)
61 1 // ack_signal = 1; //如果读取到的是NACK信号
62 1 scl = 0;
63 1 Delay2us();
64 1 return ack_signal;
65 1 }
66
67 // 作用:设置显示参数
68 // 备注:这个操作不影响显存中的数据
69 // 用例:
70 // 设置亮度并打开显示:TM1650_cfg_display(TM1650_BRIGHTx)
71 // 关闭显示:TM1650_cfg_display(TM1650_DSP_OFF)
72 static void TM1650_cfg_display(unsigned char x)
73 {
74 1 TM1650_IIC_start();
75 1 TM1650_IIC_write_byte(0x48);
76 1 TM1650_IIC_wait_ack(); // 固定命令
77 1 TM1650_IIC_write_byte(x);
78 1 TM1650_IIC_wait_ack(); // 参数值
79 1 TM1650_IIC_stop();
80 1 }
81 // 在DIG1位上显示数字3: TM1650_print(TM1650_DIG1,TUBE_TABLE_0[3]);
82 void TM1650_print(unsigned char dig, unsigned char seg_data)
83 {
84 1
85 1 TM1650_IIC_start();
86 1 TM1650_IIC_write_byte(dig * 2 + 0x68);
87 1 TM1650_IIC_wait_ack(); // 显存起始地址为0x68
88 1 TM1650_IIC_write_byte(seg_data);
89 1 TM1650_IIC_wait_ack(); // 发送段码
90 1 TM1650_IIC_stop();
91 1 }
92 // 将显存数据全部刷为0清空显示
93 static void TM1650_clear(void)
94 {
95 1 unsigned char a;
96 1 for (a = TM1650_DIG1; a <= TM1650_DIG4; a++)
97 1 {
98 2 TM1650_print(a, 0); // 将显存数据刷为0
99 2 }
100 1 }
101 // TM1650初始化
102 void TM1650_init(void)
103 {
104 1 sda = 1; // 释放SDA线
105 1 scl = 1; // 释放SCL线
106 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
107 1 TM1650_clear(); // 将显存内容清0
108 1 }
109
110 void TM1650_printpogrun(u8 set,u8 mode) // 显示run
111 {
112 1 sda = 1; // 释放SDA线
113 1 scl = 1; // 释放SCL线
C51 COMPILER V9.60.0.0 TM1650 03/23/2023 15:55:27 PAGE 3
114 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
115 1 TM1650_print(TM1650_DIG1, TUBE_TABLE_1[mode]);
116 1 Delay4us();
117 1 TM1650_print(TM1650_DIG2, 0x73);
118 1 Delay4us();
119 1 TM1650_print(TM1650_DIG3, TUBE_TABLE_0[set]);
120 1 Delay4us();
121 1 TM1650_print(TM1650_DIG4, TUBE_TABLE_1[mode+8]);
122 1 }
123 void TM1650_printpogstop(u8 set) // 显示run
124 {
125 1 sda = 1; // 释放SDA线
126 1 scl = 1; // 释放SCL线
127 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
128 1 TM1650_print(TM1650_DIG1, 0x40);
129 1 Delay4us();
130 1 TM1650_print(TM1650_DIG2, 0x73);
131 1 Delay4us();
132 1 TM1650_print(TM1650_DIG3, TUBE_TABLE_0[set]);
133 1 Delay4us();
134 1 TM1650_print(TM1650_DIG4, 0x40);
135 1 }
136 void TM1650_print_SMG1(u8 set) // 显示----页面0显示
137 {
138 1 sda = 1; // 释放SDA线
139 1 scl = 1; // 释放SCL线
140 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
141 1 TM1650_print(TM1650_DIG1, 0x40);
142 1 Delay4us();
143 1 if (set > 99)
144 1 TM1650_print(TM1650_DIG2, TUBE_TABLE_0[set / 100 % 10]);
145 1 else
146 1 TM1650_print(TM1650_DIG2, 0x00);
147 1 Delay4us();
148 1 if (set > 9)
149 1 TM1650_print(TM1650_DIG3, TUBE_TABLE_0[set / 10 % 10]);
150 1 else
151 1 TM1650_print(TM1650_DIG3, 0x00);
152 1 Delay4us();
153 1 TM1650_print(TM1650_DIG4, TUBE_TABLE_0[set % 10]);
154 1 }
155 void TM1650_print_SMG2(u16 set) // 显示----页面0显示
156 {
157 1 sda = 1; // 释放SDA线
158 1 scl = 1; // 释放SCL线
159 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
160 1 TM1650_print(TM1650_DIG1, 0x48);
161 1 Delay4us();
162 1 if (set > 99)
163 1 TM1650_print(TM1650_DIG2, TUBE_TABLE_0[set / 100 % 10]);
164 1 else
165 1 TM1650_print(TM1650_DIG2, 0x00);
166 1 Delay4us();
167 1 if (set > 9)
168 1 TM1650_print(TM1650_DIG3, TUBE_TABLE_0[set / 10 % 10]);
169 1 else
170 1 TM1650_print(TM1650_DIG3, 0x00);
171 1 Delay4us();
172 1 TM1650_print(TM1650_DIG4, TUBE_TABLE_0[set % 10]);
173 1 }
174 void TM1650_print_SMG3(u8 set) // 显示----页面0显示
175 {
C51 COMPILER V9.60.0.0 TM1650 03/23/2023 15:55:27 PAGE 4
176 1 sda = 1; // 释放SDA线
177 1 scl = 1; // 释放SCL线
178 1 TM1650_cfg_display(TM1650_BRIGHT5); // 初始化为5级亮度打开显示
179 1 TM1650_print(TM1650_DIG1, 0x49);
180 1 Delay4us();
181 1 if (set > 99)
182 1 TM1650_print(TM1650_DIG2, TUBE_TABLE_0[set / 100 % 10]);
183 1 else
184 1 TM1650_print(TM1650_DIG2, 0x00);
185 1 Delay4us();
186 1 if (set > 9)
187 1 TM1650_print(TM1650_DIG3, TUBE_TABLE_0[set / 10 % 10]);
188 1 else
189 1 TM1650_print(TM1650_DIG3, 0x00);
190 1 Delay4us();
191 1 TM1650_print(TM1650_DIG4, TUBE_TABLE_0[set % 10]);
192 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 657 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 32 14
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)