summaryrefslogtreecommitdiff
path: root/irmp-main-pic-xc8.c
blob: 2d783271f35a136a49c49153b7436b3879f838dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*---------------------------------------------------------------------------------------------------------------------------------------------------
 * irmp-main-pic-xc8.c - demo main module to test IRMP decoder on PIC18F4520 with XC8 compiler
 *
 * Copyright (c) 2009-2016 Frank Meyer - frank(at)fli4l.de
 *
 * $Id: irmp-main-pic-xc8.c,v 1.2 2016/09/09 08:01:11 fm Exp $
 *
 * This demo module is runnable on PIC18F4520 with XC8 compiler
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *---------------------------------------------------------------------------------------------------------------------------------------------------
 */

#include "irmp.h"

#ifndef F_CPU
#error F_CPU unknown
#endif

#define _XTAL_FREQ  32000000UL                                              // 32MHz clock
#define FOSC        _XTAL_FREQ
#define FCY         FOSC / 4UL                                              // --> 8MHz

#define BAUDRATE 19200UL
#define BRG (( FCY  16  BAUDRATE ) -1UL)

#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
    IRMP_DATA irmp_data;

    irmp_init();                                                            // initialize irmp

    // infinite loop, interrupts will blink PORTD pins and handle UART communications.
    while (1)
    {
        LATBbits.LATB0 = ~LATBbits.LATB0;

        if (irmp_get_data (&irmp_data))
        {
            // ir signal decoded, do something here...
            // irmp_data.protocol is the protocol, see irmp.h
            // irmp_data.address is the address/manufacturer code of ir sender
            // irmp_data.command is the command code
            // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
            printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command );
        }
    }
}

void interrupt high_priority high_isr(void)
{
    if (TMR2IF)
    {
        TMR2IF = 0;                                                         // clear Timer 0 interrupt flag
        irmp_ISR();
    }
}