📄 send_ctrl.c
字号:
#include <intrins.h>//这个头文件中有_nop_();
#include <reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
//----------------------------------------------
uint bdata dat_send=0x55; // 变量定义
uint dat=0x00;
sbit bit_dat0=dat_send^7;
uint i;
//----------------------------------------------
#define key P0 // 定义口线
sbit light=P1^0;
//------------------------------------------------ 函数声明
void get_key(void);
void send(void);
void chu_shi_hua(void);
void delay(uint j);
//-----------------------------------------------------------------------------------------------
void delay(uint j)
{
while(j--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
}
}
//------------------------------------------------------------------------------------------------
void chu_shi_hua(void) //初始化中断
{
EA=1;ET0=1;ET1=1;
TMOD=0x22;
TH0=0xf3;TL0=0xf3;
TH1=0x06;TL1=0xFF;
}
//------------------------------------------------------------------------------------------------
void send(void) //开启定时传送
{
if(dat!=0x00)
{
dat_send=dat;
TR1=1; i=8;
}
}
//-----------------------------------------------------------------------------------------------
void get_key(void) //检测键盘
{
key=0xff;
switch(key)
{
case 0x01: dat=0x05;break;
case 0x02: dat=0x09;break;
case 0x04: dat=0x0f;break;
case 0x08: dat=0x11;break;
case 0x10: dat=0x17;break;
case 0x20: dat=0x1b;break;
case 0x40: dat=0x1d;break;
case 0x80: dat=0x21;break;
default:dat=0x00;
}
}
//---------------------------------------------------------------------------------------------
void main(void) //主程序
{
chu_shi_hua();
while(1)
{
get_key();
send();
delay(90);
send();
delay(90);
send();
}
}
//---------------------------------------------------------------------------------------------
void send_38k(void) interrupt 1 using 2 //用于发38k的方波
{
light=!light;
}
//----------------------------------------------------------------------------------------------
void send_ctrl(void) interrupt 3 using 1 //定时传送控制数据
{
if(bit_dat0==1)
TR0=1;
else TR0=0;
dat_send<<=1;
i--;
if(i==0)
TR1=0;
}
//--------------------- THE END ------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -