]>
cloudbase.mooo.com Git - irmp.git/blob - irmp-main-pic-12F1840.c
fbeaff79e2637d2d0e96c3b6cf3bd60fcdc56281
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main_pic.c - example main module
4 * IR decoder using IRMP
6 * (c) 2014 Wolfgang Strobl (ws at mystrobl.de) 2014-03-12:2014-07-05
8 * This demo module is runnable on a Microchip PIC 12F1840
10 * To be used with IRMP by Frank Meyer (frank(at)fli4l.de)
11 * <http://www.mikrocontroller.net/articles/IRMP>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *---------------------------------------------------------------------------------------------------------------------------------------------------
24 10k -|___|-+ Vdd -o| o|o- Vss
25 ___ +-RS232in / GP5 -o| |o- GP0 / ICSPDAT
26 1k -|___|-- RS232out/ GP4 -o| |o- GP1 / ICSPCLK
27 Vpp / GP3 -o|__|o- GP2 / TS TSOP1736
28 Example output, using a bunch of different remote controls
29 IRMP PIC 12F1840 1.1 ws
30 P 7 a=0x0011 c=0x000c f=0x00 (RC5)
31 P 6 a=0x0001 c=0x0018 f=0x00 (RECS80)
32 P 2 a=0xbf00 c=0x0019 f=0x00 (NEC)
33 P 2 a=0xeb14 c=0x0001 f=0x00 (NEC)
34 P 7 a=0x001c c=0x0005 f=0x00 (RC5)
35 P 7 a=0x000a c=0x0057 f=0x00 (RC5)
36 P 7 a=0x000a c=0x0057 f=0x01 (RC5)
37 P 2 a=0xfb04 c=0x0008 f=0x00 (NEC)
45 /******************************************************************************/
47 /******************************************************************************/
48 #define SYS_FREQ 32000000L
49 #define _XTAL_FREQ 32000000 // for _delay
50 #define FCY (SYS_FREQ/4)
52 /******************************************************************************/
54 /******************************************************************************/
63 SPLLEN
=1; // p 46 and 54
66 /******************************************************************************/
67 // "configuration_bits.c" 12F1848
68 /******************************************************************************/
70 #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
71 #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
72 #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
73 #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
74 #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
75 #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
76 #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
77 #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
78 #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
79 #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
82 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
83 #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
84 #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
85 #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
86 #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
87 /******************************************************************************/
89 /******************************************************************************/
91 /******************************************************************************/
93 // This demo module uses RS232 TX via EUSART, only
103 TXCKSEL
= 1; // put TX on pin 4 - not 0 -, p 102
104 SPBRGL
= (_XTAL_FREQ
/BAUD
/64-1);
109 SYNC
= 0; // 0 p. 267
110 SPEN
= 1; // 26.1.1.7
111 SCKP
= 1; // invert p 269
119 while (!TRMT
) _delay(1);
123 /******************************************************************************/
125 /******************************************************************************/
131 TMR1
=0xFC00; // p. 155 wait 1024 cycles for stabilization.
132 TMR1CS1
=0; // Clock source == System Clock
134 TMR1IE
=1; // enable TMR1 interrupts
135 PEIE
=1; // enable Pheripheral Interrupts
140 /******************************************************************************/
142 /******************************************************************************/
144 void interrupt
isr(void)
147 TMR1
=0xffff-_XTAL_FREQ
/F_INTERRUPTS
;
148 TMR1IF
=0; // clear timer 1 interrupt
151 /******************************************************************************/
153 /******************************************************************************/
159 InitApp(); // später inlinen
165 printf("IRMP PIC 12F1840 1.1 ws\r\n");
166 irmp_init(); // initialize irmp
167 timer1_init(); // initialize timer1
168 ei(); // enable interrupts
169 TMR1ON
=1; // start timer
173 if (irmp_get_data (&irmp_data
))
176 printf("%d a=0x%04x c=0x%04x f=0x%02x (",irmp_data
.protocol
, irmp_data
.address
,irmp_data
.command
,irmp_data
.flags
);
179 #if IRMP_PROTOCOL_NAMES
180 printf(irmp_protocol_names
[irmp_data
.protocol
]);
182 switch(irmp_data
.protocol
)