amobbs.com 阿莫电子技术论坛
标题:
[菜鸟贴][古董贴][求助]如何利用TIMER0在ICC中实现38K的载波(用于红外通讯)
[打印本页]
作者:
Gorgon_Meducer
时间:
2004-11-28 16:21
标题:
[菜鸟贴][古董贴][求助]如何利用TIMER0在ICC中实现38K的载波(用于红外通讯)
如题,急!
作者:
gxlujd
时间:
2004-11-28 19:13
21IC里有详细资料,包括原理图。
http://design.21ic.com/news/files/news/2003525223240.asp
作者:
Gorgon_Meducer
时间:
2004-12-2 17:27
我说的是不使用额外的芯片,直接用MAGE8模拟
我已经完成了。用试波器检测无误。
/******************************************************************
红外通讯函数(发送端)4M晶震
*******************************************************************/
# include <iom8.h>
# include <macros.h>
#pragma interrupt_handler timer1_vof:9 //定时器1中断
#pragma interrupt_handler timer0_ovf_isr:10 //定时器0中断
/**************全局变量定义****************/
unsigned int time_counter=0; //定时器
unsigned int time_counter_end=0; //终止时间
char press_keys=0; //按键代码
unsigned char temp_signals=0; //要发送的数据
unsigned char signals=16;
/**************全局变量定义****************/
/****************函数声明******************/
void timer1_int(void);
void timer0_init(void);
void port_int(void);
void delay(unsigned int times);
void timer1_vof(void);
void timer0_ovf_isr(void);
void send_signal(void);
void scan_key_press(void);
/****************函数声明******************/
/***************************************
定时器
****************************************/
void timer1_int(void)
{
TCCR1B = 0x00; //stop
//TCNT1H = 0xd4; //setup
//TCNT1L = 0xce;
TCNT1H=0xf0;
TCNT1L=0x60;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
TIMSK = 0x04;
}
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0xcb; //set count 38k*2
}
/****************************************
端口初始化
****************************************/
void port_int(void)
{
//发送端程序
PORTD=0x00;
DDRD=0xff;//
DDRB=0xff;
PORTB=0xff;
DDRB=0x00; //使用PB1-5作为按键输入
DDRC=0xff;
PORTC=0xff;
DDRC=0X00; //使用PC1-3作为按键输入
}
/****************************************
延时程序
****************************************/
void delay(unsigned int times)
//times 单位 ms
{
time_counter=1; //打开计数器
time_counter_end=times; //设置延时
res:
if (time_counter!=0)
{
goto res;
}
}
/****************************************
定时器中断处理
****************************************/
void timer1_vof(void)
{
unsigned char a=0,b=0;
//逻辑自锁计数器
if (time_counter>0)
{
time_counter++;
if (time_counter>time_counter_end)
{
time_counter=0;
}
}
if (temp_signals!=0) //发送数据
{
PORTD|=(1<<7);
for (a=1;a<=10;a++)
{
for(b=1;b<=8;b++)
{
TCCR0|=((temp_signals)&(1<<(b-1)))>>(b-1); //发送38K载波
}
}
}
else
{
PORTD&=(~(1<<7));
}
}
void timer0_ovf_isr(void)
{
TCNT0 = 0xcb; //REset count 38k*2
signals=~signals;
if (signals==16)
{
PORTD|=signals;
}
else
{
PORTD&=signals;
}
}
/****************************************
按键查询
****************************************/
void scan_key_press(void)
{//返回按键值 press_keys
char a=0;
//测试B口
for(a=1;a<=5;a++)
{
if (((PINB&(1<<a))!=(1<<a)))
{
delay(10); //去陡
if (((PINB&(1<<a))!=(1<<a)))
{
press_keys=a;
goto end_sub;
}
}
}
//测试C口
for (a=6;a<9;a++)
{
if (((PINC&(1<<(a-5)))!=(1<<(a-5))))
{
delay(10);
if (((PINC&(1<<(a-5)))!=(1<<(a-5))))
{
press_keys=a;
goto end_sub;
}
}
}
press_keys=0;
temp_signals=0; //不发送数据
TCCR0=0x00;
end_sub:
;
}
/****************************************
信号发送
****************************************/
void send_signal(void)
{
temp_signals=(0xff<<(8-press_keys)); //使用步进码
}
/****************************************
主程序(查询方式)
****************************************/
void main(void)
{
timer1_int();
timer0_init();
port_int();
SEI();
TIMSK = 0b00000101; //timer interrupt sources
while(1) //等待中断
{
scan_key_press();
if (press_keys!=0)
{
send_signal();
}
}
}
作者:
armok
时间:
2004-12-2 18:26
提示:
作者被禁止或删除 内容自动屏蔽
作者:
xxheng
时间:
2005-4-15 09:38
我想从AVR的TXD口输出数据,从PD0口输出38KHz的载波,能不能把这两个口直接并接在一起,输出调制波?
作者:
bigreat
时间:
2006-8-3 22:31
Gorgon Meducer :
厉害!, 很有用!, 希望能跟你学习!
作者:
bigreat
时间:
2006-8-3 22:33
am:
你的范例好像不是用来传数据的吧 :)
作者:
Gorgon_Meducer
时间:
2006-8-3 23:56
……n年前的东西了……是否可靠,自己都忘了……
该贴质量低下!望大家不要跟贴了……谢谢。
作者:
Gorgon_Meducer
时间:
2006-8-4 00:02
那是我刚学AVR不超过1个星期的时候第一次尝试在OurAvr上发菜鸟贴时候的事情了。真怀念哈。当时的想法是,把键盘按键值通过红外调制发送出去,使用定时器0产生一个76k的中断,该中断不停的翻转电平,从而实现利用普通端口产生38k方波。通过控制定时器的使能并通过使能时间的长短来表示0或者是1……基本原理如此。当然还使用了步进码作为可靠性代码……。
不过,从我现在的角度来看,该代码——严重的菜鸟……所以还希望大家不要笑话……
菜鸟的过去是值得回忆的美好时光……哈哈哈哈哈哈哈——现在仍然是菜鸟……高级菜鸟。
-----
此内容被Gorgon Meducer于2006-08-04,00:03:09编辑过
作者:
bigreat
时间:
2006-8-4 00:10
HI,
不知道还有什么新的方法? 谢谢了,学习中
作者:
Gorgon_Meducer
时间:
2006-8-4 00:14
另外一个帖子中有相关的内容。
当然,如果是产品开发的话,建议使用专用芯片。
或者用一个555搭建一个38k发生电路,用串口TX接在该电路的使能脚上……直接实现是用串口发送红外数据……当然,速率最好慢一点……RX端接一体化接收头就可以了……
作者:
bigreat
时间:
2006-8-4 00:19
HI,
自己弄着玩的,感觉直接用avr generate 比方便,有几个菜的问题想问你,还希望能向你请教些经验,不知道能不能contact? QQ or MSN
另个帖子? 我在红外份论坛上没找到。
谢谢
作者:
earthboy
时间:
2011-7-14 21:16
mark
作者:
pplive
时间:
2015-9-7 16:03
mark,最近好贴。
欢迎光临 amobbs.com 阿莫电子技术论坛 (https://www.amobbs.com/)
Powered by Discuz! X3.4