]> 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:47:48 +0000 (14:47 +0000)
committerukw <ukw@aeb2e35e-bfc4-4214-b83c-9e8de998ed28>
Tue, 12 Jan 2016 14:47:48 +0000 (14:47 +0000)
git-svn-id: svn://mikrocontroller.net/irmp@176 aeb2e35e-bfc4-4214-b83c-9e8de998ed28

irmp-main-pic-12F1840.c

index fbeaff79e2637d2d0e96c3b6cf3bd60fcdc56281..235105e52aca650a098d1f9fe5b881bbcdbefa0f 100644 (file)
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
- * main_pic.c - example main module \r
+ * main_pic12f1840.c - example main module for PIC 12f1840\r
  * \r
  * IR decoder using IRMP\r
  *\r
- * (c) 2014 Wolfgang Strobl (ws at mystrobl.de) 2014-03-12:2014-07-05\r
+ * (c) 2014 Wolfgang Strobl (news4 at mystrobl.de) 2014-03-12:2014-07-20\r
  *\r
  * This demo module is runnable on a Microchip PIC 12F1840\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
+Hauptprogramm fuer den nachfolgenden Testaufbau, bestehend aus zwei mal \r
+\r
+\r
+             TSOP1736+        PIC12F1840\r
+                     |         __\r
+              1k     |  Vdd--o| o|o--Vss\r
+             ___     +--GP5--o|  |o--GP0 / ICSPDAT\r
+RS232 out  -|___|-------GP4--o|  |o--GP1 / ICSPCLK  ___    LED\r
+RS232 in   -|___|---Vpp/GP3--o|__|o--GP2-----------|___|- ->|---Vss\r
+             10k\r
+             \r
+auf einem Steckbrett. (Genauer gesagt, dies ist die aktuelle Beschaltung\r
+fuer V1.8,  V1.0 ist aber bzgl. IRMP-Empfang funktional identisch. Nicht eingezeichnet\r
+ist ein Abblockkondensator von 100nF ueber Vss und Vdd.\r
+\r
+Uebersetzt mit Microchip MPLAB XC8 C Compiler (Free Mode) V1.31 \r
+im stark gecrippelten "Free Mode".\r
+\r
+Memory Summary: (V 1.8)\r
+    Program space        used   C6Fh (  3183) of  1000h words   ( 77.7%)\r
+    Data space           used    9Bh (   155) of   100h bytes   ( 60.5%)\r
+    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)\r
+    Data stack space     used     0h (     0) of    5Eh bytes   (  0.0%)\r
+    Configuration bits   used     2h (     2) of     2h words   (100.0%)\r
+    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)\r
+\r
+\r
+Testaufbau: \r
+\r
+Zwei Steckbretter,\r
+urspruengliche Version des Programms als Empfaenger, \r
+aktuelle Version als Sender, Aufzeichnung mit putty,\r
+angeschlossen jeweils per USB2RS232-Kabel von Conrad\r
+(972543, basierend auf Prolific PL2303). Soft-UART \r
+fuer Input, da 12F1820 keine Kontrolle ueber Input-\r
+Polaritaet erlaubt und ich fuer Testaufbauten eine\r
+Minimalbeschaltung bevorzuge.\r
+\r
+Kurze Distanz\r
+(~30 cm) zwischen Sender und Empfaenger), keine genaue Ausrichtung.\r
+Stromversorgung wahlwweise mit 5V via PICkit 2 oder 3x1.2V NiMH-AA.\r
+\r
+Zunaechst \r
+CD TAPE TUNER AUX OFF mit Philips FB, \r
+OFF mit VAOVA TV-2900HDD FB\r
+dann Eingabe . und n beim Sender.\r
+\r
+Sender:\r
+\r
+IRMP PIC 12F1840 1.8 ws\r
+P 7 a=0x0014 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0014 c=0x003f f=0x01 (RC5)\r
+P 7 a=0x0012 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0011 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0015 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0015 c=0x000c f=0x00 (RC5)\r
+P 2 a=0xbf00 c=0x0059 f=0x00 (NEC)\r
+P 2 a=0xbf00 c=0x0059 f=0x01 (NEC)\r
+. MX115OFF PR2 221\r
+n NEC PR2 209\r
+\r
+Empfaenger:\r
+\r
+IRMP PIC 12F1840 1.0 ws\r
+P 7 a=0x0014 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0014 c=0x003f f=0x01 (RC5)\r
+P 7 a=0x0012 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0011 c=0x003f f=0x00 (RC5)\r
+P 7 a=0x0015 c=0x000c f=0x00 (RC5)\r
+P 2 a=0xbf00 c=0x0059 f=0x00 (NEC)\r
+P 2 a=0xbf00 c=0x0059 f=0x01 (NEC)\r
+P 7 a=0x0015 c=0x000c f=0x00 (RC5)\r
+P 7 a=0x0015 c=0x000c f=0x01 (RC5)\r
+P 7 a=0x0015 c=0x000c f=0x01 (RC5)\r
+P 2 a=0x0055 c=0x00aa f=0x00 (NEC)\r
+\r
+Die via DSO an der LED gemessenen Frequenzen sind 36.0 resp. 38.0 kHz\r
 \r
 */\r
 \r
 #include <stdio.h>\r
 \r
 #include "irmp.h"\r
+#include "irsnd.h"\r
 \r
 /******************************************************************************/\r
 // "system.h"\r
@@ -90,10 +153,19 @@ void InitApp(void)
 // UART\r
 /******************************************************************************/\r
 \r
-// This demo module uses RS232 TX via EUSART, only\r
+#define GPIO3 RA3 \r
+#define GPIO4 RA4 \r
+\r
+#define SOFTUART_RXPIN  GPIO3\r
+#define SOFTUART_STDIO 1\r
+#define SOFTUART_DI 1\r
+\r
 \r
-#define useEUSART 1\r
-#define BAUD 19200\r
+#define BAUD 19200 // 38200 ginge auch noch\r
+#define SOFTUART_BAUD BAUD\r
+#include "softuart_pic.h"\r
+\r
+#define kbhit softuartkbhit\r
 \r
 \r
 void \r
@@ -133,7 +205,8 @@ timer1_init(void)
     TMR1CS0=1; \r
     TMR1IE=1; // enable TMR1 interrupts\r
     PEIE=1;   // enable Pheripheral Interrupts\r
-    \r
+    TMR1IF=0;\r
+    TMR1ON=1;\r
 }\r
 \r
 \r
@@ -143,11 +216,37 @@ timer1_init(void)
 \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
+    if (!irsnd_ISR())\r
+    {\r
+        irmp_ISR();\r
+    }\r
 }\r
 \r
+\r
+IRMP_DATA irmp_data;\r
+\r
+void RC5(uint16_t addr,uint16_t  cmd, uint8_t repetitions)\r
+{\r
+    irmp_data.protocol = IRMP_RC5_PROTOCOL;                       \r
+    irmp_data.address  = addr;\r
+    irmp_data.command  = cmd;\r
+    irmp_data.flags    = repetitions;\r
+    irsnd_send_data (&irmp_data, FALSE); \r
+}\r
+\r
+void NEC(int addr,int cmd)\r
+{\r
+    irmp_data.protocol = IRMP_NEC_PROTOCOL;                       \r
+    irmp_data.address  = addr;\r
+    irmp_data.command  = cmd;\r
+    irmp_data.flags    = 0;\r
+    irsnd_send_data (&irmp_data, FALSE); \r
+}\r
+\r
+\r
 /******************************************************************************/\r
 // MAIN\r
 /******************************************************************************/\r
@@ -156,26 +255,50 @@ int
 main (void)\r
 {\r
     IRMP_DATA irmp_data;\r
-    InitApp(); // später inlinen\r
-    \r
-#if useEUSART\r
+    char c;\r
+    InitApp(); \r
+\r
+    PWMoff();\r
     RS232init();\r
-#endif\r
+    \r
     __delay_ms(200);\r
-    printf("IRMP PIC 12F1840 1.1 ws\r\n");\r
-    irmp_init();                                                            // initialize irmp\r
+    printf("IRMP PIC 12F1840 1.8 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 (kbhit())\r
+        {\r
+            c=getch();\r
+            if (c>32 && c<127) putch(c);\r
+            putch(' ');\r
+            if (c=='.')\r
+            {\r
+                printf("MX115OFF ");\r
+                RC5(0x15,0x0c,2); // Philips MC115 AUX OFF\r
+            }\r
+            else if (c=='n')\r
+            {\r
+                printf("NEC ");\r
+                NEC(0x55,0xaa); \r
+            }\r
+            else\r
+            {\r
+                putch('?');\r
+                continue;\r
+            }\r
+            while (irsnd_is_busy ()) ;\r
+            printf("PR2 %d\r\n",PR2);\r
+            continue;\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