欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
單片機(jī)紅外二極管編碼發(fā)射程序+原理圖
[打印本頁(yè)]
作者:
kevin_007_qing
時(shí)間:
2019-10-15 09:49
標(biāo)題:
單片機(jī)紅外二極管編碼發(fā)射程序+原理圖
這是一個(gè)紅外發(fā)碼解碼的原理,利用一個(gè)普通的紅外發(fā)射管,利用一個(gè)IO口,發(fā)射38KHz的載波與按鍵。這個(gè)原理圖中沒(méi)有按鍵,所以程序中就發(fā)了固定的紅外碼值,如果需要加入按鍵的話直接加入按鍵掃描的程序即可。本程序是的開(kāi)發(fā)語(yǔ)言是mini C(為了適用特別的編譯器),基本上是和C語(yǔ)言一樣的,只是個(gè)別關(guān)鍵字不一樣而已。
電路原理圖如下:
原理圖.png
(46.77 KB, 下載次數(shù): 29)
下載附件
2019-10-15 09:40 上傳
單片機(jī)源程序如下:
//發(fā)射源碼
#include "extern.h"
.RAMADR 0
WORD zero;
WORD count;
WORD set_count;
WORD cnt0;
BYTE FLAG_1;
//WORD cnt1;
//BYTE cnt2;
//BYTE cnt3;
//BYTE irdata;
BYTE ircode;
//.RAMADR SYSTEM
BIT ir : PA.3;
BIT ir_flag : FLAG_1.0;
void INIT(void)
{
PA=0XFF; //IO
PAC=0B_1111_1111; //輸入設(shè)置 1為輸出 PA4輸入
PAPH=0X00; //無(wú)上拉
$ PADIER 0B_0000_0000; //使能數(shù)字輸入及喚醒功能,0數(shù)字,1模擬
// disgint ;
inten.2=1; //tm16溢出中斷
intrq=0;
t16m=0B_001_00_000; //SYSCLK_4m,1分頻,8位中斷,1/(4M/1) = 0.25us
integs=0B_0000_0000;
WORD t_count=215;
stt16 t_count; //tm16置初值,定時(shí)0.25*(256-204)=13us
engint; //使能中斷
}
void delay_ms(void)//24ms
{
while(1)
{
cnt0++;
if(cnt0>=8000)
{
cnt0=0;
break;
}
}
}
void delay_s(void)
{
BYTE i = 2;//2
do
{
delay_ms();
}while(i--);
}
void ir_sendbyte(void)
{
BYTE i = 8;
do
{
i--;
set_count = 43;//發(fā)送560us高電平
ir_flag = 1;//啟動(dòng)紅外發(fā)射
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
if(ircode.0) set_count = 130;//判斷紅外編碼最低位,若為1則為1.69ms低電平
else set_count = 43;//否則為560us低電平
ir_flag = 0;//低電平不發(fā)射
count = 0;
set1 t16m.5;
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
ircode = ircode>>1;
}while(i);
}
void ir_send1(void)
{
set_count = 782;//692發(fā)送編碼中的引導(dǎo)碼(9ms+4.5ms)
ir_flag = 1;//啟動(dòng)紅外
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
set_count = 346;//發(fā)送編碼中的4.5ms低電平
ir_flag = 0;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
ircode = 0x00;//用戶碼前8位
ir_sendbyte();
ircode = 0xff;//用戶碼后8位
ir_sendbyte();
ircode = 0x56;//8位數(shù)據(jù)碼0x56 測(cè)試0x45 反0xba
ir_sendbyte();
ircode = 0xa9;//數(shù)據(jù)碼反碼0xa9
ir_sendbyte();
set_count = 43;//發(fā)送編碼中的560us高電平
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
ir = 1;
delay_ms();//23ms
set_count = 782;//發(fā)送引導(dǎo)碼
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
set_count = 346;//發(fā)送編碼中的4.5ms低電平
ir_flag = 0;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
set_count = 43;
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
ir = 1;
}
void ir_send2(void)
{
set_count = 782;//692發(fā)送編碼中的引導(dǎo)碼(9ms+4.5ms)
ir_flag = 1;//啟動(dòng)紅外
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
set_count = 346;//發(fā)送編碼中的4.5ms低電平
ir_flag = 0;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
ircode = 0x00;//用戶碼前8位
ir_sendbyte();
ircode = 0xff;//用戶碼后8位
ir_sendbyte();
ircode = 0x34;//8位數(shù)據(jù)碼0x34 測(cè)試0x47 反0xb8
ir_sendbyte();
ircode = 0xcb;//數(shù)據(jù)碼反碼0xcb
ir_sendbyte();
set_count = 43;//發(fā)送編碼中的560us高電平
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;//關(guān)閉定時(shí)器
ir = 1;
delay_ms();//23ms
set_count = 782;//發(fā)送引導(dǎo)碼
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
set_count = 346;//發(fā)送編碼中的4.5ms低電平
ir_flag = 0;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
set_count = 43;
ir_flag = 1;
count = 0;
set1 t16m.5;//開(kāi)啟定時(shí)器
while(1)
{
if(count > set_count) break;
}
set0 t16m.5;
ir = 1;
}
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/2
// Insert Initial Code
//清除RAM
Zero = _SYS(RAM_SIZE)-1;
a = 0;
do
{
*Zero = a;
}while(--Zero$0);
count = 0;
ir_flag = 0;
INIT();
while (1)
{
ir_send1();
delay_s();
ir_send2();
delay_s();
// wdreset;
}
}
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1