source: svn/branches/remocon/zasc/app_c/DST_nec_ir_sender.c

Last change on this file was 65, checked in by megakiss, 11 years ago
File size: 1.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include "dst_eroum_interface.h"
4
5//int nLEDState = 0;
6
7// IR LED¸¦ Á¦¾îÇÏ´Â Äڵ带 È£ÃâÇØ¾ß ÇÔ
8static void SetIRLED(int nOn)
9{
10        //nLEDState = nOn;
11        // TO DO LED Control
12        if(nOn==1)
13        {
14                DHL_SetLED(true,true);
15        }
16        else
17        {
18                DHL_SetLED(false,false);
19        }
20
21}
22
23static void signal38k(bool bOn)
24{
25        int i;
26        SetIRLED(bOn ? 1 : 0);
27        for (i = 0; i < 1616; i++)
28        {
29               
30        }
31        SetIRLED(0);
32        for (i = 0; i < 1616; i++)
33        {
34               
35        }
36}
37
38static void signal(bool bOn, int nCount)
39{
40        int i;
41        for (i = 0; i < nCount; i++)
42        {
43                signal38k(bOn);
44        }
45}
46
47static void SendBit(int bOn)
48{
49        signal(true, 22);
50        signal(false, bOn == 0 ? 21 : 64);
51}
52
53static void SendByte(unsigned char code)
54{
55        SendBit(code & 0x01);
56        SendBit(code & 0x02);
57        SendBit(code & 0x04);
58        SendBit(code & 0x08);
59        SendBit(code & 0x10);
60        SendBit(code & 0x20);
61        SendBit(code & 0x40);
62        SendBit(code & 0x80);
63}
64
65
66
67void DST_NEC_IR_Send(unsigned char custom0, unsigned char custom1, unsigned char code)
68{
69        unsigned int flags = bos_enter_critical();
70        // http://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol
71        // a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
72        signal(true, 38*9);
73        // a 4.5ms space
74        signal(false, (38*9)/2);
75        // the 8-bit address for the receiving device
76        SendByte(custom0);
77        // the 8-bit logical inverse of the address
78        SendByte(custom1);
79        // the 8-bit command
80        SendByte(code);
81        // the 8-bit logical inverse of the command
82        SendByte(~code);
83        // a final 562.5¥ìs pulse burst to signify the end of message transmission.
84        SendBit(0);
85        bos_exit_critical(flags);
86}
87
88#if 0
89int main()
90{
91        DST_NEC_IR_Send(0x20, 0x20, 0x20); // CMB ¸®¸ðÄÜÀÇ Mute Ű
92        return 0;
93}
94#endif
Note: See TracBrowser for help on using the repository browser.