这个红外遥控主要是程序通过对按下的键的键码进行解析,并运行相应的功能代码
![](https://img2018.cnblogs.com/blog/1578282/201904/1578282-20190418211833608-151608259.png)
一次按键动作的遥控编码信息为 32 位串行二进制码。对于二进制信号“0”,一个脉冲占 1.2ms;对于二进制信号“1”,一个脉冲占 2.4ms,而每一脉冲内低电平均为 0.6ms。从起始标志到 32 位编码脉冲发完大约需80ms,此后遥控信号维持高电平。若按键未释放,则从起始标志起每隔 108ms 发出 3 个脉冲的重复标志。在 32 位的编码脉冲中,前 16 位码不随按键的不同而变化,我们称之为用户码。它是为了表示特定用户而设置的一个辨识标志,以区别不同机种和不同用户发射的遥控信号,防止误操作。后 16 位码随着按键的不同而改变,我们就是要读取这 16 位按键编码,经解码得到按键键号,转而执行相应控制动作。
主要运用DS1302时钟芯片,红外遥控,oled显示屏,蜂鸣器,定时器,中断实现
研究过程:
1.工程的建立和文件存放分配
2.根据原理图进行全局参数,引脚申明,类型说明头文件的编写
3.功能模块调试
1>oled液晶显示屏功能调试
2>蜂鸣器功能调试 //定时器2
3>DS1302读写调试
4>红外遥控按键功能的调试 //定时器1和外部中断0
4.所有显示程序的调试
5.程序总体功能的调试
7引脚的oled接线:
GND接GND,VCC接VCC,D0,D1,RST,DC接自定义引脚,CS接地。
引脚申明类型说明
1 #ifndef _CONFIG_H_
2 #define _CONFIG_H_
3
4 #include"reg52.h"
5 #include"intrins.h"
6
7 typedef signed char int8;
8 typedef signed int int16;
9 typedef unsigned int u16;
10 typedef unsigned char u8;
11 typedef signed long int32;
12
13 #define LED P2
14 #define SYS_MCLK 1000000
15
16 sbit GPIO_KEY=P1;
17
18 sbit OLED_SCLK=P1^0; //D0时钟管脚
19 sbit OLED_SDA=P1^1; //D1数据管脚
20 sbit OLED_RST=P1^2; //电源复位,低电平有效
21 sbit OLED_DC=P1^3; //数据或命令控制管脚
22
23 sbit DS_IO=P3^4 ;
24 sbit DS_SCLK=P3^6;
25 sbit DS_RST=P3^5;
26
27
28 sbit BUZZER=P1^5;
29
30 sbit DSPORT=P3^7;
31
32 sbit IRIN=P3^2;
33
34 #endif
oled显示屏代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #define _OLED_C
2 #include"config.h"
3 #include"OLED.h"
4 #define _OLED_C
5 void OLED_SetPos(u8 x,u8 y);
6 //命令函数
7 const u8 code F6x8[][6] =
8 {
9 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //sp0
10 { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !1
11 { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "2
12 { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #3
13 { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $4
14 { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %5
15 { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &6
16 { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '7
17 { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (8
18 { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )9
19 { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *10
20 { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +11
21 { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,12
22 { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -13
23 { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .14
24 { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /15
25 { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 016
26 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 117
27 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 218
28 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 319
29 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 420
30 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 521
31 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 622
32 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 723
33 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 824
34 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 925
35 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :26
36 { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;27
37 { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // 30
40 { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?31
41 { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @32
42 { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A33
43 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B34
44 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C35
45 { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D36
46 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E37
47 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F38
48 { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G39
49 { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H40
50 { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I41
51 { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J42
52 { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K43
53 { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L44
54 { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M45
55 { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N46
56 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O47
57 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P48
58 { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q49
59 { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R50
60 { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S51
61 { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T52
62 { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U53
63 { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V54
64 { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W55
65 { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X56
66 { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y57
67 { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z58
68 { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [59
69 { 0x00, 0x02, 0x04, 0x08, 0x10, 0x20 }, // \60
70 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]61
71 { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^62
72 { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _63
73 { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '64
74 { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a65
75 { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b66
76 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c67
77 { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d68
78 { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e69
79 { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f70
80 { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g71
81 { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h72
82 { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i73
83 { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j74
84 { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k75
85 { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l76
86 { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m77
87 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n78
88 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o79
89 { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p80
90 { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q81
91 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r82
92 { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s83
93 { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t84
94 { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u85
95 { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v86
96 { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w87
97 { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x88
98 { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y89
99 { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z90
100 { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines91
101 };
102
103 const u8 code F8X16[]=
104 {
105 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
106 0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,//!1
107 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
108 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
109 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
110 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
111 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
112 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
113 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
114 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
115 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
116 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
117 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
118 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
119 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
120 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
121 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
122 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
123 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
124 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
125 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
126 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
127 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
128 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
129 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
130 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
131 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
132 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
133 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//30
136 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
137 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
138 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
139 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
140 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
141 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
142 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
143 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
144 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
145 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
146 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
147 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
148 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
149 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
150 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
151 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
152 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
153 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
154 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
155 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
156 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
157 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
158 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
159 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
160 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
161 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
162 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
163 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
164 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
165 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
166 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
167 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
168 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
169 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
170 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
171 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
172 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
173 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
174 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
175 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
176 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
177 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
178 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
179 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
180 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
181 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
182 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
183 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
184 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
185 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
186 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
187 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
188 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
189 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
190 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
191 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
192 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
193 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
194 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
195 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
196 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
197 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
198 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
199 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
200 };
201
202
203
204 const u8 code F14x16_Idx[] =
205 {
206 "星期一二日六五四三"
207 };
208
209 //中文字符串编码
210 const u8 code F14x16[] =
211
212 {
213
214 0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,
215 0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,//星
216 0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,
217 0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,//期
218 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
219 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//一
220 0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
221 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,//二
222 0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,
223 0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,//日
224 0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,
225 0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,//六
226 0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,
227 0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,//五
228 0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,
229 0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,//四
230 0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,
231 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20//三
232
233 };
234
235
236 void OLED_WriteCmd(u8 Cmd)
237 {
238 u8 i=8 ;
239 OLED_DC=0;
240 OLED_SCLK=0;
241 while(i--)
242 {
243 if(Cmd&0x80)
244 {
245 OLED_SDA=1;
246 }
247 else
248 {
249 OLED_SDA=0;
250 }
251 OLED_SCLK= 1;
252 _nop_();
253 OLED_SCLK=0;
254 Cmd122)
361 {
362 x=0;
363 y++;
364 }
365 OLED_SetPos(x,y);
366 for(i=0;i122)
382 {
383 x=0;
384 y++;
385 }
386 OLED_SetPos(x,y);
387 for(i=0;i 127)
482 {
483 if(F14x16_Idx[i]==ucDataStr[j])
484 {
485 if(F14x16_Idx[i + 1]==ucDataStr[j + 1])
486 {
487 usAddress = i * 14;
488 break;
489 }
490 }
491
492 i += 2;
493 }
494
495 if(x > 114)
496 {
497 x = 0;
498 y += 2;
499 }
500
501 if(usAddress != 1)// 显示汉字
502 {
503 OLED_SetPos(x, y);
504 for(i = 0; i < 14; i++)
505 {
506 OLED_WriteDat(F14x16[usAddress]);
507 usAddress++;
508 }
509
510 OLED_SetPos(x,y + 1);
511 for(i = 0;i < 14;i++)
512 {
513 OLED_WriteDat(F14x16[usAddress]);
514 usAddress++;
515 }
516 j+=2;
517 }
518 else
519 {
520 OLED_SetPos(x,y);
521 for(i=0;i 127)
554 {
555 ucTmpStr[0] = ucDataStr[i];
556 ucTmpStr[1] = ucDataStr[i + 1];
557 ucTmpStr[2] = '\0'; //汉字为两个字节
558 LED_P14x16Str(x, y, ucTmpStr); //显示汉字
559 x += 14;
560 i += 2;
561 }
562 else
563 {
564 ucTmpStr[0] = ucDataStr[i];
565 ucTmpStr[1] = '\0'; //字母占一个字节
566 OLED_P8x16Str(x, y, ucTmpStr); //显示字母
567 x += 8;
568 i += 1;
569 }
570 }
571
572 return;
573 }
574 /*****************************************************************************
575 函 数 名 : LED_PrintImage
576 功能描述 : 将图像显示出来
577 输入参数 : UCHAR8 *pucTable 二维图像数组的地址
578 USHORT16 usRowNum 二维图像的行数1~64
579 USHORT16 usColumnNum 二维图像的列数1~128
580 输出参数 : none
581 返 回 值 : none
582 *****************************************************************************/
583 void LED_PrintImage(u8 *pucTable, u16 usRowNum, u16 usColumnNum)
584 {
585 u8 ucData;
586 u16 i,j,k,m,n;
587 u16 usRowTmp;
588
589 m = usRowNum >> 3; //计算图片行数以8位为一组完整的组数
590 n = usRowNum % 8; //计算分完组后剩下的行数
591
592 for(i = 0; i < m; i++) //完整组行扫描
593 {
594 OLED_SetPos(0,(u8)i);
595 usRowTmp = i > 1;
602 if((pucTable + (usRowTmp + k) * usColumnNum)[j] == 128)
603 {
604 ucData = ucData | 0x80;
605 }
606
607 }
608 OLED_WriteDat(ucData);
609 }
610 }
611
612 OLED_SetPos(0,(u8)i); //设置剩下的行显示的起始坐标
613 usRowTmp = i > 1;
620 if((pucTable + (usRowTmp + k) * usColumnNum)[j] == 128)
621 {
622 ucData = ucData | 0x80;
623 }
624
625 }
626 ucData = ucData >> (8 - n);
627 OLED_WriteDat(ucData);
628 }
629
630 return;
631 }
632
633
oled.c
DS1302时钟芯片
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 1 #define _DS1302_C
2 2 #include"config.h"
3 3 #include"ds1302.h"
4 4
5 5 u8 code READ_RTC_ADDR[7] = {0x8d,0x89,0x87,0x8b,0x85,0x83,0x81};
6 6 u8 code WRITE_RTC_ADDR[7] = {0x8c,0x88,0x86,0x8a,0x84,0x82,0x80};
7 7
8 8 //---DS1302时钟初始化2016年5月7日星期六12点00分00秒。---//
9 9 //---存储顺序是秒分时日月周年,存储格式是用BCD码---//
10 10 u8 time[7] = {0x19,0x04,0x12,0x05,0x21,0x43,0};
11 11
12 12 /*******************************************************************************
13 13 * 函 数 名 : Ds1302Write
14 14 * 函数功能 : 向DS1302命令(地址+数据)
15 15 * 输 入 : addr,dat
16 16 * 输 出 : 无
17 17 *******************************************************************************/
18 18
19 19 void Ds1302Write(u8 addr, u8 dat)
20 20 {
21 21 u8 n;
22 22 DS_RST = 0;
23 23 _nop_();
24 24
25 25 DS_SCLK = 0;//先将SCLK置低电平。
26 26 _nop_();
27 27 DS_RST = 1; //然后将RST(CE)置高电平。
28 28 _nop_();
29 29
30 30 for (n=0; n>= 1;
34 34 DS_SCLK = 1;//数据在上升沿时,DS1302读取数据
35 35 _nop_();
36 36 DS_SCLK = 0;
37 37 _nop_();
38 38 }
39 39 for (n=0; n>= 1;
43 43 DS_SCLK = 1;//数据在上升沿时,DS1302读取数据
44 44 _nop_();
45 45 DS_SCLK = 0;
46 46 _nop_();
47 47 }
48 48
49 49 DS_RST = 0;//传送数据结束
50 50 _nop_();
51 51 }
52 52
53 53 /*******************************************************************************
54 54 * 函 数 名 : Ds1302Read
55 55 * 函数功能 : 读取一个地址的数据
56 56 * 输 入 : addr
57 57 * 输 出 : dat
58 58 *******************************************************************************/
59 59
60 60 u8 Ds1302Read(u8 addr)
61 61 {
62 62 u8 n,dat,dat1;
63 63 DS_RST = 0;
64 64 _nop_();
65 65
66 66 DS_SCLK = 0;//先将SCLK置低电平。
67 67 _nop_();
68 68 DS_RST = 1;//然后将RST(CE)置高电平。
69 69 _nop_();
70 70
71 71 for(n=0; n>= 1;
75 75 DS_SCLK = 1;//数据在上升沿时,DS1302读取数据
76 76 _nop_();
77 77 DS_SCLK = 0;//DS1302下降沿时,放置数据
78 78 _nop_();
79 79 }
80 80 _nop_();
81 81 for(n=0; n>1) | (dat1无 Mode->无 静音->ESC
9 {0x44,0x00}, {0x40,0x25}, {0x43,0x27}, //播放->无 后退->向左 前进->向右
10 {0x07,0x00}, {0x15,0x28}, {0x09,0x26}, // EQ->无 减号->向下 加号->向上
11 {0x16, '0'}, {0x19,0x1B}, {0x0D,0x0D}, //'0'->'0' 箭头->ESC U/SD->回车
12 {0x0C, '1'}, {0x18, '2'}, {0x5E, '3'}, //'1'->'1' '2'->'2' '3'->'3'
13 {0x08, '4'}, {0x1C, '5'}, {0x5A, '6'}, //'4'->'4' '5'->'5' '6'->'6'
14 {0x42, '7'}, {0x52, '8'}, {0x4A, '9'}, //'7'->'7' '6'->'8' '9'->'9'
15 };
16 bit irflag=0;
17 u8 ircode[4];
18
19 void InfraredDriver()
20 {
21 u8 i;
22
23 if (irflag)
24 {
25 irflag = 0;
26 for (i=0; i=0x40)
58 {
59 break;
60 }
61 }
62 TR1=0;
63 return (TH1*256+TL1);
64 }
65
66 u16 GetLowTime()
67 {
68 TH1=0;
69 TL1=0;
70 TR1=1;
71 while(!IRIN)
72 { if(TH1>=0x40)
73 {
74 break;
75 }
76 }
77 TR1=0;
78 return (TH1*256+TL1);
79 }
80
81
82 void outinterrupt() interrupt 0
83 {
84 u8 i,j;
85 u8 byt;
86 u16 time;
87
88 time = GetLowTime();
89 if((time9500))
90 {
91 IE0=0;
92 return;
93 }
94
95 time=GetHighTime();
96 if((time=5000))
97 { IE0=0;
98 return;
99 }
100
101 for(i=0;i=1;
115 }
116 else if((time>=1460)&&(time>=1;
119 byt|=0x80;
120 }
121 else
122 {
123 IE0=0;
124 return;
125 }
126 }
127 ircode[i]=byt;
128 }
129 irflag=1;
130 IE0=0;
131 }
132
Infrared.c
显示层代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #define _TIME_C
2 #include"config.h"
3 #include"OLED.h"
4 #include"DS1302.h"
5 #include"main.h"
6 #include"Time.h"
7 #include"LedBuzzer.h"
8
9 u8 xingqi[7][6]={"星期1","星期2","星期3","星期4",
10 "星期5","星期6","星期7"};
11
12 bit staMute = 0;
13
14 u8 AlarmHour = 0x07;
15 u8 AlarmMin = 0x30;
16
17 u8 SetIndex = 0;
18
19 u8 pdata SetAlarmHour;
20 u8 pdata SetAlarmHour; //闹钟小时数设置缓冲
21 u8 pdata SetAlarmMin; //闹钟分钟数设置缓冲
22 u8 pdata SetTime[7];
23
24 u8 str1[11], str3[9], *str2;
25
26
27 void RefreshTime()
28 {
29 Ds1302ReadTime();
30 str3[0]=(time[4] >> 4) + '0';
31 str3[1]=(time[4]&0x0f)+'0';
32 str3[2]=':';
33 str3[3]=(time[5]>>4)+'0';
34 str3[4]=(time[5]&0x0f)+'0';
35 str3[5]=':';
36 str3[6]=(time[6]>>4)+'0';
37 str3[7]= (time[6]&0x0f)+'0';
38 str3[8]='\0';
39 str2 =xingqi[(time[3]&0x0f)-1];
40 OLED_P8x16Str(30,2,(u8*)str3);
41 OLED_P14x16Str(88,0,(u8*)str2);
42 }
43
44 void RefreshDate(u8 ops)
45 {
46 u8 backup=0;
47
48 if((backup!=time[2])||ops!=0)
49 {
50 str1[0] = '2';
51 str1[1] = '0';
52 str1[2] = (time[0] >> 4) + '0';
53 str1[3] = (time[0]&0x0f) + '0';
54 str1[4] = '/';
55 str1[5] = (time[1] >> 4) + '0';
56 str1[6] = (time[1]&0x0F) + '0';
57 str1[7] = '/';
58 str1[8] = (time[2] >> 4) + '0';
59 str1[9] = (time[2]&0x0F) + '0';
60 str1[10] = '\0';
61 OLED_P8x16Str(0, 0, (u8*)str1);
62 backup=time[2];
63 }
64 }
65
66 void RefreshAlarm()
67 {
68 u8 pdata str[6];
69
70 OLED6x8Showstr(0,7,"Alarm ");
71 str[0] = (AlarmHour >> 4) + '0'; //闹钟小时数
72 str[1] = (AlarmHour & 0x0F) + '0';
73 str[2] = ':'; //分隔符
74 str[3] = (AlarmMin >> 4) + '0'; //闹钟分钟数
75 str[4] = (AlarmMin & 0x0F) + '0';
76 str[5] = '\0';
77 OLED6x8Showstr(40,7,(u8*)str);
78 }
79
80
81 void AlarmMonitor()
82 {
83 if((time[4]==AlarmHour)&&(time[5]==AlarmMin))
84 {
85 if (!staMute) //检查是否静音
86 staBuzzer = ~staBuzzer; //实现蜂鸣器断续鸣叫
87 else
88 staBuzzer = 0;
89 }
90 else
91 {
92 staMute = 0;
93 staBuzzer = 0;
94 }
95 }
96
97 void ShowSetTime()
98 {
99 u8 pdata str4[6];
100 str1[0] = (SetTime[0]>>4) + '0'; //2位数年份
101 str1[1] = (SetTime[0] & 0x0F) + '0';
102 str1[2] = '/';
103 str1[3] = (SetTime[1] >> 4) + '0'; //月份
104 str1[4] = (SetTime[1] & 0x0F) + '0';
105 str1[5] = '/';
106 str1[6] = (SetTime[2] >> 4) + '0'; //日期
107 str1[7] = (SetTime[2] & 0x0F) + '0';
108 str1[8] = '\0';
109 str2 =xingqi[(SetTime[3]&0x0f)-1]; //星期
110
111 str4[0] = (SetTime[4] >> 4) + '0'; //小时
112 str4[1] = (SetTime[4] & 0x0F) + '0';
113 str4[2] = ':';
114 str4[3] = (SetTime[5] >> 4) + '0'; //分钟
115 str4[4] = (SetTime[5] & 0x0F) + '0';
116 str4[5] = '\0';
117
118 OLED_P8x16Str(0,0,"Set Data Time");
119 OLED_P8x16Str(0, 2, (u8*)str1);
120 OLED_P14x16Str(88,2,(u8*)str2);
121 OLED6x8Showstr(30,7,(u8*)str4);
122 }
123
124 void ShowSetAlarm()
125 { u8 pdata str[8];
126 str[0] = (SetAlarmHour >> 4) + '0'; //小时
127 str[1] = (SetAlarmHour & 0x0F) + '0';
128 str[2] = ':';
129 str[3] = (SetAlarmMin >> 4) + '0'; //分钟
130 str[4] = (SetAlarmMin & 0x0F) + '0';
131 str[5] = '\0';
132 OLED_P8x16Str(0,0,"Set Alarm");
133 OLED_P8x16Str(45,2,(u8*)str);
134 }
135
136 void CancelCurSet()
137 {
138 staSystem = E_NORMAL;
139 OledInit();
140 RefreshTime(); //刷新当前时间
141 RefreshDate(1); //立即刷新日期显示
142 RefreshAlarm();
143 }
144
145 void SetRealTime()
146 {
147 u8 n;
148 Ds1302Write(0x8E,0X00); //禁止写保护,就是关闭写保护功能
149 for (n=0; n>8); //定时器重载值拆分为高低字节
53 T0RL = (u8)tmp;
54 TMOD &= 0xF0; //清零T0的控制位
55 TMOD |= 0x01; //配置T0为模式1
56 TH0 = T0RH; //加载T0重载值
57 TL0 = T0RL;
58 ET0 = 1; //使能T0中断
59 TR0 = 1; //启动T0
60 }
61 /* T0中断服务函数,实现系统定时和按键扫描 */
62
63 void InterruptTimer0() interrupt 1
64 {
65
66 static u8 tmr200ms = 0;
67
68 TH0 = T0RH; //重新加载重载值
69 TL0 = T0RL;
70 tmr200ms++; //定时200ms
71 if (tmr200ms >= 200)
72 {
73 tmr200ms = 0;
74 flag200ms = 1;
75 }
76
77 }
main.c
蜂鸣器代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #define _LED_BUZZER_C
2 #include"config.h"
3 #include"LedBuzzer.h"
4
5 bit staBuzzer=0;
6
7 void InitLed()
8 {
9 T2CON=0x00;
10 RCAP2H=((65536-SYS_MCLK/1500)>>8);
11 RCAP2L=(65536-SYS_MCLK/1500);
12 TH2=RCAP2H;
13 TL2=RCAP2L;
14 ET2=1;
15 PT2=1;
16 TR2=1;
17 }
18
19
20 void interruptTime2() interrupt 5
21 {
22
23 TF2=0;
24
25
26 if(staBuzzer == 1)
27 BUZZER=~BUZZER;
28 else
29 BUZZER=1;
30
31 }
Buff.c
除引脚申明头文件,其他头文件就不附上啦
![](https://img2018.cnblogs.com/blog/1578282/201904/1578282-20190418190334097-117274724.png)
U/SD转换模式,RPT回到最初显示模式,||设置位向左向右移动,静音符号关闭闹铃,0~9输出时间设置数字。
欢迎大家指正(☆▽☆)
|