#include "reg51.h"
#include "intrins.h"
#include "LCD1602.h"
sbit TX=P2^0;
sbit KEY=P1^0;
//定义延时
#define delay11us {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}
#define delay12us {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}
//600us
#define High_Low_Wide_H 0XFD
#define High_Low_Wide_L 0xA8
//600us
#define Low_Gap_H 0XFD
#define Low_Gap_L 0xA8
//1200us
#define High_Gap_H 0xFB
#define High_Gap_L 0x50
//2400us
#define Start_High_H 0xF6
#define Start_High_L 0xA0
//按位发送函数
void Ir_Send_Bit(uint_16 us_h,uint_16 us_l,bit Status);
//按8位发送函数
void Ir_Send_Data(uint_8 Data);
//定时器初始化
void TimerInit(void);
//输入函数
void Input_num(uint_8 num);
//矩阵按键扫描
void JU_scan(void);
//密码发送函数
void Send_Power(uint_8 *power);
uint_8 line1[]="POWER INPUT:";
uint_8 line2[7]={32,32,32,32,'\0'};
uint_8 error1[]="POWER LESS 4";
uint_8 error2[]="RESUME LOAD";
uint_8 line3[]="NEW POWER:";
uint_8 power[4]={1,1,1,1};
uint_8 command[4]={10,10,10,10};
uint_8 pattern=0;
void main(void)
{
Lcd1602_init();
TimerInit();TX = 0;
while(1)
{
if(pattern==0)
{
Show_String(line1,line2);
}
else if(pattern==1)
{
Show_String(error1,error2);
}
else if(pattern==2)
{
Show_String(line3,line2);
}
JU_scan();
}
}
void Delay5ms() //@12.000MHz
{
unsigned char i, j;
i = 10;
j = 183;
do
{
while (--j);
} while (--i);
}
void Delect_num()
{
// if(line2[5]!=32)
// {
// line2[5]=32;
// }
// else if(line2[4]!=32)
// {
// line2[4]=32;
// }
if(line2[3]!=32)
{
line2[3]=32;
}
else if(line2[2]!=32)
{
line2[2]=32;
}
else if(line2[1]!=32)
{
line2[1]=32;
}
else if(line2[0]!=32)
{
line2[0]=32;
}
}
//void change_num(uint_8 *power)
//{
//// char i=0;
//// for(i=0;i<3;i++)
//// {
//// if(power[i]==1)power[i]=0x01;
//// else if(power[i]==2)power[i]=0x02;
//// else if(power[i]==3)power[i]=0x04;
//// else if(power[i]==4)power[i]=0x08;
//// else if(power[i]==5)power[i]=0x10;
//// else if(power[i]==6)power[i]=0x20;
//// else if(power[i]==7)power[i]=0x40;
//// else if(power[i]==8)power[i]=0x80;
//// }
//}
void JU_scan(void)
{
uint_8 i,team;
for(i=0x80;i>8;i >>=1)
{
P1=~i;team=P1;
if((team&0x0f)!=0x0f)
{
Delay5ms();
if((team&0x0f)!=0x0f)
{
switch(team)
{
case 0x7e:Input_num(1);break;//1
case 0x7d:Input_num(4);break;//4
case 0x7b:Input_num(7);break;//7
case 0x77:
for(i=0;i<4;i++)
{
if(line2[i]==32){pattern=1;break;}
else power[i]=line2[i]-48;//
}
Send_Power(power);
break;//发送
case 0xbe:Input_num(2);break;//2
case 0xbd:Input_num(5);break;//5
case 0xbb:Input_num(8);break;//8
case 0xb7:Input_num(0);break;//0
case 0xde:Input_num(3);break;//3
case 0xdd:Input_num(6);break;//6
case 0xdb:Input_num(9);break;//9
case 0xd7:Delect_num();break;//删除
case 0xee:
pattern=2;
for(i=0;i<6;i++)line2[i]=32;
Lcd1602_Clear();
Send_Power(command);
break;//修改密码
case 0xed:
pattern=0;
for(i=0;i<6;i++)line2[i]=32;
Lcd1602_Clear();
break;//重新输入
case 0xeb:Input_num(0);break;
case 0xe7:Input_num(0);break;
}
}
while((team&0x0f)!=0x0f)
{
team=P1;
}
}
}
}
void Input_num(uint_8 num)
{
num+=48;
if(line2[0]==32)
{
line2[0]=num;
}
else if(line2[1]==32)
{
line2[1]=num;
}
else if(line2[2]==32)
{
line2[2]=num;
}
else if(line2[3]==32)
{
line2[3]=num;
}
// else if(line2[4]==32)
// {
// line2[4]=num;
// }
// else if(line2[5]==32)
// {
// line2[5]=num;
// }
}
//按键扫描函数
void Send_Power(uint_8 *power)
{
TX = 0;
Ir_Send_Bit(Start_High_H,Start_High_L,1); //起始信号2.4ms
Ir_Send_Bit(Low_Gap_H,Low_Gap_L,0); //间隔输出0.6ms
Ir_Send_Data((power[0]|(power[1]<<4))); //数据
Ir_Send_Data((power[2]|(power[3]<<4))); //数据
Ir_Send_Bit(Low_Gap_H,Low_Gap_L,1);
}
//一位发送
void Ir_Send_Bit(uint_16 us_h,uint_16 us_l,bit Status)
{
TH0 = us_h; //设置定时初值
TL0 = us_l; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
if(Status==1)
{
// TX = 1;
while(TF0==0)
{
TX = 1;
delay12us;
TX = 0;
delay11us;
}
}
else if(Status==0)
{
TX = 0;
while(TF0==0);
}
TF0 = 0;
TR0 = 0; //关闭定时器
TX = 0;
}
//八位发送 从最低位往高位发送
void Ir_Send_Data(uint_8 Data)
{
uint_8 i=0;
for(i=0;i<8;i++)
{
if(Data&0x01) //高电平
{
Ir_Send_Bit(High_Low_Wide_H,High_Low_Wide_L,1); //脉宽输出
Ir_Send_Bit(High_Gap_H,High_Gap_L,0); //间隔输出
}
else
{
Ir_Send_Bit(High_Low_Wide_H,High_Low_Wide_L,1); //脉宽输出
Ir_Send_Bit(Low_Gap_H,Low_Gap_L,0); //间隔输出
}
Data >>=1;
}
}
void TimerInit(void) //12微秒@12.000MHz
{
TMOD=0X01; //设置定时器模式
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论


























收起资源包目录





















































共 48 条
- 1

月明Mo
- 粉丝: 2w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- maven下载安装与配置教程.md
- 【IOS应用源码】可以左右滚动的tab bar.zip
- 【IOS应用源码】酷黑轮盘计数器.zip
- 【IOS应用源码】控件的使用.zip
- 【IOS应用源码】可制作新闻图片列表的demo.zip
- 【IOS应用源码】酷炫的popup子菜单.zip
- 【IOS应用源码】垃圾桶组件.zip
- 【IOS应用源码】酷炫的图片展示效果.zip
- 【IOS应用源码】类似Chrome浏览器的多页签视图.zip
- 【IOS应用源码】类似android的9点解锁.zip
- 【IOS应用源码】老外的翻页效果──相当牛.zip
- 【IOS应用源码】类似Flipboard的杂志风格的view.zip
- 【IOS应用源码】类似js的checkbox效果的效果库.zip
- maven下载安装与配置教程.md
- 【IOS应用源码】类似安卓的底部动态提示.zip
- 【IOS应用源码】类似js的radio选项.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页