本帖最后由 34af9uc 于 2020-11-9 23:42 编辑
//应广单片机编程第七季
//试商法,逆向工程,红外发射
//QQ:774145445
//快手:共同学习stm8
//2020/11/8
//--------------PMS150G----------
// ______@_____
// |1vdd gnd8|
// |2pa7 pa07|
// |3pa6 pa46|--led
// |4pa5____pa35|
#include "extern.h"
led bit pa.4;
word yanshi_a1;
byte shuju;
void fa1(); //发1
void fa0(); //发0
void yindao(); //引导码
void fasong(); //发送数据
void jieshu(); //结束码
void chongfu(); //重复码
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
$ led out,low;
while (1)
{
yindao(); //引导码
shuju =0x00; //客户识别码1
fasong();
shuju =0xff; //客户识别码2
fasong();
shuju =0x43; //正数据
fasong();
shuju =0xbc; //反数据
fasong();
jieshu(); //结束码
while(1) //重复发送
{
chongfu();
}
}
}
/**************************************************/
void yindao() //引导码
{
yanshi_a1 =350; //9ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145; //109
yanshi_a1 --;
}
led =0; //4.5ms低
.delay 18000;
}
/**************************************************/
void fa1() //发1
{
yanshi_a1 =22; //0.56ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145;
yanshi_a1 --;
}
led =0; //1.69ms低
.delay 6720;//2240;
}
/**************************************************/
void fa0() //发0
{
yanshi_a1 =22; //0.56ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145;
yanshi_a1 --;
}
led =0; //0.56ms低
.delay 2240;//2240;
}
/**************************************************/
void fasong() //发送数据
{
if(shuju.0){fa1();} else{fa0();}
if(shuju.1){fa1();} else{fa0();}
if(shuju.2){fa1();} else{fa0();}
if(shuju.3){fa1();} else{fa0();}
if(shuju.4){fa1();} else{fa0();}
if(shuju.5){fa1();} else{fa0();}
if(shuju.6){fa1();} else{fa0();}
}
/**************************************************/
void jieshu() //结束码
{
yanshi_a1 =22; //0.56ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145;
yanshi_a1 --;
}
}
/**************************************************/
void chongfu() //重复码
{
yanshi_a1 =350; //9ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145;
yanshi_a1 --;
}
led =0; //2.25ms低
.delay 9000;
yanshi_a1 =22; //0.56ms高
while(yanshi_a1)
{
led =1;
.delay 73; //109
led =0;
.delay 145;
yanshi_a1 --;
}
led =0; //98ms低
.delay 392000;
}
/**************************************************/
/*
void Interrupt (void)
{
pushaf;
if (Intrq.T16)
{ // T16 Trig
// User can add code
Intrq.T16 = 0;
//...
}
popaf;
}
*/
/**************************************************/ |