+\r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ * PIC18F4520 with XC8 compiler:\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
+#elif defined (__XC8)\r
+\r
+#define _XTAL_FREQ 32000000UL // 32MHz clock\r
+#define FOSC _XTAL_FREQ\r
+#define FCY FOSC / 4UL // --> 8MHz\r
+\r
+#define BAUDRATE 19200UL\r
+#define BRG (( FCY 16 BAUDRATE ) -1UL)\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+int\r
+main (void)\r
+{\r
+ IRMP_DATA irmp_data;\r
+\r
+ irmp_init(); // initialize irmp\r
+\r
+ // infinite loop, interrupts will blink PORTD pins and handle UART communications.\r
+ while (1)\r
+ {\r
+ LATBbits.LATB0 = ~LATBbits.LATB0;\r
+\r
+ if (irmp_get_data (&irmp_data))\r
+ {\r
+ // ir signal decoded, do something here...\r
+ // irmp_data.protocol is the protocol, see irmp.h\r
+ // irmp_data.address is the address/manufacturer code of ir sender\r
+ // irmp_data.command is the command code\r
+ // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)\r
+ printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command );\r
+ }\r
+ }\r
+}\r
+\r
+void interrupt high_priority high_isr(void)\r
+{\r
+ if (TMR2IF)\r
+ {\r
+ TMR2IF = 0; // clear Timer 0 interrupt flag\r
+ irmp_ISR();\r
+ }\r
+}\r
+\r
+/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ * STM32:\r
+ *---------------------------------------------------------------------------------------------------------------------------------------------------\r
+ */\r
+#elif defined(ARM_STM32)\r
+\r
+uint32_t\r
+SysCtlClockGet(void)\r
+{\r
+ RCC_ClocksTypeDef RCC_ClocksStatus;\r
+ RCC_GetClocksFreq(&RCC_ClocksStatus);\r
+ return RCC_ClocksStatus.SYSCLK_Frequency;\r
+}\r
+\r
+void\r
+timer2_init (void)\r
+{\r
+ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;\r
+ NVIC_InitTypeDef NVIC_InitStructure;\r
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);\r
+\r
+ TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;\r
+ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;\r
+ TIM_TimeBaseStructure.TIM_Period = 7;\r
+ TIM_TimeBaseStructure.TIM_Prescaler = ((F_CPU / F_INTERRUPTS)/8) - 1;\r
+ TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);\r
+\r
+ TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);\r
+\r
+ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;\r
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\r
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;\r
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;\r
+ NVIC_Init(&NVIC_InitStructure);\r
+\r
+ TIM_Cmd(TIM2, ENABLE);\r
+}\r
+\r
+void\r
+TIM2_IRQHandler(void) // Timer2 Interrupt Handler\r
+{\r
+ TIM_ClearITPendingBit(TIM2, TIM_IT_Update);\r
+ (void) irmp_ISR(); // call irmp ISR\r
+ // call other timer interrupt routines...\r
+}\r
+\r
+int\r
+main (void)\r
+{\r
+ IRMP_DATA irmp_data;\r
+ \r
+ irmp_init(); // initialize irmp\r
+ timer2_init(); // initialize timer2\r
+\r
+ for (;;)\r
+ {\r
+ if (irmp_get_data (&irmp_data))\r
+ {\r
+ // ir signal decoded, do something here...\r
+ // irmp_data.protocol is the protocol, see irmp.h\r
+ // irmp_data.address is the address/manufacturer code of ir sender\r
+ // irmp_data.command is the command code\r
+ // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)\r
+ }\r
+ }\r
+}\r
+#endif\r