]>
cloudbase.mooo.com Git - irmp.git/blob - irmp-main-pic-12F1840.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp-main-pic-12F1840.c - example main module for PIC 12f1840
4 * IR decoder using IRMP
6 * (c) 2014 Wolfgang Strobl (news4 at mystrobl.de) 2014-03-12:2014-07-20
8 * $Id: irmp-main-pic-12F1840.c,v 1.4 2016/09/09 08:01:11 fm Exp $
10 * This demo module is runnable on a Microchip PIC 12F1840
12 * To be used with IRMP by Frank Meyer (frank(at)fli4l.de)
13 * <http://www.mikrocontroller.net/articles/IRMP>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *---------------------------------------------------------------------------------------------------------------------------------------------------
25 Hauptprogramm fuer den nachfolgenden Testaufbau, bestehend aus zwei mal
31 ___ +--GP5--o| |o--GP0 / ICSPDAT
32 RS232 out -|___|-------GP4--o| |o--GP1 / ICSPCLK ___ LED
33 RS232 in -|___|---Vpp/GP3--o|__|o--GP2-----------|___|- ->|---Vss
36 auf einem Steckbrett. (Genauer gesagt, dies ist die aktuelle Beschaltung
37 fuer V1.8, V1.0 ist aber bzgl. IRMP-Empfang funktional identisch. Nicht eingezeichnet
38 ist ein Abblockkondensator von 100nF ueber Vss und Vdd.
40 Uebersetzt mit Microchip MPLAB XC8 C Compiler (Free Mode) V1.31
41 im stark gecrippelten "Free Mode".
43 Memory Summary: (V 1.8)
44 Program space used C6Fh ( 3183) of 1000h words ( 77.7%)
45 Data space used 9Bh ( 155) of 100h bytes ( 60.5%)
46 EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
47 Data stack space used 0h ( 0) of 5Eh bytes ( 0.0%)
48 Configuration bits used 2h ( 2) of 2h words (100.0%)
49 ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
55 urspruengliche Version des Programms als Empfaenger,
56 aktuelle Version als Sender, Aufzeichnung mit putty,
57 angeschlossen jeweils per USB2RS232-Kabel von Conrad
58 (972543, basierend auf Prolific PL2303). Soft-UART
59 fuer Input, da 12F1820 keine Kontrolle ueber Input-
60 Polaritaet erlaubt und ich fuer Testaufbauten eine
61 Minimalbeschaltung bevorzuge.
64 (~30 cm) zwischen Sender und Empfaenger), keine genaue Ausrichtung.
65 Stromversorgung wahlwweise mit 5V via PICkit 2 oder 3x1.2V NiMH-AA.
68 CD TAPE TUNER AUX OFF mit Philips FB,
69 OFF mit VAOVA TV-2900HDD FB
70 dann Eingabe . und n beim Sender.
74 IRMP PIC 12F1840 1.8 ws
75 P 7 a=0x0014 c=0x003f f=0x00 (RC5)
76 P 7 a=0x0014 c=0x003f f=0x01 (RC5)
77 P 7 a=0x0012 c=0x003f f=0x00 (RC5)
78 P 7 a=0x0011 c=0x003f f=0x00 (RC5)
79 P 7 a=0x0015 c=0x003f f=0x00 (RC5)
80 P 7 a=0x0015 c=0x000c f=0x00 (RC5)
81 P 2 a=0xbf00 c=0x0059 f=0x00 (NEC)
82 P 2 a=0xbf00 c=0x0059 f=0x01 (NEC)
88 IRMP PIC 12F1840 1.0 ws
89 P 7 a=0x0014 c=0x003f f=0x00 (RC5)
90 P 7 a=0x0014 c=0x003f f=0x01 (RC5)
91 P 7 a=0x0012 c=0x003f f=0x00 (RC5)
92 P 7 a=0x0011 c=0x003f f=0x00 (RC5)
93 P 7 a=0x0015 c=0x000c f=0x00 (RC5)
94 P 2 a=0xbf00 c=0x0059 f=0x00 (NEC)
95 P 2 a=0xbf00 c=0x0059 f=0x01 (NEC)
96 P 7 a=0x0015 c=0x000c f=0x00 (RC5)
97 P 7 a=0x0015 c=0x000c f=0x01 (RC5)
98 P 7 a=0x0015 c=0x000c f=0x01 (RC5)
99 P 2 a=0x0055 c=0x00aa f=0x00 (NEC)
101 Die via DSO an der LED gemessenen Frequenzen sind 36.0 resp. 38.0 kHz
110 /******************************************************************************/
112 /******************************************************************************/
113 #define SYS_FREQ 32000000L
114 #define _XTAL_FREQ 32000000 // for _delay
115 #define FCY (SYS_FREQ/4)
117 /******************************************************************************/
119 /******************************************************************************/
128 SPLLEN
=1; // p 46 and 54
131 /******************************************************************************/
132 // "configuration_bits.c" 12F1848
133 /******************************************************************************/
135 #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
136 #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
137 #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
138 #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
139 #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
140 #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
141 #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
142 #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
143 #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
144 #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
147 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
148 #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
149 #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
150 #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
151 #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
152 /******************************************************************************/
154 /******************************************************************************/
156 /******************************************************************************/
161 #define SOFTUART_RXPIN GPIO3
162 #define SOFTUART_STDIO 1
163 #define SOFTUART_DI 1
166 #define BAUD 19200 // 38200 ginge auch noch
167 #define SOFTUART_BAUD BAUD
168 #include "softuart_pic.h"
170 #define kbhit softuartkbhit
177 TXCKSEL
= 1; // put TX on pin 4 - not 0 -, p 102
178 SPBRGL
= (_XTAL_FREQ
/BAUD
/64-1);
183 SYNC
= 0; // 0 p. 267
184 SPEN
= 1; // 26.1.1.7
185 SCKP
= 1; // invert p 269
193 while (!TRMT
) _delay(1);
197 /******************************************************************************/
199 /******************************************************************************/
205 TMR1
=0xFC00; // p. 155 wait 1024 cycles for stabilization.
206 TMR1CS1
=0; // Clock source == System Clock
208 TMR1IE
=1; // enable TMR1 interrupts
209 PEIE
=1; // enable Pheripheral Interrupts
215 /******************************************************************************/
217 /******************************************************************************/
219 void interrupt
isr(void)
221 TMR1
=0xffff-_XTAL_FREQ
/F_INTERRUPTS
;
222 TMR1IF
=0; // clear timer 1 interrupt
233 void RC5(uint16_t addr
,uint16_t cmd
, uint8_t repetitions
)
235 irmp_data
.protocol
= IRMP_RC5_PROTOCOL
;
236 irmp_data
.address
= addr
;
237 irmp_data
.command
= cmd
;
238 irmp_data
.flags
= repetitions
;
239 irsnd_send_data (&irmp_data
, FALSE
);
242 void NEC(int addr
,int cmd
)
244 irmp_data
.protocol
= IRMP_NEC_PROTOCOL
;
245 irmp_data
.address
= addr
;
246 irmp_data
.command
= cmd
;
248 irsnd_send_data (&irmp_data
, FALSE
);
252 /******************************************************************************/
254 /******************************************************************************/
267 printf("IRMP PIC 12F1840 1.8 ws\r\n");
268 irmp_init(); // initialize irmp
269 timer1_init(); // initialize timer1
270 ei(); // enable interrupts
271 TMR1ON
=1; // start timer
278 if (c
>32 && c
<127) putch(c
);
283 RC5(0x15,0x0c,2); // Philips MC115 AUX OFF
295 while (irsnd_is_busy ()) ;
296 printf("PR2 %d\r\n",PR2
);
299 if (irmp_get_data (&irmp_data
))
302 printf("%d a=0x%04x c=0x%04x f=0x%02x (",irmp_data
.protocol
, irmp_data
.address
,irmp_data
.command
,irmp_data
.flags
);
304 #if IRMP_PROTOCOL_NAMES
305 printf(irmp_protocol_names
[irmp_data
.protocol
]);
307 switch(irmp_data
.protocol
)