]> cloudbase.mooo.com Git - irmp.git/commitdiff
Version 2.6.2: port to PIC 12F1840
authorukw <ukw@aeb2e35e-bfc4-4214-b83c-9e8de998ed28>
Mon, 21 Jul 2014 09:05:03 +0000 (09:05 +0000)
committerukw <ukw@aeb2e35e-bfc4-4214-b83c-9e8de998ed28>
Mon, 21 Jul 2014 09:05:03 +0000 (09:05 +0000)
git-svn-id: svn://mikrocontroller.net/irmp@143 aeb2e35e-bfc4-4214-b83c-9e8de998ed28

14 files changed:
README.txt
irmp.c
irmp.h
irmpconfig.h
irmpprotocols.h
irmpsystem.h
irsnd.c
irsnd.h
irsndconfig.h
irsndmain.c
main.c
pic/main_pic.c [new file with mode: 0644]
pic/main_pic12f1840.c [new file with mode: 0644]
pic/softuart_pic.h [new file with mode: 0644]

index 58afd88a84e7df4e27f2e05e49ac3b68617979dd..24bd1ca40175a975cf90da813e56ca421dba9fd2 100644 (file)
@@ -1,8 +1,8 @@
 IRMP - Infrared Multi Protocol Decoder\r
 --------------------------------------\r
 \r
-Version IRMP:  2.6.0 09.07.2014\r
-Version IRSND: 2.6.1 10.07.2014\r
+Version IRMP:  2.6.2 21.07.2014\r
+Version IRSND: 2.6.2 21.07.2014\r
 \r
 Dokumentation:\r
  \r
diff --git a/irmp.c b/irmp.c
index 851c270f63beb6976962bae3598495d92798815c..5b25eea0f57d6693fcbf4103bcc0fc84866c5d25 100644 (file)
--- a/irmp.c
+++ b/irmp.c
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * irmp.c - infrared multi-protocol decoder, supports several remote control protocols\r
  *\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmp.c,v 1.159 2014/07/09 15:31:25 fm Exp $\r
+ * $Id: irmp.c,v 1.161 2014/07/21 08:58:58 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
@@ -498,7 +498,7 @@ static void                                     (*irmp_callback_ptr) (uint8_t);
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
 #if defined(UNIX_OR_WINDOWS) || IRMP_PROTOCOL_NAMES == 1\r
-char *\r
+const char *\r
 irmp_protocol_names[IRMP_N_PROTOCOLS + 1] =\r
 {\r
     "UNKNOWN",\r
diff --git a/irmp.h b/irmp.h
index faa4201e2f5ee6e41b3e2f9029a30cdf146e3c93..8b61f25a449d95a7a83027629937e1ed78290c1f 100644 (file)
--- a/irmp.h
+++ b/irmp.h
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * irmp.h\r
  *\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmp.h,v 1.86 2014/07/09 15:26:02 fm Exp $\r
+ * $Id: irmp.h,v 1.88 2014/07/21 08:58:58 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
@@ -178,7 +178,7 @@ extern uint8_t                          irmp_is_busy (void);
 extern uint8_t                          irmp_ISR (void);\r
 \r
 #if IRMP_PROTOCOL_NAMES == 1\r
-extern char *                           irmp_protocol_names[IRMP_N_PROTOCOLS + 1];\r
+extern const char *                     irmp_protocol_names[IRMP_N_PROTOCOLS + 1];\r
 #endif\r
 \r
 #if IRMP_USE_CALLBACK == 1\r
index 5c78bd416b54a634c764493fb105027496eef3a5..218e939a9fda7ce475fbd445f885a6701125157d 100644 (file)
@@ -3,11 +3,10 @@
  *\r
  * DO NOT INCLUDE THIS FILE, WILL BE INCLUDED BY IRMP.H!\r
  *\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
+ * Extensions for PIC 12F1820 W.Strobl 2014-07-20\r
  *\r
- * $Id: irmpconfig.h,v 1.116 2014/07/10 09:49:24 fm Exp $\r
- *\r
- * ATMEGA88 @ 8 MHz\r
+ * $Id: irmpconfig.h,v 1.117 2014/07/21 08:56:39 fm Exp $\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
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
 #elif defined (PIC_C18)                                                 // use RB4 as IR input on PIC (C18 or XC8 compiler)\r
-#  define IRMP_PIN                              PORTBbits.RB4\r
+#if defined(__12F1840)\r
+#  define IRMP_PIN                              RA5                     // on 12F1840 with XC8 compiler\r
+#endif\r
+#  define IRMP_PIN                              PORTBbits.RB4           // PIC C18\r
 \r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * Change hardware pin here for PIC CCS compiler\r
index 0f66c9cf599872df2ecfce143268f442d267d43b..05c009dd489077a9ab2f6cb5b7ad841aaec2c1fa 100644 (file)
@@ -3,9 +3,9 @@
  *\r
  * DO NOT INCLUDE THIS FILE, WILL BE INCLUDED BY IRMP.H or IRSND.H!\r
  *\r
- * Copyright (c) 2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2013-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmpprotocols.h,v 1.25 2014/07/09 14:45:56 fm Exp $\r
+ * $Id: irmpprotocols.h,v 1.26 2014/07/21 08:58:58 fm Exp $\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
index fdd2fa3acf521ffc7091cf784bc9c7d8717919b7..575bfdaa44158799fc7500c1eb126130024d84c4 100644 (file)
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * irmpsystem.h - system specific includes and defines\r
  *\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irmpsystem.h,v 1.12 2014/07/01 20:08:20 fm Exp $\r
+ * $Id: irmpsystem.h,v 1.13 2014/07/21 08:58:58 fm Exp $\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
diff --git a/irsnd.c b/irsnd.c
index c5f7004d398454d1cca824067a532c31e5d1d0e9..447971e74152439e728226ac6dea08d05d3bbc13 100644 (file)
--- a/irsnd.c
+++ b/irsnd.c
@@ -1,7 +1,7 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * @file irsnd.c\r
  *\r
- * Copyright (c) 2010-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
  * Supported mikrocontrollers:\r
  *\r
@@ -13,7 +13,7 @@
  * ATmega164, ATmega324, ATmega644,  ATmega644P, ATmega1284, ATmega1284P\r
  * ATmega88,  ATmega88P, ATmega168,  ATmega168P, ATmega328P\r
  *\r
- * $Id: irsnd.c,v 1.79 2014/07/10 10:38:07 fm Exp $\r
+ * $Id: irsnd.c,v 1.81 2014/07/21 08:58:58 fm Exp $\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
@@ -505,14 +505,34 @@ irsnd_off (void)
  *  @details  sets pwm frequency\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
+#if defined(__12F1840)\r
+extern void pwm_init(uint16_t freq);\r
+#include <stdio.h>\r
+#endif\r
+\r
 static void\r
 irsnd_set_freq (IRSND_FREQ_TYPE freq)\r
 {\r
 #ifndef ANALYZE\r
-#  if defined(PIC_C18)                                                                      // PIC C18\r
-         OpenPWM(freq); \r
-         SetDCPWM( (uint16_t) (freq * 2) + 1); // freq*2 = Duty cycles 50%\r
-         PWMoff();\r
+#  if defined(PIC_C18)                                                                      // PIC C18 or XC8\r
+#    if defined(__12F1840)                                                                  // XC8\r
+        TRISA2=0; \r
+        PR2=freq;\r
+        CCP1M0=1;\r
+        CCP1M1=1;\r
+        CCP1M2=1;\r
+        CCP1M3=1;\r
+        DC1B0=1;\r
+        DC1B1=0;\r
+        CCPR1L = 0b01101001;\r
+        TMR2IF = 0;\r
+        TMR2ON=1;\r
+        CCP1CON &=(~0b0011); // p 197 "active high"\r
+#    else                                                                                   // PIC C18\r
+        OpenPWM(freq); \r
+        SetDCPWM( (uint16_t) (freq * 2) + 1); // freq*2 = Duty cycles 50%\r
+#    endif\r
+        PWMoff();\r
 #  elif defined (ARM_STM32)                                                                 // STM32\r
          static uint32_t      TimeBaseFreq = 0;\r
 \r
@@ -578,8 +598,10 @@ void
 irsnd_init (void)\r
 {\r
 #ifndef ANALYZE\r
-#  if defined(PIC_C18)                                                      // PIC C18\r
+#  if defined(PIC_C18)                                                      // PIC C18 or XC8 compiler\r
+#    if ! defined(__12F1840)                                                // only C18:\r
         OpenTimer;\r
+#    endif\r
         irsnd_set_freq (IRSND_FREQ_36_KHZ);                                 // default frequency\r
         IRSND_PIN = 0;                                                      // set IO to outout\r
         PWMoff();\r
@@ -2095,7 +2117,7 @@ irsnd_ISR (void)
                                 if (current_bit < SAMSUNG_ADDRESS_LEN)                              // send address bits\r
                                 {\r
                                     pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ?\r
                                                     (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
                                 }\r
                                 else if (current_bit == SAMSUNG_ADDRESS_LEN)                        // send SYNC bit (16th bit)\r
@@ -2108,7 +2130,7 @@ irsnd_ISR (void)
                                     uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
 \r
                                     pulse_len = SAMSUNG_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[cur_bit >> 3] & (1<<(7-(cur_bit & 7)))) ?\r
                                                     (SAMSUNG_1_PAUSE_LEN - 1) : (SAMSUNG_0_PAUSE_LEN - 1);\r
                                 }\r
                             }\r
@@ -2121,7 +2143,7 @@ irsnd_ISR (void)
                                 if (current_bit < NEC16_ADDRESS_LEN)                                // send address bits\r
                                 {\r
                                     pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ?\r
                                                     (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
                                 }\r
                                 else if (current_bit == NEC16_ADDRESS_LEN)                          // send SYNC bit (8th bit)\r
@@ -2134,7 +2156,7 @@ irsnd_ISR (void)
                                     uint8_t cur_bit = current_bit - 1;                              // sync skipped, offset = -1 !\r
 \r
                                     pulse_len = NEC_PULSE_LEN;\r
-                                    pause_len = (irsnd_buffer[cur_bit / 8] & (1<<(7-(cur_bit % 8)))) ?\r
+                                    pause_len = (irsnd_buffer[cur_bit >> 3] & (1<<(7-(cur_bit & 7)))) ?\r
                                                     (NEC_1_PAUSE_LEN - 1) : (NEC_0_PAUSE_LEN - 1);\r
                                 }\r
                             }\r
@@ -2166,7 +2188,7 @@ irsnd_ISR (void)
                                 }\r
                                 else if (current_bit < BANG_OLUFSEN_COMPLETE_DATA_LEN)              // send n'th bit\r
                                 {\r
-                                    uint8_t cur_bit_value = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? 1 : 0;\r
+                                    uint8_t cur_bit_value = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? 1 : 0;\r
                                     pulse_len = BANG_OLUFSEN_PULSE_LEN;\r
 \r
                                     if (cur_bit_value == last_bit_value)\r
@@ -2182,7 +2204,7 @@ irsnd_ISR (void)
                             }\r
                             else\r
 #endif\r
-                            if (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8))))\r
+                            if (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7))))\r
                             {\r
                                 pulse_len = pulse_1_len;\r
                                 pause_len = pause_1_len;\r
@@ -2349,7 +2371,7 @@ irsnd_ISR (void)
                             {\r
                                 pulse_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
                                 pause_len = GRUNDIG_NOKIA_IR60_BIT_LEN;\r
-                                first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
+                                first_pulse = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? TRUE : FALSE;\r
                             }\r
                         }\r
                         else // if (irsnd_protocol == IRMP_RC5_PROTOCOL || irsnd_protocol == IRMP_RC6_PROTOCOL || irsnd_protocol == IRMP_RC6A_PROTOCOL ||\r
@@ -2409,7 +2431,7 @@ irsnd_ISR (void)
                                     }\r
                                 }\r
 #endif\r
-                                first_pulse = (irsnd_buffer[current_bit / 8] & (1<<(7-(current_bit % 8)))) ? TRUE : FALSE;\r
+                                first_pulse = (irsnd_buffer[current_bit >> 3] & (1<<(7-(current_bit & 7)))) ? TRUE : FALSE;\r
                             }\r
 \r
                             if (irsnd_protocol == IRMP_RC5_PROTOCOL)\r
diff --git a/irsnd.h b/irsnd.h
index 28f90df84fd75fb04ae0aa8844a27cc933c4107c..e9e1736c6626dcf5991a21a84e6503733a4a8712 100644 (file)
--- a/irsnd.h
+++ b/irsnd.h
@@ -1,9 +1,9 @@
-/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * irsnd.h\r
  *\r
- * Copyright (c) 2010-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irsnd.h,v 1.17 2014/02/19 12:57:36 fm Exp $\r
+ * $Id: irsnd.h,v 1.19 2014/07/21 08:58:58 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
 #  endif\r
 \r
 #elif defined(PIC_C18)\r
-// Do not change lines below until you have a different HW. Example is for 18F2550/18F4550\r
-// setup macro for PWM used PWM module\r
-#  if IRSND_OCx == IRSND_PIC_CCP2        \r
-#    define PWMon()                             TMR2=0,CCP2CON |=0b1100\r
-#    define PWMoff()                            CCP2CON &=(~0b1100)\r
-#    define IRSND_PIN                           TRISCbits.TRISC1        // RC1 = PWM2\r
-#    define SetDCPWM(x)                         SetDCPWM2(x)                    \r
-#    define ClosePWM                            ClosePWM2\r
-#    define OpenPWM(x)                          OpenPWM2(x) \r
-#  endif\r
-#  if IRSND_OCx == IRSND_PIC_CCP1        \r
-#    define PWMon()                             TMR2=0,CCP1CON |=0b1100\r
-#    define PWMoff()                            CCP1CON &=(~0b1100)\r
-#    define IRSND_PIN                           TRISCbits.TRISC2        // RC2 = PWM1\r
-#    define SetDCPWM(x)                         SetDCPWM1(x)\r
-#    define ClosePWM                            ClosePWM1\r
-#    define OpenPWM(x)                          OpenPWM1(x)\r
-#  endif\r
-//Setup macro for OpenTimer with defined Pre_Scaler\r
-#  if Pre_Scaler == 1\r
-#    define OpenTimer                               OpenTimer2(TIMER_INT_OFF & T2_PS_1_1); \r
-#  elif Pre_Scaler == 4\r
-#    define OpenTimer                               OpenTimer2(TIMER_INT_OFF & T2_PS_1_4); \r
-#  elif Pre_Scaler == 16\r
-#    define OpenTimer                               OpenTimer2(TIMER_INT_OFF & T2_PS_1_16); \r
-#  else\r
-#    error Incorrect value for Pre_Scaler\r
-#  endif\r
-#endif // ARM_STM32\r
+\r
+# if defined(__12F1840)\r
+    // Do not change lines below unless you have a different HW. This example is for 12F1840\r
+    // setup macro for PWM used PWM module\r
+         \r
+    //~ #    define PWMon()                         TMR2=0,IRSND_PIN=1\r
+    //~ #    define PWMoff()                        CCP1CON &=(~0b1100)\r
+    //~ #    define PWMon()                         TMR2ON=1\r
+    //~ #    define PWMoff()                        TMR2ON=0\r
+    #if defined(IRSND_DEBUG) \r
+        #define PWMon()                             LATA0=1\r
+        #define PWMoff()                            LATA0=0\r
+        #define IRSND_PIN                           LATA0\r
+    #else\r
+        #    define PWMon()                         TMR2=0,CCP1CON |=0b1100\r
+        #    define PWMoff()                        CCP1CON &=(~0b1100)\r
+        #    define IRSND_PIN                       RA2\r
+    #endif\r
+\r
+#else\r
+    // Do not change lines below until you have a different HW. Example is for 18F2550/18F4550\r
+    // setup macro for PWM used PWM module\r
+    #  if IRSND_OCx == IRSND_PIC_CCP2        \r
+    #    define PWMon()                             TMR2=0,CCP2CON |=0b1100\r
+    #    define PWMoff()                            CCP2CON &=(~0b1100)\r
+    #    define IRSND_PIN                           TRISCbits.TRISC1        // RC1 = PWM2\r
+    #    define SetDCPWM(x)                         SetDCPWM2(x)                    \r
+    #    define ClosePWM                            ClosePWM2\r
+    #    define OpenPWM(x)                          OpenPWM2(x) \r
+    #  endif\r
+    #  if IRSND_OCx == IRSND_PIC_CCP1        \r
+    #    define PWMon()                             TMR2=0,CCP1CON |=0b1100\r
+    #    define PWMoff()                            CCP1CON &=(~0b1100)\r
+    #    define IRSND_PIN                           TRISCbits.TRISC2        // RC2 = PWM1\r
+    #    define SetDCPWM(x)                         SetDCPWM1(x)\r
+    #    define ClosePWM                            ClosePWM1\r
+    #    define OpenPWM(x)                          OpenPWM1(x)\r
+    # endif \r
+# endif\r
+#  endif // PIC_C18\r
 \r
 #if IRSND_SUPPORT_SIEMENS_PROTOCOL == 1 && F_INTERRUPTS < 15000\r
 #  warning F_INTERRUPTS too low, SIEMENS protocol disabled (should be at least 15000)\r
index 402f1256af8637661450637e8b49b6d6daa654ad..97d1d355f7d9440dab10457e972615c11485276f 100644 (file)
@@ -3,9 +3,9 @@
  *\r
  * DO NOT INCLUDE THIS FILE, WILL BE INCLUDED BY IRSND.H!\r
  *\r
- * Copyright (c) 2010-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: irsndconfig.h,v 1.61 2014/07/10 10:38:07 fm Exp $\r
+ * $Id: irsndconfig.h,v 1.62 2014/07/21 08:56:39 fm Exp $\r
  *\r
  * ATMEGA88 @ 8 MHz\r
  *\r
@@ -23,6 +23,8 @@
 #  error please include only irsnd.h, not irsndconfig.h\r
 #endif\r
 \r
+//~ #define IRSND_DEBUG 1                                   // activate debugging\r
+\r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * F_INTERRUPTS: number of interrupts per second, should be in the range from 10000 to 20000, typically 15000\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
 #  define IRSND_OCx                             IRSND_OC2B              // use OC2B\r
 \r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
- * PIC C18 section:\r
+ * PIC C18 or XC8 section:\r
  *\r
  * Change hardware pin here:                    IRSND_PIC_CCP1 = RC2 on PIC 18F2550/18F4550, ...\r
  *                                              IRSND_PIC_CCP2 = RC1 on PIC 18F2550/18F4550, ...\r
  *---------------------------------------------------------------------------------------------------------------------------------------------------\r
  */\r
-#elif defined(PIC_C18)\r
+#elif defined(PIC_C18)                                                  // C18 or XC8 compiler\r
+# if defined(__12F1840)                                                 // XC8 compiler\r
+#  define Pre_Scaler                            1                       // define prescaler for timer2 e.g. 1,4,16\r
+#  define F_CPU                                 32000000UL              // PIC frequency: set your freq here\r
+#  define PIC_Scaler                            2                       // PIC needs /2 extra in IRSND_FREQ_32_KHZ calculation for right value\r
+\r
+# else                                                                  // C18 compiler\r
 #  define IRSND_OCx                             IRSND_PIC_CCP2          // Use PWMx for PIC\r
                                                                         // change other PIC C18 specific settings:\r
 #  define F_CPU                                 48000000UL              // PIC frequency: set your freq here\r
 #  define Pre_Scaler                            4                       // define prescaler for timer2 e.g. 1,4,16\r
 #  define PIC_Scaler                            2                       // PIC needs /2 extra in IRSND_FREQ_32_KHZ calculation for right value\r
-#  warning Timer2 used for IRSND (PWM out) ! Do not use/setup Timer 2 yourself !\r
+# endif\r
 \r
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * ARM STM32 section:\r
index ae918eca7011a3d1a893a2bb25f9900da0adce9c..ee6f6600ca19c4e473f7246d6429c5adf6f05e96 100644 (file)
@@ -1,7 +1,7 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * irsndmain.c - demo main module to test IRSND encoder on AVRs\r
  *\r
- * Copyright (c) 2010-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2010-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
  * ATMEGA88 @ 8 MHz internal RC      Osc with BODLEVEL 4.3V: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9\r
  * ATMEGA88 @ 8 MHz external Crystal Osc with BODLEVEL 4.3V: lfuse: 0xFF hfuse: 0xDC efuse: 0xF9\r
diff --git a/main.c b/main.c
index 25600d6d226f43f89aa3b7eb85b7743d7425e3d0..9c1cc24330efa2cacea584b5ab53ea3697c0eb58 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,9 +1,9 @@
 /*---------------------------------------------------------------------------------------------------------------------------------------------------\r
  * main.c - demo main module to test irmp decoder\r
  *\r
- * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
  *\r
- * $Id: main.c,v 1.18 2014/07/01 07:50:33 fm Exp $\r
+ * $Id: main.c,v 1.19 2014/07/21 08:58:59 fm Exp $\r
  *\r
  * This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4)\r
  *\r
diff --git a/pic/main_pic.c b/pic/main_pic.c
new file mode 100644 (file)
index 0000000..6b5eab5
--- /dev/null
@@ -0,0 +1,203 @@
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\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
+\r
+Example output, using a bunch of different remote controls\r
+\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
diff --git a/pic/main_pic12f1840.c b/pic/main_pic12f1840.c
new file mode 100644 (file)
index 0000000..235105e
--- /dev/null
@@ -0,0 +1,324 @@
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ * main_pic12f1840.c - example main module for PIC 12f1840\r
+ * \r
+ * IR decoder using IRMP\r
+ *\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
+ * 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
+\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
+/******************************************************************************/\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
+#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 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
+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
+    TMR1IF=0;\r
+    TMR1ON=1;\r
+}\r
+\r
+\r
+/******************************************************************************/\r
+// Interrupt handler\r
+/******************************************************************************/\r
+\r
+void interrupt isr(void)\r
+{\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
+\r
+int\r
+main (void)\r
+{\r
+    IRMP_DATA irmp_data;\r
+    char c;\r
+    InitApp(); \r
+\r
+    PWMoff();\r
+    RS232init();\r
+    \r
+    __delay_ms(200);\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
+#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
diff --git a/pic/softuart_pic.h b/pic/softuart_pic.h
new file mode 100644 (file)
index 0000000..3d40bc8
--- /dev/null
@@ -0,0 +1,151 @@
+/*\r
+                                                    W. Strobl, Bonn, March 2014\r
+                                        \r
+Simple minded software bit banging async RS232 implementation for Microchip XC8\r
+\r
+http://en.wikipedia.org/wiki/Bit_banging\r
+\r
+Tested with 2400, 9600 and 19200 baud on a 4 MHz 16F675 so far\r
+Tested with 9600 baud on a 32 MHz 12F1840. \r
+19200 softuard doesn't work.\r
+\r
+                              PIC12F1840\r
+\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 /\r
+\r
+Necessary definitions (examples)\r
+\r
+#define FCY 1000000             // cycles per second (4 MHz PIC)\r
+#define SOFTUART_RXPIN  GPIO5   // if input is desired\r
+#define SOFTUART_TXPIN  GPIO4   // if output is desired\r
+\r
+Optional definitions\r
+\r
+#define SOFTUART_BAUD 19200     // default: 9600\r
+#define SOFTUART_STDIO 1        // if definition for getch, putch is desired\r
+                                // default: 0\r
+#define SOFTUART_DI 1           // if interrupts are to be disabled during IO\r
+                                // default: 0\r
+#define SOFTUART_MARK 0         // 0: not inverted (default: 1)\r
+\r
+\r
+Typical:\r
+\r
+\r
+#define SOFTUART_RXPIN  GPIO5\r
+#define SOFTUART_TXPIN  GPIO4\r
+#define SOFTUART_STDIO 1\r
+#define SOFTUART_DI 1\r
+#include "softuart.h"\r
+\r
+#define kbhit softuartkbhit\r
+\r
+*/\r
+\r
+/******************************************************************************/\r
+// Software UART \r
+/******************************************************************************/\r
+// FCY == instructions per second, see system.h for xc8\r
+#ifndef SOFTUART_BAUD           // default baudrate\r
+#define SOFTUART_BAUD 9600\r
+#endif\r
+#define SOFTUART_BITLEN (FCY/SOFTUART_BAUD)\r
+#define SOFTUART_DELAY (SOFTUART_BITLEN/5)\r
+\r
+#ifndef SOFTUART_MARK\r
+#define SOFTUART_MARK 1         // 0: not inverted (default: 1)\r
+#endif\r
+\r
+\r
+// Input Pin defined?\r
+#ifdef SOFTUART_RXPIN\r
+/******************************************************************************/\r
+// Input\r
+/******************************************************************************/\r
+\r
+char softuartgetch(void)\r
+{\r
+    char rcvd,i; \r
+#if SOFTUART_DI\r
+    di();\r
+#endif\r
+    rcvd=0;\r
+    _delay(SOFTUART_BITLEN/2-10); // wait half a startbit\r
+    if (SOFTUART_RXPIN != SOFTUART_MARK) \r
+    {\r
+#if SOFTUART_DI\r
+        ei();\r
+#endif\r
+        return 0; // glitch\r
+    }\r
+    _delay(SOFTUART_BITLEN/2-10); // wait half a startbit\r
+    for (i=0;i<8;i++)\r
+    {\r
+        rcvd >>= 1; // shift previous bits, LSB comes first\r
+        _delay(SOFTUART_BITLEN/2-12); // ADJUST\r
+        rcvd |= ((SOFTUART_RXPIN != SOFTUART_MARK)?0x80:0);\r
+        _delay(SOFTUART_BITLEN/2-10); // ADJUST\r
+    }\r
+#ifdef SOFTUART_DI\r
+    ei();\r
+#endif\r
+    _delay(SOFTUART_BITLEN); // stopbit\r
+    return rcvd;\r
+}\r
+\r
+#define softuartkbhit() (SOFTUART_RXPIN == SOFTUART_MARK)\r
+\r
+#endif\r
+\r
+// Output Pin defined?\r
+#ifdef SOFTUART_TXPIN\r
+/******************************************************************************/\r
+// Output \r
+//******************************************************************************/\r
+\r
+#if defined(SOFTUART_TXPIN) || defined(SOFTUART_STDIO)\r
+#define softuartputch putch\r
+#endif\r
+\r
+void softuartputch(char c)\r
+{\r
+    char i;\r
+#ifdef SOFTUART_DI\r
+        di();\r
+#endif\r
+    SOFTUART_TXPIN = SOFTUART_MARK; // startbit \r
+    _delay(SOFTUART_BITLEN-20); // Adjust Schleifeninit braucht \r
+    for (i=0;i<8;i++)\r
+    {\r
+        SOFTUART_TXPIN = c; // checken, ob da das untere Bit verwendet wird sonst\r
+#if SOFTUART_MARK\r
+        SOFTUART_TXPIN = ~(c&1);\r
+#else\r
+        SOFTUART_TXPIN = c&1;\r
+#endif\r
+        c >>=1;\r
+        _delay(SOFTUART_BITLEN-20); // Adjust\r
+    }\r
+    SOFTUART_TXPIN = ~SOFTUART_MARK;\r
+    _delay(SOFTUART_BITLEN*2); // two stop bits\r
+#ifdef SOFTUART_DI\r
+    ei();\r
+#endif\r
+}\r
+#endif\r
+\r
+/******************************************************************************/\r
+// Utility\r
+/******************************************************************************/\r
+#if defined(SOFTUART_RXPIN) || defined(SOFTUART_STDIO)\r
+// getch with wait\r
+char getch(void)\r
+{\r
+    while (!softuartkbhit()) _delay(1);\r
+    return softuartgetch();\r
+}\r
+#endif\r