X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/775fabfac758cbdc33aa81431380ed0b6377143b..3d2da98a7a2b423edbdf4e685b588fbc5789dd7f:/main.c?ds=sidebyside diff --git a/main.c b/main.c index 88deb31..1c3050b 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * main.c - demo main module to test irmp decoder * - * Copyright (c) 2009-2012 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2015 Frank Meyer - frank(at)fli4l.de * - * $Id: main.c,v 1.16 2012/12/06 08:49:33 fm Exp $ + * $Id: main.c,v 1.27 2015/02/27 10:19:20 fm Exp $ * * This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4) * @@ -20,7 +20,7 @@ #include "irmp.h" #ifndef F_CPU -#error F_CPU unkown +#error F_CPU unknown #endif /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -29,7 +29,110 @@ */ #if defined (ATMEL_AVR) -void +#include "irmp.h" +#define BAUD 9600L +#include + +#ifdef UBRR0H + +#define UART0_UBRRH UBRR0H +#define UART0_UBRRL UBRR0L +#define UART0_UCSRA UCSR0A +#define UART0_UCSRB UCSR0B +#define UART0_UCSRC UCSR0C +#define UART0_UDRE_BIT_VALUE (1<>= 4) + { + buf[digits] = "0123456789ABCDEF"[number & 0x0F]; + } + return buf; +} + +static void timer1_init (void) { #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85: @@ -69,21 +172,41 @@ ISR(COMPA_VECT) // T int main (void) { - IRMP_DATA irmp_data; + IRMP_DATA irmp_data; + char buf[3]; irmp_init(); // initialize irmp timer1_init(); // initialize timer1 + uart_init(); // initialize uart + sei (); // enable interrupts for (;;) { if (irmp_get_data (&irmp_data)) { - // ir signal decoded, do something here... - // irmp_data.protocol is the protocol, see irmp.h - // irmp_data.address is the address/manufacturer code of ir sender - // irmp_data.command is the command code - // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) + uart_puts_P (PSTR("protocol: 0x")); + itoh (buf, 2, irmp_data.protocol); + uart_puts (buf); + +#if IRMP_PROTOCOL_NAMES == 1 + uart_puts_P (PSTR(" ")); + uart_puts_P (pgm_read_word (&(irmp_protocol_names[irmp_data.protocol]))); +#endif + + uart_puts_P (PSTR(" address: 0x")); + itoh (buf, 4, irmp_data.address); + uart_puts (buf); + + uart_puts_P (PSTR(" command: 0x")); + itoh (buf, 4, irmp_data.command); + uart_puts (buf); + + uart_puts_P (PSTR(" flags: 0x")); + itoh (buf, 2, irmp_data.flags); + uart_puts (buf); + + uart_puts_P (PSTR("\r\n")); } } } @@ -140,4 +263,119 @@ main (void) } } +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * PIC18F4520 with XC8 compiler: + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#elif defined (__XC8) + +#define _XTAL_FREQ 32000000UL // 32MHz clock +#define FOSC _XTAL_FREQ +#define FCY FOSC / 4UL // --> 8MHz + +#define BAUDRATE 19200UL +#define BRG (( FCY 16 BAUDRATE ) -1UL) + +#include +#include + +int +main (void) +{ + IRMP_DATA irmp_data; + + irmp_init(); // initialize irmp + + // infinite loop, interrupts will blink PORTD pins and handle UART communications. + while (1) + { + LATBbits.LATB0 = ~LATBbits.LATB0; + + if (irmp_get_data (&irmp_data)) + { + // ir signal decoded, do something here... + // irmp_data.protocol is the protocol, see irmp.h + // irmp_data.address is the address/manufacturer code of ir sender + // irmp_data.command is the command code + // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) + printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command ); + } + } +} + +void interrupt high_priority high_isr(void) +{ + if (TMR2IF) + { + TMR2IF = 0; // clear Timer 0 interrupt flag + irmp_ISR(); + } +} + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * STM32: + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#elif defined(ARM_STM32) + +uint32_t +SysCtlClockGet(void) +{ + RCC_ClocksTypeDef RCC_ClocksStatus; + RCC_GetClocksFreq(&RCC_ClocksStatus); + return RCC_ClocksStatus.SYSCLK_Frequency; +} + +void +timer2_init (void) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + NVIC_InitTypeDef NVIC_InitStructure; + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructure.TIM_Period = 7; + TIM_TimeBaseStructure.TIM_Prescaler = ((F_CPU / F_INTERRUPTS)/8) - 1; + TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); + + TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); + + NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; + NVIC_Init(&NVIC_InitStructure); + + TIM_Cmd(TIM2, ENABLE); +} + +void +TIM2_IRQHandler(void) // Timer2 Interrupt Handler +{ + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + (void) irmp_ISR(); // call irmp ISR + // call other timer interrupt routines... +} + +int +main (void) +{ + IRMP_DATA irmp_data; + + irmp_init(); // initialize irmp + timer2_init(); // initialize timer2 + + for (;;) + { + if (irmp_get_data (&irmp_data)) + { + // ir signal decoded, do something here... + // irmp_data.protocol is the protocol, see irmp.h + // irmp_data.address is the address/manufacturer code of ir sender + // irmp_data.command is the command code + // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) + } + } +} #endif