⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 红外遥控器.c

📁 avr单片机编写 一种能同时使用两种格式(TV/DVD)的红外遥控器,奉献给大家(原理图,代码)
💻 C
字号:
/*****************************************************
CodeWizardAVR V1.25.3 Professional

Project : 红外遥控器
Version : V 1.0.0
Date    : 2007-08-10
Author  : Aleyn.wu
Company : www.e-midas.cn
E-mail  : aleyn@e-midas.cn


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 455K hz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega8.h>
#include "Config.h"

#include "IR38K.c"
#include "TV.c"
#include "DVD.c"

void Port_Init(void)
{
	PORTB=0x00;
	DDRB=0B00000011;

	PORTC=0x00;
	DDRC=0x00;

	PORTD=0xE0;
	DDRD=0xE0;
}

void main(void)
{
	unsigned char LastKey;
	unsigned char Key;
	unsigned char State;
	unsigned char i;
	
	Port_Init();
	//USART_Init(0x02);
	LastKey=0;
	
	while (1)
	{
		
		//PORTD.7=PINB.2;
		
		State=(~PINC)&0x3F;
		
		if (State)
		{
			Key=0;
			
			for (i=0;i<6;i++)
			{
				if ((State>>i)&0x01)
				{
					Key=i+1;
					break;
				}
			}
			
			if ((Key>0)&&(Key<7))
			{
				GRE_LED_ON;
				
				if (PINB.2)
				{
					if (Key!=LastKey)
					{
						SendTVIR(TVKey[Key-1]);
						LastKey=Key;
					}
					else
					{
						SendTVIRRept();
					}
				}
				else
				{
					if (Key!=LastKey)
					{
						SendDVDIR(DVDKey[Key-1]);
						LastKey=Key;
					}
					else
					{
						SendDVDIRRept();
					}
				}
				
				GRE_LED_OFF;
			}
		}
		else
		{
			LastKey=0;
		}
		
	};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -