]> cloudbase.mooo.com Git - irmp.git/commitdiff
Version 3.0: corrected ESP8266 port, added MBED port, added several main example...
authorukw <ukw@aeb2e35e-bfc4-4214-b83c-9e8de998ed28>
Tue, 12 Jan 2016 14:23:26 +0000 (14:23 +0000)
committerukw <ukw@aeb2e35e-bfc4-4214-b83c-9e8de998ed28>
Tue, 12 Jan 2016 14:23:26 +0000 (14:23 +0000)
git-svn-id: svn://mikrocontroller.net/irmp@175 aeb2e35e-bfc4-4214-b83c-9e8de998ed28

irmp-main-pic-12F1840.c [new file with mode: 0644]

diff --git a/irmp-main-pic-12F1840.c b/irmp-main-pic-12F1840.c
new file mode 100644 (file)
index 0000000..fbeaff7
--- /dev/null
@@ -0,0 +1,201 @@
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ * main_pic.c - example main module \r
+ * \r
+ * IR decoder using IRMP\r
+ *\r
+ * (c) 2014 Wolfgang Strobl (ws at mystrobl.de) 2014-03-12:2014-07-05\r
+ *\r
+ * This demo module is runnable on a Microchip PIC 12F1840\r
+ *\r
+ * To be used with IRMP by Frank Meyer (frank(at)fli4l.de)\r
+ * <http://www.mikrocontroller.net/articles/IRMP>\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
\r
\r
+/* \r
+                              PIC12F1840\r
+       ___                     __\r
+ 10k -|___|-+           Vdd -o| o|o- Vss\r
+       ___  +-RS232in / GP5 -o|  |o- GP0 / ICSPDAT\r
+  1k -|___|-- RS232out/ GP4 -o|  |o- GP1 / ICSPCLK \r
+                  Vpp / GP3 -o|__|o- GP2 / TS TSOP1736\r
+Example output, using a bunch of different remote controls\r
+IRMP PIC 12F1840 1.1 ws\r
+P 7 a=0x0011 c=0x000c f=0x00 (RC5)\r
+P 6 a=0x0001 c=0x0018 f=0x00 (RECS80)\r
+P 2 a=0xbf00 c=0x0019 f=0x00 (NEC)\r
+P 2 a=0xeb14 c=0x0001 f=0x00 (NEC)\r
+P 7 a=0x001c c=0x0005 f=0x00 (RC5)\r
+P 7 a=0x000a c=0x0057 f=0x00 (RC5)\r
+P 7 a=0x000a c=0x0057 f=0x01 (RC5)\r
+P 2 a=0xfb04 c=0x0008 f=0x00 (NEC)\r
+\r
+*/\r
+\r
+#include <stdio.h>\r
+\r
+#include "irmp.h"\r
+\r
+/******************************************************************************/\r
+// "system.h"\r
+/******************************************************************************/\r
+#define SYS_FREQ        32000000L\r
+#define _XTAL_FREQ      32000000   // for _delay\r
+#define FCY             (SYS_FREQ/4)\r
+\r
+/******************************************************************************/\r
+// "user.c"\r
+/******************************************************************************/\r
+void InitApp(void)\r
+{\r
+    ANSELA=0;\r
+    TRISA4=0;\r
+    IRCF0=0; // p. 45\r
+    IRCF1=1;\r
+    IRCF2=1;\r
+    IRCF3=1;\r
+    SPLLEN=1; // p  46 and 54 \r
+}\r
+\r
+/******************************************************************************/\r
+// "configuration_bits.c" 12F1848\r
+/******************************************************************************/\r
+// CONFIG1\r
+#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)\r
+#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)\r
+#pragma config PWRTE = ON       // Power-up Timer Enable (PWRT enabled)\r
+#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)\r
+#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)\r
+#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)\r
+#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)\r
+#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)\r
+#pragma config IESO = OFF       // Internal/External Switchover (Internal/External Switchover mode is disabled)\r
+#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)\r
+\r
+// CONFIG2\r
+#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)\r
+#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)\r
+#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)\r
+#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)\r
+#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)\r
+/******************************************************************************/\r
+\r
+/******************************************************************************/\r
+// UART\r
+/******************************************************************************/\r
+\r
+// This demo module uses RS232 TX via EUSART, only\r
+\r
+#define useEUSART 1\r
+#define BAUD 19200\r
+\r
+\r
+void \r
+RS232init(void)\r
+ {\r
+     // Transmit\r
+     TXCKSEL = 1;                 //  put TX on pin 4 - not 0 -, p 102\r
+     SPBRGL = (_XTAL_FREQ/BAUD/64-1);  \r
+     SPBRGH = 0;\r
+     BRGH = 0;\r
+     BRG16 = 0;\r
+     // p 259 manual\r
+     SYNC = 0;                  // 0 p. 267\r
+     SPEN = 1;                  //  26.1.1.7\r
+     SCKP = 1;                  // invert p 269\r
+     TXEN = 1;\r
+ }\r
+\r
+ // EUSART transmit\r
+ void \r
+ putch(char c)\r
+ {\r
+    while (!TRMT) _delay(1);\r
+    TXREG=c;\r
+ }\r
\r
+/******************************************************************************/\r
+// Timer and ISR\r
+/******************************************************************************/\r
\r
+void \r
+timer1_init(void)\r
+{\r
+    // p 154\r
+    TMR1=0xFC00; // p. 155 wait 1024 cycles for stabilization.\r
+    TMR1CS1=0; // Clock source == System Clock\r
+    TMR1CS0=1; \r
+    TMR1IE=1; // enable TMR1 interrupts\r
+    PEIE=1;   // enable Pheripheral Interrupts\r
+    \r
+}\r
+\r
+\r
+/******************************************************************************/\r
+// Interrupt handler\r
+/******************************************************************************/\r
+\r
+void interrupt isr(void)\r
+{\r
+    irmp_ISR();\r
+    TMR1=0xffff-_XTAL_FREQ/F_INTERRUPTS; \r
+    TMR1IF=0; // clear timer 1 interrupt\r
+}\r
+\r
+/******************************************************************************/\r
+// MAIN\r
+/******************************************************************************/\r
+\r
+int\r
+main (void)\r
+{\r
+    IRMP_DATA irmp_data;\r
+    InitApp(); // später inlinen\r
+    \r
+#if useEUSART\r
+    RS232init();\r
+#endif\r
+    __delay_ms(200);\r
+    printf("IRMP PIC 12F1840 1.1 ws\r\n");\r
+    irmp_init();                                                            // initialize irmp\r
+    timer1_init();            // initialize timer1\r
+    ei();                     // enable interrupts\r
+    TMR1ON=1; // start timer\r
+  \r
+    for (;;)\r
+    {\r
+        if (irmp_get_data (&irmp_data))\r
+        {\r
+            printf("P ");\r
+            printf("%d a=0x%04x c=0x%04x f=0x%02x (",irmp_data.protocol, irmp_data.address,irmp_data.command,irmp_data.flags); \r
+            \r
+            \r
+#if IRMP_PROTOCOL_NAMES\r
+            printf(irmp_protocol_names[irmp_data.protocol]);\r
+#else            \r
+            switch(irmp_data.protocol)\r
+            {\r
+                case 1:\r
+                    printf("Sony");\r
+                    break;\r
+                case 2:\r
+                    printf("NEC");\r
+                    break;\r
+                case 7:\r
+                    printf("RC5");\r
+                    break;\r
+                case 0x21:\r
+                    printf("Ortek");\r
+                    break;\r
+            }\r
+#endif\r
+            printf(")\r\n");\r
+        }\r
+    }\r
+}\r