source: microcontroller/src-atmel/scannergame/lab-irkit2.h

Last change on this file was 4268, checked in by siro, 6 years ago

added more IR-codes, changed port config to Atmega32

File size: 5.5 KB
Line 
1//      lab-irkit.h
2//     
3//      Authors: Hans-Gert Dahmen  <sexyludernatascha@gmail.com>
4//     
5//      This program is free software; you can redistribute it and/or modify
6//      it under the terms of the GNU General Public License as published by
7//      the Free Software Foundation; either version 2 of the License, or
8//      (at your option) any later version.
9//     
10//      This program is distributed in the hope that it will be useful,
11//      but WITHOUT ANY WARRANTY; without even the implied warranty of
12//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13//      GNU General Public License for more details.
14//     
15//      You should have received a copy of the GNU General Public License
16//      along with this program; if not, write to the Free Software
17//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18//      MA 02110-1301, USA.
19
20
21/*
22 * IR codes are stored in an array of on/off pulse lengths.
23 * As transmissions must always start with a one and consist
24 * of alternating ones and zeroes, every even index in the
25 * array will be a one-pulse and every odd array index
26 * will be a zero-pulse.
27 */
28
29#ifndef _H_LAB_IRKIT
30#define _H_LAB_IRKIT
31
32#include <avr/io.h>
33
34//one tick is 16 µS long
35//#define IR_TICK_US 16
36
37#ifndef F_CPU
38 #error F_CPU not defined
39#else
40 //standart IR frequencies, define your own here
41 #define IR_FREQ30K (uint16_t)(F_CPU/30000UL)
42 #define IR_FREQ33K (uint16_t)(F_CPU/33000UL)
43 #define IR_FREQ36K (uint16_t)(F_CPU/36000UL)
44 #define IR_FREQ38K (uint16_t)(F_CPU/38000UL)
45 #define IR_FREQ40K (uint16_t)(F_CPU/40000UL)
46 #define IR_FREQ56K (uint16_t)(F_CPU/56000UL)
47 #define IR_FREQ455K (uint16_t)(F_CPU/455000UL)
48#endif
49
50//define output PORT
51#define IRPORT PORTA
52#define IRDDR DDRA
53#define IRUSEDPORTS 0x3
54
55//define how long a carrier pulse last 0..1
56//select 0.5 for normal LED mode or
57//less values if you overcurrent the IR LEDs
58#define IR_pulse_width 0.2f
59
60//max SRAM usage
61#define IR_MAX_SRAM 512
62
63
64//see datasheet: http://www.princeton.com.tw/downloadprocess/downloadfile.asp?mydownload=PT2248.pdf
65#define IR_PT2248_Carrier IR_FREQ38K
66#define IR_PT2248_pulselength 422
67#define IR_PT2248_oneCode 0b0001
68#define IR_PT2248_oneCodelength 4
69#define IR_PT2248_zeroCode 0b0111
70#define IR_PT2248_zeroCodelength 4
71#define IR_PT2248_header 0
72#define IR_PT2248_headerlength 0
73
74#define IR_PhilipsRC5_Carrier IR_FREQ36K
75#define IR_PhilipsRC5_pulselength 889
76#define IR_PhilipsRC5_oneCode 0b10
77#define IR_PhilipsRC5_oneCodelength 2
78#define IR_PhilipsRC5_zeroCode 0b01
79#define IR_PhilipsRC5_zeroCodelength 2
80#define IR_PhilipsRC5_header 0
81#define IR_PhilipsRC5_headerlength 0
82
83#define IR_PhilipsRC6_Carrier IR_FREQ36K
84#define IR_PhilipsRC6_pulselength 444
85#define IR_PhilipsRC6_oneCode 0b10
86#define IR_PhilipsRC6_oneCodelength 2
87#define IR_PhilipsRC6_zeroCode 0b01
88#define IR_PhilipsRC6_zeroCodelength 2
89#define IR_PhilipsRC6_header 0
90#define IR_PhilipsRC6_headerlength 0
91
92#define IR_SIRC_Carrier IR_FREQ40K
93#define IR_SIRC_pulselength 600
94#define IR_SIRC_oneCode 0b100
95#define IR_SIRC_oneCodelength 3
96#define IR_SIRC_zeroCode 0b10
97#define IR_SIRC_zeroCodelength 2
98#define IR_SIRC_header 0b11110
99#define IR_SIRC_headerlength 5
100
101#define IR_Sharp_Carrier IR_FREQ38K
102#define IR_Sharp_pulselength 320
103#define IR_Sharp_oneCode 0b100000
104#define IR_Sharp_oneCodelength 6
105#define IR_Sharp_zeroCode 0b100
106#define IR_Sharp_zeroCodelength 3
107#define IR_Sharp_header 0
108#define IR_Sharp_headerlength 0
109
110#define IR_NokiaNRC17_Carrier IR_FREQ38K
111#define IR_NokiaNRC17_pulselength 500
112#define IR_NokiaNRC17_oneCode 0b10
113#define IR_NokiaNRC17_oneCodelength 2
114#define IR_NokiaNRC17_zeroCode 0b01
115#define IR_NokiaNRC17_zeroCodelength 2
116#define IR_NokiaNRC17_header 0b100000
117#define IR_NokiaNRC17_headerlength 6
118
119#define IR_NEC_Carrier IR_FREQ38K
120#define IR_NEC_pulselength 560
121#define IR_NEC_oneCode 0b1000
122#define IR_NEC_oneCodelength 4
123#define IR_NEC_zeroCode 0b10
124#define IR_NEC_zeroCodelength 2
125#define IR_NEC_header 0b111111111111111100000000
126#define IR_NEC_headerlength 24
127
128#define IR_JVC_Carrier IR_FREQ38K
129#define IR_JVC_pulselength 526
130#define IR_JVC_oneCode 0b1000
131#define IR_JVC_oneCodelength 4
132#define IR_JVC_zeroCode 0b10
133#define IR_JVC_zeroCodelength 2
134#define IR_JVC_header 0b111111111111111100000000
135#define IR_JVC_headerlength 24
136
137/*
138Code example:
139#include <stdio.h>
140#include <stdlib.h>
141
142#include "lab-irkit2.h"
143
144int main(void)
145{
146        //initialize ir subsystem
147        ir_init(IR_NEC_Carrier, IR_NEC_pulselength);
148       
149        uint8_t codelength=0;
150        ir_genHeader(0, IR_NEC_header, IR_NEC_headerlength);  //generate header
151        codelength=ir_genCode(IR_NEC_headerlength,0,IR_NEC_oneCode,IR_NEC_oneCodelength,IR_NEC_zeroCode,IR_NEC_zeroCodelength,0b00010000110010001110000100011110, 32);  //generate code
152        while (1)
153        {       
154                ir_sendCode(codelength);  //transmit code
155        }
156}
157
158*/
159
160// stop TIMER1, disable IRPORT
161#define FREQGEN_OFF() TCCR1B = 0; IRPORT&=IRDDR
162
163// start TIMER1, reset timer count
164#define FREQGEN_ON() TCNT1 = 0; TCCR1B = _BV(WGM12)|_BV(CS10) //counter is running now
165
166//function prototypes
167uint8_t ir_init(uint16_t freq, uint16_t pulselength);
168void ir_disable(void);
169uint16_t ir_genCode(uint8_t headerlength, uint8_t channel, uint8_t oneCode, uint8_t oneCode_length, uint8_t zeroCode,uint8_t zeroCode_length, uint32_t bitCode, uint8_t codeLen);
170uint8_t ir_genHeader(uint8_t channel, uint32_t headerCode, uint8_t headerLen);
171uint8_t ir_freqInit(uint16_t freq, uint16_t pulselength);
172void ir_sendCode(uint16_t codeLen);
173uint8_t transmission_pending(void);
174
175//work in progress
176/*typedef struct {
177uint16_t oneOntime;
178uint16_t oneOfftime;
179uint16_t zeroOntime;
180uint16_t zeroOfftime;
181
182} ir_proto;*/
183
184#endif //_H_LAB_IRKIT
185
Note: See TracBrowser for help on using the repository browser.