这个红外遥控主要是程序通过对按下的键的键码进行解析,并运行相应的功能代码

一次按键动作的遥控编码信息为 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接地。

引脚申明类型说明

 #ifndef _CONFIG_H_
#define _CONFIG_H_ #include"reg52.h"
#include"intrins.h" typedef signed char int8;
typedef signed int int16;
typedef unsigned int u16;
typedef unsigned char u8;
typedef signed long int32; #define LED P2
#define SYS_MCLK 1000000 sbit GPIO_KEY=P1; sbit OLED_SCLK=P1^; //D0时钟管脚
sbit OLED_SDA=P1^; //D1数据管脚
sbit OLED_RST=P1^; //电源复位,低电平有效
sbit OLED_DC=P1^; //数据或命令控制管脚 sbit DS_IO=P3^ ;
sbit DS_SCLK=P3^;
sbit DS_RST=P3^; sbit BUZZER=P1^; sbit DSPORT=P3^; sbit IRIN=P3^; #endif

oled显示屏代码 

 #define _OLED_C
#include"config.h"
#include"OLED.h"
#define _OLED_C
void OLED_SetPos(u8 x,u8 y);
//命令函数
const u8 code F6x8[][] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //sp0
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !1
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "2
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #3
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $4
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %5
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &6
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '7
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (8
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )9
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *10
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +11
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,12
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -13
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .14
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /15
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, //
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, //
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, //
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, //
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, //
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, //
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, //
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, //
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, //
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, //
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :26
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;27
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <28
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =29
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >30
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?31
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @32
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A33
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B34
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C35
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D36
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E37
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F38
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G39
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H40
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I41
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J42
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K43
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L44
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M45
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N46
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O47
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P48
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q49
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R50
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S51
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T52
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U53
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V54
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W55
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X56
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y57
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z58
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [59
{ 0x00, 0x02, 0x04, 0x08, 0x10, 0x20 }, // \60
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]61
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^62
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _63
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '64
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a65
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b66
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c67
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d68
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e69
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f70
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g71
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h72
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i73
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j74
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k75
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l76
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m77
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n78
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o79
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p80
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q81
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r82
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s83
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t84
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u85
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v86
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w87
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x88
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y89
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z90
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines91
}; const u8 code F8X16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,//!1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
}; const u8 code F14x16_Idx[] =
{
"星期一二日六五四三"
}; //中文字符串编码
const u8 code F14x16[] = { 0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,
0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,//星
0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,
0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,//期
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//一
0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,//二
0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,//日
0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,//六
0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,
0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,//五
0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,//四
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20//三 }; void OLED_WriteCmd(u8 Cmd)
{
u8 i= ;
OLED_DC=;
OLED_SCLK=;
while(i--)
{
if(Cmd&0x80)
{
OLED_SDA=;
}
else
{
OLED_SDA=;
}
OLED_SCLK= ;
_nop_();
OLED_SCLK=;
Cmd<<=;
}
return;
} void OLED_WriteDat(u8 Dat)
{
u8 i= ;
OLED_DC=;
OLED_SCLK=;
while(i--)
{
if(Dat&0x80)
{
OLED_SDA=;
}
else
{
OLED_SDA=;
}
OLED_SCLK= ;
_nop_();
OLED_SCLK=;
Dat<<=;
} return;
} void OLED_FILL(u8 date)
{
u8 Page,Column;
for( Page=;Page<;Page++)
{
OLED_WriteCmd(0xb0+Page);
OLED_WriteCmd(0x00);
OLED_WriteCmd(0x10);
for(Column=;Column<;Column++)
{
OLED_WriteDat( date );
}
}
} //初始化 void OledInit()
{ u8 i; OLED_SCLK = ;
OLED_RST = ; for(i = ; i < ; i++)
{
_nop_(); //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕
} OLED_RST = ;
OLED_WriteCmd(0xae);
OLED_WriteCmd(0x00);
OLED_WriteCmd(0x10);
OLED_WriteCmd(0x40);
OLED_WriteCmd(0x81);
OLED_WriteCmd(0xcf);
OLED_WriteCmd(0xa1);
OLED_WriteCmd(0xc8);
OLED_WriteCmd(0xa6);
OLED_WriteCmd(0xa8);
OLED_WriteCmd(0x3f);
OLED_WriteCmd(0xd3);
OLED_WriteCmd(0x00);
OLED_WriteCmd(0xd5);
OLED_WriteCmd(0x80);
OLED_WriteCmd(0xd9);
OLED_WriteCmd(0xf1);
OLED_WriteCmd(0xda);
OLED_WriteCmd(0x12);
OLED_WriteCmd(0xdb);
OLED_WriteCmd(0x40);
OLED_WriteCmd(0x20);
OLED_WriteCmd(0x02);
OLED_WriteCmd(0x8d);
OLED_WriteCmd(0x14);
OLED_WriteCmd(0xa4);
OLED_WriteCmd(0xa6);
OLED_WriteCmd(0xaf);
OLED_FILL(0x00);
OLED_SetPos(,);
} void OLED_SetPos(u8 x,u8 y)
{
OLED_WriteCmd(0xb0 + y);
OLED_WriteCmd(((x & 0xf0)>> ) | 0x10);
OLED_WriteCmd((x & 0x0f) | 0x01);
} void OLED6x8Showstr(u8 x,u8 y,u8 str[])
{ u8 c=,i=,j=;
while(str[j]!='\0')
{
c=str[j]-;
if(x>)
{
x=;
y++;
}
OLED_SetPos(x,y);
for(i=;i<;i++)
{
OLED_WriteDat(F6x8[c][i]);
}
x+=;
j++;
}
return;
}
void OLED_6x8C(u8 x,u8 y,u8 ascii)
{ u8 c=,i=,j=; c=ascii-;
if(x>)
{
x=;
y++;
}
OLED_SetPos(x,y);
for(i=;i<;i++)
{
OLED_WriteDat(F6x8[c][i]);
}
x+=;
j++;
return;
}
void OLED_8x16C(u8 x,u8 y, u8 ascii)
{
u8 i,j=,ucDataTmp; y <<= ; ucDataTmp = ascii - ; if(x > )
{
x = ;
y += ;
} OLED_SetPos(x, y); for(i = ; i < ; i++)
{
OLED_WriteDat(F8X16[(ucDataTmp << ) + i]);
} OLED_SetPos(x, y + ); for(i = ; i < ; i++)
{
OLED_WriteDat(F8X16[(ucDataTmp << ) + i + ]);
}
x += ; return;
} void OLED_P8x16Str(u8 x, u8 y, u8 ucDataStr[])
{
u8 i, j, ucDataTmp; y <<= ; for (j = ; ucDataStr[j] != '\0'; j++)
{
ucDataTmp = ucDataStr[j] - ; if(x > )
{
x = ;
y += ;
} OLED_SetPos(x, y); for(i = ; i < ; i++)
{
OLED_WriteDat(F8X16[(ucDataTmp << ) + i]);
} OLED_SetPos(x, y + ); for(i = ; i < ; i++)
{
OLED_WriteDat(F8X16[(ucDataTmp << ) + i + ]);
}
x += ; } return;
} void LED_P14x16Str(u8 x, u8 y, u8 ucDataStr[])
{
u8 i, j;
u16 usAddress; y <<= ; j = ;
while(ucDataStr[j] != '\0')
{
i = ;
usAddress = ;
while(F14x16_Idx[i] > )
{
if(F14x16_Idx[i]==ucDataStr[j])
{
if(F14x16_Idx[i + ]==ucDataStr[j + ])
{
usAddress = i * ;
break;
}
} i += ;
} if(x > )
{
x = ;
y += ;
} if(usAddress != )// 显示汉字
{
OLED_SetPos(x, y);
for(i = ; i < ; i++)
{
OLED_WriteDat(F14x16[usAddress]);
usAddress++;
} OLED_SetPos(x,y + );
for(i = ;i < ;i++)
{
OLED_WriteDat(F14x16[usAddress]);
usAddress++;
}
j+=;
}
else
{
OLED_SetPos(x,y);
for(i=;i<;i++)
{
OLED_WriteDat();
}
OLED_SetPos(x,y+);
for(i=;i<;i++)
{
OLED_WriteDat();
}
j++;
}
x+=;
}
return;
} /*****************************************************************************
函 数 名 : LED_PXx16MixStr
功能描述 : 输出14x16汉字和字符混合字符串 (字符串表格中需含有此字)
输入参数 : UCHAR8 ucIdxX 为显示的横坐标0~114
UCHAR8 ucIdxY 为页范围0~3
UCHAR8 ucDataStr[] 要显示的中文字符串
输出参数 : NONE
返 回 值 : NONE
*****************************************************************************/
void OLED_P14x16Str(u8 x, u8 y, u8 ucDataStr[])
{
u8 ucTmpStr[];
u8 i = ; while(ucDataStr[i] != '\0')
{
if(ucDataStr[i] > )
{
ucTmpStr[] = ucDataStr[i];
ucTmpStr[] = ucDataStr[i + ];
ucTmpStr[] = '\0'; //汉字为两个字节
LED_P14x16Str(x, y, ucTmpStr); //显示汉字
x += ;
i += ;
}
else
{
ucTmpStr[] = ucDataStr[i];
ucTmpStr[] = '\0'; //字母占一个字节
OLED_P8x16Str(x, y, ucTmpStr); //显示字母
x += ;
i += ;
}
} return;
}
/*****************************************************************************
函 数 名 : LED_PrintImage
功能描述 : 将图像显示出来
输入参数 : UCHAR8 *pucTable 二维图像数组的地址
USHORT16 usRowNum 二维图像的行数1~64
USHORT16 usColumnNum 二维图像的列数1~128
输出参数 : none
返 回 值 : none
*****************************************************************************/
void LED_PrintImage(u8 *pucTable, u16 usRowNum, u16 usColumnNum)
{
u8 ucData;
u16 i,j,k,m,n;
u16 usRowTmp; m = usRowNum >> ; //计算图片行数以8位为一组完整的组数
n = usRowNum % ; //计算分完组后剩下的行数 for(i = ; i < m; i++) //完整组行扫描
{
OLED_SetPos(,(u8)i);
usRowTmp = i << ; //计算当前所在行的下标
for(j = ; j < usColumnNum; j++) //列扫描
{
ucData = ;
for(k = ; k < ; k++) //在i组中对这8行扫描
{
ucData = ucData >> ;
if((pucTable + (usRowTmp + k) * usColumnNum)[j] == )
{
ucData = ucData | 0x80;
} }
OLED_WriteDat(ucData);
}
} OLED_SetPos(,(u8)i); //设置剩下的行显示的起始坐标
usRowTmp = i << ; //计算当前所在行的下标
for(j = ; j < usColumnNum; j++) //列扫描
{
ucData = ;
for(k = ; k < n; k++) //对剩下的行扫描
{
ucData = ucData >> ;
if((pucTable + (usRowTmp + k) * usColumnNum)[j] == )
{
ucData = ucData | 0x80;
} }
ucData = ucData >> ( - n);
OLED_WriteDat(ucData);
} return;
}

oled.c

DS1302时钟芯片

    #define _DS1302_C
#include"config.h"
#include"ds1302.h" u8 code READ_RTC_ADDR[] = {0x8d,0x89,0x87,0x8b,0x85,0x83,0x81};
u8 code WRITE_RTC_ADDR[] = {0x8c,0x88,0x86,0x8a,0x84,0x82,0x80}; //---DS1302时钟初始化2016年5月7日星期六12点00分00秒。---//
//---存储顺序是秒分时日月周年,存储格式是用BCD码---//
u8 time[] = {0x19,0x04,0x12,0x05,0x21,0x43,}; /*******************************************************************************
13 * 函 数 名 : Ds1302Write
14 * 函数功能 : 向DS1302命令(地址+数据)
15 * 输 入 : addr,dat
16 * 输 出 : 无
17 *******************************************************************************/ void Ds1302Write(u8 addr, u8 dat)
{
u8 n;
DS_RST = ;
_nop_(); DS_SCLK = ;//先将SCLK置低电平。
_nop_();
DS_RST = ; //然后将RST(CE)置高电平。
_nop_(); for (n=; n<; n++)//开始传送八位地址命令
{
DS_IO = addr & 0x01;//数据从低位开始传送
addr >>= ;
DS_SCLK = ;//数据在上升沿时,DS1302读取数据
_nop_();
DS_SCLK = ;
_nop_();
}
for (n=; n<; n++)//写入8位数据
{
DS_IO = dat & 0x01;
dat >>= ;
DS_SCLK = ;//数据在上升沿时,DS1302读取数据
_nop_();
DS_SCLK = ;
_nop_();
} DS_RST = ;//传送数据结束
_nop_();
} /*******************************************************************************
54 * 函 数 名 : Ds1302Read
55 * 函数功能 : 读取一个地址的数据
56 * 输 入 : addr
57 * 输 出 : dat
58 *******************************************************************************/ u8 Ds1302Read(u8 addr)
{
u8 n,dat,dat1;
DS_RST = ;
_nop_(); DS_SCLK = ;//先将SCLK置低电平。
_nop_();
DS_RST = ;//然后将RST(CE)置高电平。
_nop_(); for(n=; n<; n++)//开始传送八位地址命令
{
DS_IO = addr & 0x01;//数据从低位开始传送
addr >>= ;
DS_SCLK = ;//数据在上升沿时,DS1302读取数据
_nop_();
DS_SCLK = ;//DS1302下降沿时,放置数据
_nop_();
}
_nop_();
for(n=; n<; n++)//读取8位数据
{
dat1 = DS_IO;//从最低位开始接收
dat = (dat>>) | (dat1<<);
DS_SCLK = ;
_nop_();
DS_SCLK = ;//DS1302下降沿时,放置数据
_nop_();
} DS_RST = ;
_nop_(); //以下为DS1302复位的稳定时间,必须的。
DS_SCLK = ;
_nop_();
DS_IO = ;
_nop_();
DS_IO = ;
_nop_();
return dat;
} /*******************************************************************************
103 * 函 数 名 : Ds1302Init
104 * 函数功能 : 初始化DS1302.
105 * 输 入 : 无
106 * 输 出 : 无
107 *******************************************************************************/ void Ds1302Init()
{
u8 n;
Ds1302Write(0x8E,0X00); //禁止写保护,就是关闭写保护功能
for (n=; n<; n++)//写入7个字节的时钟信号:分秒时日月周年
{
Ds1302Write(WRITE_RTC_ADDR[n],time[n]);
}
Ds1302Write(0x8E,0x80); //打开写保护功能
} /*******************************************************************************
122 * 函 数 名 : Ds1302ReadTime
123 * 函数功能 : 读取时钟信息
124 * 输 入 : 无
125 * 输 出 : 无
126 *******************************************************************************/ void Ds1302ReadTime()
{
u8 n;
for (n=; n<; n++)//读取7个字节的时钟信号:分秒时日月周年
{
time[n] = Ds1302Read(READ_RTC_ADDR[n]);
} }

DS1302.c

红外遥控代码

 #define _INFRARED_C
#include"config.h"
#include"Infrared.h"
#include"Time.h" const u8 code IrCodeMap[][] = { //红外键码到标准PC键码的映射表
{0x45,0x00}, {0x46,0x00}, {0x47,0x1B}, //开关->无 Mode->无 静音->ESC
{0x44,0x00}, {0x40,0x25}, {0x43,0x27}, //播放->无 后退->向左 前进->向右
{0x07,0x00}, {0x15,0x28}, {0x09,0x26}, // EQ->无 减号->向下 加号->向上
{0x16, ''}, {0x19,0x1B}, {0x0D,0x0D}, //'0'->'0' 箭头->ESC U/SD->回车
{0x0C, ''}, {0x18, ''}, {0x5E, ''}, //'1'->'1' '2'->'2' '3'->'3'
{0x08, ''}, {0x1C, ''}, {0x5A, ''}, //'4'->'4' '5'->'5' '6'->'6'
{0x42, ''}, {0x52, ''}, {0x4A, ''}, //'7'->'7' '6'->'8' '9'->'9'
};
bit irflag=;
u8 ircode[]; void InfraredDriver()
{
u8 i; if (irflag)
{
irflag = ;
for (i=; i<sizeof(IrCodeMap)/sizeof(IrCodeMap[]); i++) //遍历映射表
{
if (ircode[] == IrCodeMap[i][]) //在表中找到当前接收的键码后,
{ //用对应的映射码执行函数调度,
KeyAction(IrCodeMap[i][]); //直接调用按键动作函数即可。
break;
}
}
}
} void InitInfrared()
{
IRIN=;
TMOD&=0x0F;
TMOD|=0x10;
TR1=;
ET1=;
IT0=;
EX0=;
} u16 GetHighTime()
{
TH1=;
TL1=;
TR1=;
while(IRIN)
{
if(TH1>=0x40)
{
break;
}
}
TR1=;
return (TH1*+TL1);
} u16 GetLowTime()
{
TH1=;
TL1=;
TR1=;
while(!IRIN)
{ if(TH1>=0x40)
{
break;
}
}
TR1=;
return (TH1*+TL1);
} void outinterrupt() interrupt
{
u8 i,j;
u8 byt;
u16 time; time = GetLowTime();
if((time<)||(time>))
{
IE0=;
return;
} time=GetHighTime();
if((time<=)||(time>=))
{ IE0=;
return;
} for(i=;i<;i++)
{
for(j=;j<;j++)
{
time=GetLowTime();
if((time<)||(time>))
{
IE0=;
return;
}
time=GetHighTime();
if((time>=)&&(time<=))
{
byt>>=;
}
else if((time>=)&&(time<=))
{
byt>>=;
byt|=0x80;
}
else
{
IE0=;
return;
}
}
ircode[i]=byt;
}
irflag=;
IE0=;
}

Infrared.c

显示层代码

 #define _TIME_C
#include"config.h"
#include"OLED.h"
#include"DS1302.h"
#include"main.h"
#include"Time.h"
#include"LedBuzzer.h" u8 xingqi[][]={"星期1","星期2","星期3","星期4",
"星期5","星期6","星期7"}; bit staMute = ; u8 AlarmHour = 0x07;
u8 AlarmMin = 0x30; u8 SetIndex = ; u8 pdata SetAlarmHour;
u8 pdata SetAlarmHour; //闹钟小时数设置缓冲
u8 pdata SetAlarmMin; //闹钟分钟数设置缓冲
u8 pdata SetTime[]; u8 str1[], str3[], *str2; void RefreshTime()
{
Ds1302ReadTime();
str3[]=(time[] >> ) + '';
str3[]=(time[]&0x0f)+'';
str3[]=':';
str3[]=(time[]>>)+'';
str3[]=(time[]&0x0f)+'';
str3[]=':';
str3[]=(time[]>>)+'';
str3[]= (time[]&0x0f)+'';
str3[]='\0';
str2 =xingqi[(time[]&0x0f)-];
OLED_P8x16Str(,,(u8*)str3);
OLED_P14x16Str(,,(u8*)str2);
} void RefreshDate(u8 ops)
{
u8 backup=; if((backup!=time[])||ops!=)
{
str1[] = '';
str1[] = '';
str1[] = (time[] >> ) + '';
str1[] = (time[]&0x0f) + '';
str1[] = '/';
str1[] = (time[] >> ) + '';
str1[] = (time[]&0x0F) + '';
str1[] = '/';
str1[] = (time[] >> ) + '';
str1[] = (time[]&0x0F) + '';
str1[] = '\0';
OLED_P8x16Str(, , (u8*)str1);
backup=time[];
}
} void RefreshAlarm()
{
u8 pdata str[]; OLED6x8Showstr(,,"Alarm ");
str[] = (AlarmHour >> ) + ''; //闹钟小时数
str[] = (AlarmHour & 0x0F) + '';
str[] = ':'; //分隔符
str[] = (AlarmMin >> ) + ''; //闹钟分钟数
str[] = (AlarmMin & 0x0F) + '';
str[] = '\0';
OLED6x8Showstr(,,(u8*)str);
} void AlarmMonitor()
{
if((time[]==AlarmHour)&&(time[]==AlarmMin))
{
if (!staMute) //检查是否静音
staBuzzer = ~staBuzzer; //实现蜂鸣器断续鸣叫
else
staBuzzer = ;
}
else
{
staMute = ;
staBuzzer = ;
}
} void ShowSetTime()
{
u8 pdata str4[];
str1[] = (SetTime[]>>) + ''; //2位数年份
str1[] = (SetTime[] & 0x0F) + '';
str1[] = '/';
str1[] = (SetTime[] >> ) + ''; //月份
str1[] = (SetTime[] & 0x0F) + '';
str1[] = '/';
str1[] = (SetTime[] >> ) + ''; //日期
str1[] = (SetTime[] & 0x0F) + '';
str1[] = '\0';
str2 =xingqi[(SetTime[]&0x0f)-]; //星期 str4[] = (SetTime[] >> ) + ''; //小时
str4[] = (SetTime[] & 0x0F) + '';
str4[] = ':';
str4[] = (SetTime[] >> ) + ''; //分钟
str4[] = (SetTime[] & 0x0F) + '';
str4[] = '\0'; OLED_P8x16Str(,,"Set Data Time");
OLED_P8x16Str(, , (u8*)str1);
OLED_P14x16Str(,,(u8*)str2);
OLED6x8Showstr(,,(u8*)str4);
} void ShowSetAlarm()
{ u8 pdata str[];
str[] = (SetAlarmHour >> ) + ''; //小时
str[] = (SetAlarmHour & 0x0F) + '';
str[] = ':';
str[] = (SetAlarmMin >> ) + ''; //分钟
str[] = (SetAlarmMin & 0x0F) + '';
str[] = '\0';
OLED_P8x16Str(,,"Set Alarm");
OLED_P8x16Str(,,(u8*)str);
} void CancelCurSet()
{
staSystem = E_NORMAL;
OledInit();
RefreshTime(); //刷新当前时间
RefreshDate(); //立即刷新日期显示
RefreshAlarm();
} void SetRealTime()
{
u8 n;
Ds1302Write(0x8E,0X00); //禁止写保护,就是关闭写保护功能
for (n=; n<; n++)//写入7个字节的时钟信号:分秒时日月周年
{
Ds1302Write(WRITE_RTC_ADDR[n],SetTime[n]);
}
Ds1302Write(0x8E,0x80); //打开写保护功能
} void SetRightShift()
{
if (staSystem == E_SET_TIME)
{
switch (SetIndex)
{
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
default: SetIndex=; break;
}
}
else if (staSystem == E_SET_ALARM)
{
switch (SetIndex)
{
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
default: SetIndex=; break;
}
}
} void SetLeftShift()
{
if (staSystem == E_SET_TIME)
{
switch (SetIndex)
{
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
default: SetIndex=; break;
}
} else if (staSystem == E_SET_ALARM)
{
switch (SetIndex)
{
case : SetIndex=; break;
case : SetIndex=; break;
case : SetIndex=; break;
default: SetIndex=; break;
}
}
}
void InputSetNumber(u8 ascii)
{
u8 num; num = ascii - '';
if (num <= ) //只响应0~9的数字
{
if (staSystem == E_SET_TIME)
{
switch (SetIndex)
{
case : SetTime[] = (SetTime[]&0x0F)|(num<<);
OLED_8x16C(, ,ascii); break; //年份高位数字
case : SetTime[] = (SetTime[]&0xF0)|(num);
OLED_8x16C(, , ascii); break; //年份低位数字
case : SetTime[] = (SetTime[]&0x0F)|(num<<);
OLED_8x16C(, , ascii); break; //月份高位数字
case : SetTime[] = (SetTime[]&0xF0)|(num);
OLED_8x16C(, , ascii); break; //月份低位数字
case : SetTime[] = (SetTime[]&0x0F)|(num<<);
OLED_8x16C(, , ascii); break; //日期高位数字
case : SetTime[] = (SetTime[]&0xF0)|(num);
OLED_8x16C(, , ascii); break; //日期低位数字
case : SetTime[] = (SetTime[]&0xF0)|(num);
OLED_P14x16Str(,,(u8*)(xingqi[(SetTime[]&0x0f)-])); break; //星期数字
case : SetTime[] = (SetTime[]&0x0F)|(num<<);
OLED_6x8C(,, ascii); break; //小时高位数字
case : SetTime[] = (SetTime[]&0xF0)|(num);
OLED_6x8C(,, ascii); break; //小时低位数字
case : SetTime[]= (SetTime[]&0x0F)|(num<<);
OLED_6x8C(,, ascii); break; //分钟高位数字
default:SetTime[] = (SetTime[]&0xF0)|(num);
OLED_6x8C(,, ascii); break; //分钟低位数字
}
SetRightShift(); //完成该位设置后自动右移
}
else if (staSystem == E_SET_ALARM)
{
switch (SetIndex)
{
case : SetAlarmHour = (SetAlarmHour&0x0F) | (num<<);
OLED_8x16C(,, ascii); break; //小时高位数字
case : SetAlarmHour = (SetAlarmHour&0xF0) | (num);
OLED_8x16C(,, ascii); break; //小时低位数字
case : SetAlarmMin = (SetAlarmMin&0x0F) | (num<<);
OLED_8x16C(,, ascii); break; //分钟高位数字
default:SetAlarmMin = (SetAlarmMin&0xF0) | (num);
OLED_8x16C(,, ascii); break; //分钟低位数字
}
SetRightShift(); //完成该位设置后自动右移
}
}
} void SwitchSystemSta()
{
if (staSystem == E_NORMAL)
{
staSystem = E_SET_TIME;
SetTime[] = time[]; //当前时间拷贝到时间设置缓冲区中
SetTime[] = time[];
SetTime[] = time[];
SetTime[] = time[];
SetTime[] = time[];
SetTime[] = time[];
SetTime[] = time[];
OledInit(); //液晶清屏
ShowSetTime(); //显示设置时间
SetIndex = ;
SetRightShift(); }
else if (staSystem == E_SET_TIME) //时间设置切换到闹钟设置
{
staSystem = E_SET_ALARM;
SetTime[] = ; //秒清零,即当设置时间后从0秒开始走时
SetRealTime(); //设定时间写入实时时钟
SetAlarmHour = AlarmHour; //当前闹钟值拷贝到设置缓冲区
SetAlarmMin = AlarmMin;
OledInit(); //液晶清屏
ShowSetAlarm(); //显示设置闹钟
SetIndex = ; //与接下来的右移一起将光标设在最左边的位置上
SetRightShift();
}
else //闹钟设置切换会正常运行
{
staSystem = E_NORMAL;
AlarmHour = SetAlarmHour; //设定的闹钟值写入闹钟时间
AlarmMin = SetAlarmMin;
OledInit(); //液晶清屏
RefreshTime(); //刷新当前时间
RefreshDate(); //立即刷新日期显示
RefreshAlarm(); //闹钟设定值显示
}
} /* 按键动作函数,根据键码执行相应的操作,keycode-按键键码 */
void KeyAction(u8 keycode)
{
if ((keycode>='') && (keycode<='')) //数字键输入当前位设定值
{
InputSetNumber(keycode);
}
else if (keycode == 0x25) //向左键,向左切换设置位
{
SetLeftShift();
}
else if (keycode == 0x27) //向右键,向右切换设置位
{
SetRightShift();
}
else if (keycode == 0x0D) //回车键,切换运行状态/保存设置
{
SwitchSystemSta();
}
else if (keycode == 0x1B) //Esc键,静音/取消当前设置
{
if (staSystem == E_NORMAL) //处于正常运行状态时闹铃静音
{
staMute = ;
}
else //处于设置状态时退出设置
{
CancelCurSet();
}
}
}

Time.c

主函数代码

 #define _MAIN_C
#include"config.h" //此文件中定义了单片机的一些特殊功能寄存器
#include"DS18B20.h"
#include"OLED.h"
#include"main.h"
#include"DS1302.h"
#include"LedBuzzer.h"
#include"Infrared.h"
#include"Time.h" //bit flag2s = 0; //2s定时标志位
bit flag200ms = ; //200ms定时标志
u8 T0RH = ; //T0重载值的高字节
u8 T0RL = ; //T0重载值的低字节
enum eStaSystem staSystem = E_NORMAL;
void main()
{
EA = ;
ConfigTimer0();
InitLed();
Ds1302Init();
InitInfrared();
OledInit(); RefreshTime();
RefreshDate();
RefreshAlarm();
while()
{
InfraredDriver();
if(staSystem==E_NORMAL)
{
if(flag200ms)
{
flag200ms=;
RefreshTime();
AlarmMonitor();
RefreshDate();
}
}
}
} void ConfigTimer0(u16 ms)
{
int32 tmp; tmp = (SYS_MCLK*ms)/; //计算所需的计数值
tmp = - tmp; //计算定时器重载值
tmp = tmp + ; //补偿中断响应延时造成的误差
T0RH = (u8)(tmp>>); //定时器重载值拆分为高低字节
T0RL = (u8)tmp;
TMOD &= 0xF0; //清零T0的控制位
TMOD |= 0x01; //配置T0为模式1
TH0 = T0RH; //加载T0重载值
TL0 = T0RL;
ET0 = ; //使能T0中断
TR0 = ; //启动T0
}
/* T0中断服务函数,实现系统定时和按键扫描 */ void InterruptTimer0() interrupt
{ static u8 tmr200ms = ; TH0 = T0RH; //重新加载重载值
TL0 = T0RL;
tmr200ms++; //定时200ms
if (tmr200ms >= )
{
tmr200ms = ;
flag200ms = ;
} }

main.c

蜂鸣器代码

 #define _LED_BUZZER_C
#include"config.h"
#include"LedBuzzer.h" bit staBuzzer=; void InitLed()
{
T2CON=0x00;
RCAP2H=((-SYS_MCLK/)>>);
RCAP2L=(-SYS_MCLK/);
TH2=RCAP2H;
TL2=RCAP2L;
ET2=;
PT2=;
TR2=;
} void interruptTime2() interrupt
{ TF2=; if(staBuzzer == )
BUZZER=~BUZZER;
else
BUZZER=; }

Buff.c

除引脚申明头文件,其他头文件就不附上啦

                                    

U/SD转换模式,RPT回到最初显示模式,|<<,>>|设置位向左向右移动,静音符号关闭闹铃,0~9输出时间设置数字。

欢迎大家指正(☆▽☆)

基于STC89C52的oled红外遥控闹钟的更多相关文章

  1. 红外遥控NEC协议使用总结

    最近做了一个调试红外遥控三色灯的实习,花了一个多月的时间研究基于NEC协议的红外遥控,下面是这次实习技术方面的总结. 一.NEC协议特征: 8位地址和8位命令长度 每次传输两遍地址(用户码)和命令(按 ...

  2. 基于Arduino、STM32进行红外遥控信号接收

    catalogue . 遥控器原理简介 . 红外遥控原理 . 常见红外遥控器红外线信号传输协议 . 遙控器的发展 . 实验过程 . 攻击面 . 基于STM32实现红外信号解码 1. 遥控器原理简介 0 ...

  3. 基于FPGA的红外遥控解码与PC串口通信

    基于FPGA的红外遥控解码与PC串口通信 zouxy09@qq.com http://blog.csdn.net/zouxy09 这是我的<电子设计EDA>的课程设计作业(呵呵,这个月都拿 ...

  4. 基于STM32的红外遥控重点解析

    本文有两个内容:一.红外遥控协议的的讲解:二.解码程序解析(参考正点原子的代码) 红外的介绍.优点.缺点就不给大家说了,进入正题 一.红外遥控协议的的讲解 红外遥控的编码目前广泛使用的是:NEC Pr ...

  5. 基于Arduino的红外遥控

    1.红外接收头介绍  一.什么是红外接收头?  红外遥控器发出的信号是一连串的二进制脉冲码.为了使其在无线传输过程中免受其他红外信号的干扰,通常都是先将其调制在特定的载波频率上,然后再经红外发射二极管 ...

  6. 51单片机tea5767收音机 红外遥控 自动搜台 存台 DIY

    先看效果图: 显示 频道CH , 频率 100.0Mhz 欢迎信息,1602 内置日文平假名, 正好用来显示博主名称. 焊接前,已经万能面包板上试验成功. 焊接完成以后,1602 的D0 - D7 接 ...

  7. Arduino红外遥控系列教程2013——红外转码

    教程三:红外转码教程——用电视遥控器取代机顶盒遥控器 前言前段时间看到了使用红外遥控的X-Bot机器人[链接],感觉很有意思.最近开始玩Arduino与红外,一方面打算将来用于BOXZ的之间的通讯控制 ...

  8. STM32之红外遥控信号自学习实现

    一.序言 很早前就想实现这个红外遥控自学习的这个实验,用于来自己控制房子里如空调等红外遥控设备的自动化,NEC的标准到具体的产品上可能就被厂家定义为不一样了,所以自学习就应该是接收到什么就发送什么,不 ...

  9. arduino红外遥控库IRremote的IRsend类sendRaw函数溢出问题及其解决方法

    最近在调试红外遥控格力空调,在论坛中学到了不少东西.参考: (1)<解决问题系列(4)——红外编码分析利器使用> (2)<315Mhz模块传输替代315Mhz遥控器> 调试环境 ...

随机推荐

  1. python变量前的单下划线(私有变量)和双下划线()

    1.单下划线 变量前的单下划线表示表面上私有 ,但是其实这样的实例变量外部是可以访问的,但是,按照约定俗成的规定,当你看到这样的变量时,意思就是,“虽然我可以被访问,但是,请把我视为私有变量,不要随意 ...

  2. c排序

    #pragma once//如果写头文件 放置头文件重复包含 #include<stdio.h> //定义类型 结构体类型定义 //宏定义 #define //函数申明 void prin ...

  3. java中Long类型和long类型的大小比较

    在开发过程中老犯一些低级错误,基础还得好好加强啊...... 今天遇到这样一个问题,我用 "=="来比较两个Long类型的数据,明明数值都相等,可是结果就是false,后来仔细想想 ...

  4. Spring Cloud Zuul的动态路由怎样做?集成Nacos实现很简单

    一.说明 网关的核心概念就是路由配置和路由规则,而作为所有请求流量的入口,在实际生产环境中为了保证高可靠和高可用,是尽量要避免重启的,所以实现动态路由是非常有必要的:本文主要介绍实现的思路,并且以Na ...

  5. Flink中Periodic水印和Punctuated水印实现原理(源码分析)

    在用户代码中,我们设置生成水印和事件时间的方法assignTimestampsAndWatermarks()中这里有个方法的重载 我们传入的对象分为两种 AssignerWithPunctuatedW ...

  6. unity shader 入门

    1.一个简单的顶点/片元着色器基本结构 Shader "Unity Shaders Book/Chapter 5/Simple Shader" { } SubShader { Pa ...

  7. unity_实用小技巧(空指针错误)

    在游戏开发中,空指针错误是我们最常见也是最容易出现的错误.下面介绍一下博主近期遇见的空指针错误 如上图,有两个类,如果此时我们在图2中调用图1的单例模式可能会出现空指针错误. 原因在于:编译器可能先执 ...

  8. Javaweb简介

    Javaweb简介 一.什么是Javaweb? 在Sun的Java Servlet规范中,对Java Web应用作了这样定义:“Java Web应用由一组Servlet.HTML页.类.以及其它可以被 ...

  9. 使用synchronized获取互斥锁的几点说明

    在并发编程中,多线程同时并发访问的资源叫做临界资源,当多个线程同时访问对象并要求操作相同资源时,分割了原子操作就有可能出现数据的不一致或数据不完整的情况,为避免这种情况的发生,我们会采取同步机制,以确 ...

  10. [C#] 改进SqliteHelper, 减少拼接SQL语句

    说明:开始几个是基本的方法,后面稍微封装了下 public class SqliteHelper { //连接字符串 private static readonly string str = Conf ...