STC12C5410AD學(xué)習(xí)板---紅外解碼
視頻演示地址:
http://v.youku.com/v_show/id_XMTUyMzQwMjg4.html
以下是詳細(xì)程序:
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :cooldianzi@163.com *****/
/*************************************************************/
/*****File Function : IR Soft Recode(SAA3010) *****/
/*****Compile Date : 2009/2/4 *****/
/*****Edition Info : V1.0 *****/
/*****Amend Date : *****/
/*************************************************************/
/************紅外軟件解碼,遙控器型號,SAA3310芯片************/
/***********************2009.2.4******************************/
/***********可以紅外解碼LCD顯示*************/
#include
#include "intrins.h "
#include "SAA3010_Recode.h"
#include "LCD12864.H"
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit speaker=P2^1;
uchar LCD_IR_da
void Delay1ms(unsigned int count);
void Key_Beep(void);
void Delay_Beep(unsigned int count1);
void init_rs232(void);
/***************************1秒延時(shí)子程序start***************************/
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i
}
/***************************1秒延時(shí)子程序end***************************/
/*****************按鍵聲音********************/
void Key_Beep(void)
{ uchar i;
for (i=0;i<250;i++)
{ speaker=1;
Delay_Beep(30);
speaker=0;
Delay_Beep(30);
}
speaker=1;
}
/**************************************************/
/***************************蜂鳴器延時(shí)子程序start**********************/
void Delay_Beep(unsigned int count)
{
unsigned int i,j;
for(i=0;i
}
/***************************蜂鳴器延時(shí)子程序end************************/
/* 串口通信初始化設(shè)置 */
void init_rs232(void)
{
AUXR=74; //設(shè)置波特率是普通51的12倍 ,允許AD中斷
SCON=0x50;
PCON=0x00;
TH1=0xFA; //波特率 115200 22.1184MHZ 時(shí)候(F4 4800 FA 9600 FDH 9600)*12
TL1=0XFA;
TMOD=0X20;
TR1=1;
}
void main(void)
{
uchar key_co
uchar key_co
uchar key_co
Delay1ms(1000);
init_rs232();
TI=1;
printf("STC12C5410AD學(xué)習(xí)板 紅外遙控解碼n");
printf("ClimberWin 2009.2.4nn");
Delay1ms(5000);
LCD_INIT();
Delay1ms(1000);
LCD_LOCAL(1,1,"STC 單片機(jī)學(xué)習(xí)板");
LCD_LOCAL(2,1,"MCU:STC12C5410AD");
LCD_LOCAL(4,1,"Date:2009.2.4 ");
LCD_LOCAL(3,1,"By ClimberWin ");
/****************************************/
Delay1ms(50000);
LCD_LOCAL(1,1,"紅外遙控測試界面");
LCD_LOCAL(2,1,"遙控芯片:SAA3010");
LCD_LOCAL(3,1,"測試結(jié)果: ");
LCD_LOCAL(4,1," ");
printf("紅外遙控測試界面n");
//Delay100us(8); // 實(shí)為760uS
Key_Beep();
IR_Input = 1;//先把信號線拉高,等待接收紅外信號
while(1)
{
LCD_IR_da
LCD_IR_da
LCD_IR_da
if(!IR_Input) SAA3010_Recode();
if(SAA3010_CO
{Key_Beep();
SBUF=SAA3010_CO
key_co
key_co
key_co
LCD_IR_da
LCD_IR_da
LCD_IR_da
LCD_LOCAL(4,1,LCD_IR_da
SAA3010_CO
SAA3010_CO
SAA3010_CO
SAA3010_CO
}
else
{SAA3010_CO
}
}
LCD12864.H 如下:
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :cooldianzi@163.com *****/
/*************************************************************/
/*****File Function : LCD12864 Display Module *****/
/*****Compile Date : 2009/1/28 *****/
/*****Edition Info : V1.0 *****/
/*****Amend Date : *****/
/*************************************************************/
#ifndef __LCD12864__
#define __LCD12864__
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit LCD_CS = P1^7;//片選 高電平有效 單片LCD使用時(shí)可固定高電平rs
sbit LCD_SID = P1^6;//數(shù)據(jù) r/w
sbit LCD_SCLK = P1^5;//時(shí)鐘 e
/********************LCD12864**************************/
void LCD_SEND(uchar date);
void LCD_SCOM(bit st,uchar date);
void LCD_DELAY(void);
void LCD_INIT(void);
void LCD_write(uchar *p);
void LCD_LOCAL(uchar x,uchar y,uchar *p);
void LCD_cblank(uchar x,uchar y);
void LCD_count(long s,uchar x1,uchar y1,uchar x,uchar y,uchar *p);
void DELAYLCD(uchar t);
/*****************************************************/
/****************************lcd12864************************************/
void DELAYLCD(uchar t)
{
while(--t);
}
void LCD_SEND(uchar date)
{
uchar i;
LCD_SCLK=0;
for(i=0;i<8;i++)
{
LCD_SID=date&0x80;
LCD_SCLK=1;
LCD_SCLK=0;
date<<=1;
}
}
void LCD_SCOM(bit st,uchar date)
{
uchar st_temp,hdate,ldate;
if(st)
st_temp=0xfa;
else st_temp=0xf8;
hdate=date&0xf0;
ldate=date&0x0f;
ldate <<= 4;
LCD_CS = 1;
LCD_SEND(st_temp);
LCD_SEND(hdate);
LCD_SEND(ldate);
LCD_CS = 0;
DELAYLCD(38);
}
void LCD_DELAY(void)
{ uchar s;
s=10;
while(--s)
DELAYLCD(250);
}
void LCD_INIT(void)
{
LCD_SCOM(0,0x30);
LCD_DELAY();
LCD_SCOM(0,0x0c);
LCD_DELAY();
LCD_SCOM(0,0x01); //清屏,將DDRAM的地址計(jì)數(shù)器歸零
LCD_DELAY();
}
void LCD_write(uchar *p)
{
while(*p)
{
LCD_SCOM(1,*p);
p++;
}
}
void LCD_LOCAL(uchar x,uchar y,uchar *p) //lcd string (x,y) write!
{
switch (x)
{
case 1:LCD_SCOM(0,0x7f+y); LCD_write(p);break;
case 2:LCD_SCOM(0,0x8f+y); LCD_write(p);break;
case 3:LCD_SCOM(0,0x87+y); LCD_write(p);break;
case 4:LCD_SCOM(0,0x97+y); LCD_write(p);break;
default :LCD_SCOM(0,0x7f+y); LCD_write(p);
}
}
void LCD_cblank(uchar x,uchar y)
{
switch (x)
{
case 1:LCD_SCOM(0,0x7f+y); LCD_SCOM(0,0x0d);break;
case 2:LCD_SCOM(0,0x8f+y); LCD_SCOM(0,0x0d);break;
case 3:LCD_SCOM(0,0x87+y); LCD_SCOM(0,0x0d);break;
case 4:LCD_SCOM(0,0x97+y); LCD_SCOM(0,0x0d);break;
default :LCD_SCOM(0,0x7f+y); LCD_SCOM(0,0x0d);
}
}
/************************************************************************/
/*******************************************************************************/
#endif
SAA3010_Rncode.H 如下:
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :cooldianzi@163.com *****/
/*************************************************************/
/*****File Function : SAA3010 IR_Input soft recode *****/
/*****Compile Date : 2009/2/4 *****/
/*****Edition Info : V1.0 *****/
/*****Amend Date : *****/
/*************************************************************/
/***************對紅外遙控器SAA3010軟件解碼*******************/
#ifndef __SAA3010_Rncode__
#define __SAA3010_Rncode__
#define uchar unsigned char
#include
sbit IR_Input=P3^4;
uchar SAA3010_CO
void SAA3010_Recode(void);
void Delay100us(uchar i);
/*************SAA3010解碼程序**************/
void SAA3010_Recode(void)
{
unsigned char i, j;
bit FBIT;
// IR_Input 由高變低,跳過第一次采樣
for (i=0; i<4; i++)
{
SAA3010_CO
}
/*--------------------------------------
曼徹斯特碼:
輸入二元碼 Manchester碼
0 01
1 10
****************************************/
// 設(shè)為第二次采樣,采樣時(shí)間間隔800uS
Delay100us(8);
if (!IR_Input)
{
// 因?yàn)镾AA3010的起始位為1
SAA3010_CO
SAA3010_CO
// 起始第二位一次采樣
Delay100us(8);
if (IR_Input)
{ // 采樣是1
SAA3010_CO
FBIT = 1;
}
else
{ // 采樣是0
FBIT = 0;
}
if (FBIT)
{ // 若第一次采樣是1
while (IR_Input);
}
else
{
while (!IR_Input);
}
// 二次采樣
Delay100us(8);
//----------------------------------------------------------------------------
// 采樣控制位
// 一次采樣
Delay100us(8);
if (IR_Input)
{
SAA3010_CO
FBIT = 1;
}
else
{
FBIT = 0;
}
if (FBIT)
{
while (IR_Input);
}
else
{
while (!IR_Input); // 等待IR_Input上升
}
// 二次采樣
Delay100us(8);
//----------------------------------------------------------------------------------
// 收集系統(tǒng)碼(5位)
for (j=0; j<5; j++)
{
// 一次采樣
Delay100us(8);
if (IR_Input)
{
SAA3010_CO
FBIT = 1;
}
else
{
FBIT = 0;
}
if (FBIT)
{
while (IR_Input);
}
else
{
while (!IR_Input);
}
// 二次采樣
Delay100us(8);
SAA3010_CO
}
//-----------------------------------------------------------------------------
// 收集數(shù)據(jù)碼(6位)
for (j=0; j<6; j++)
{
// 一次采樣
Delay100us(8);
if (IR_Input)
{
SAA3010_CO
FBIT = 1;
}
else
{
FBIT = 0;
}
if (FBIT)
{
while (IR_Input);
}
else
{
while (!IR_Input);
}
// 二次采樣
Delay100us(8);
SAA3010_CO
}
//-----------------------------------------------------------------------------
}
else
{ // 是抖動
for (i=0; i<4; i++)
{
SAA3010_CO
}
return;
}
SAA3010_CO
}
/************760us延時(shí)程序********************/
void Delay100us(uchar i)
{
uchar j;
while(i<50)//50
{
for(j=0;j<50;j++)
{ _nop_();}
i++;
}
}
/******************************************************/
#endif
評論