From 9c86ff1a028fc9f554a74a23e4638179b9e5a1de Mon Sep 17 00:00:00 2001 From: ukw Date: Thu, 16 Feb 2012 11:15:44 +0000 Subject: [PATCH] Version 2.1.0: port to PIC C18 compiler git-svn-id: svn://mikrocontroller.net/irmp@88 aeb2e35e-bfc4-4214-b83c-9e8de998ed28 --- irmpconfig.h | 2 +- irsnd.c | 132 ++++++++++++++++++++++++++++++++++---------------- irsnd.h | 13 +++-- irsndconfig.h | 66 ++++++++++++++++++++++++- 4 files changed, 165 insertions(+), 48 deletions(-) diff --git a/irmpconfig.h b/irmpconfig.h index 2349fa0..a303719 100644 --- a/irmpconfig.h +++ b/irmpconfig.h @@ -24,7 +24,7 @@ *--------------------------------------------------------------------------------------------------------------------------------------------------- */ #ifndef F_INTERRUPTS -#define F_INTERRUPTS 11718 // interrupts per second, min: 10000, max: 20000, typ: 15000 +#define F_INTERRUPTS 15000 // interrupts per second, min: 10000, max: 20000, typ: 15000 #endif /*--------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/irsnd.c b/irsnd.c index 68a6691..f08044f 100644 --- a/irsnd.c +++ b/irsnd.c @@ -12,7 +12,7 @@ * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P * - * $Id: irsnd.c,v 1.46 2012/02/15 11:02:42 fm Exp $ + * $Id: irsnd.c,v 1.45 2012/02/13 11:02:29 fm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,13 @@ *--------------------------------------------------------------------------------------------------------------------------------------------------- */ +#if defined(__18CXX) +#define PIC_C18 // Microchip C18 +#include // basic P18 lib +#include "timers.h" // timer lib +#include "pwm.h" // pwm lib +#endif + #ifdef unix // test/debug on linux/unix #include #include @@ -46,14 +53,16 @@ typedef unsigned short uint16_t; #else #ifdef CODEVISION - #define COM2A0 6 - #define WGM21 1 - #define CS20 0 +#define COM2A0 6 +#define WGM21 1 +#define CS20 0 +#elif defined(PIC_C18) + //nothing to do here #else - #include - #include - #include - #include +#include +#include +#include +#include #endif // CODEVISION #endif // WIN32 @@ -63,11 +72,6 @@ typedef unsigned short uint16_t; #include "irsndconfig.h" #include "irsnd.h" -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * ATtiny pin definition of OC0A / OC0B - * ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * ATtiny pin definition of OC0A / OC0B * ATmega pin definition of OC2 / OC2A / OC2B / OC0 / OC0A / OC0B @@ -124,6 +128,7 @@ typedef unsigned short uint16_t; #define IRSND_PORT PORTB // port B #define IRSND_DDR DDRB // ddr B #define IRSND_BIT 1 // OC2 + #elif IRSND_OCx == IRSND_OC0 // OC0 #define IRSND_PORT PORTB // port B #define IRSND_DDR DDRB // ddr B @@ -199,6 +204,9 @@ typedef unsigned short uint16_t; #error Wrong value for IRSND_OCx, choose IRSND_OC0, IRSND_OC1A, or IRSND_OC1B in irsndconfig.h #endif // IRSND_OCx +#elif defined (PIC_C18) //Microchip C18 compiler + //Nothing here to do here -> See irsndconfig.h + #else #if !defined (unix) && !defined (WIN32) #error mikrocontroller not defined, please fill in definitions here. @@ -206,9 +214,9 @@ typedef unsigned short uint16_t; #endif // __AVR... #if IRSND_SUPPORT_NIKON_PROTOCOL == 1 -typedef uint16_t IRSND_PAUSE_LEN; + typedef uint16_t IRSND_PAUSE_LEN; #else -typedef uint8_t IRSND_PAUSE_LEN; + typedef uint8_t IRSND_PAUSE_LEN; #endif /*--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -314,8 +322,8 @@ typedef uint8_t IRSND_PAUSE_LEN; #define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME + 0.5) #define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! -#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5) -#define GRUNDIG_NOKIA_IR60_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5) +#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME + 0.5) +#define GRUNDIG_NOKIA_IR60_BIT_LEN (uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME + 0.5) #define GRUNDIG_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t! #define NOKIA_AUTO_REPETITION_PAUSE_LEN (uint16_t)(F_INTERRUPTS * NOKIA_AUTO_REPETITION_PAUSE_TIME + 0.5) // use uint16_t! #define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! @@ -324,12 +332,22 @@ typedef uint8_t IRSND_PAUSE_LEN; #define SIEMENS_BIT_LEN (uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME + 0.5) #define SIEMENS_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! + +#ifdef PIC_C18 +#define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2 / Pre_Scaler / PIC_Scaler) - 1) +#else // AVR #define IRSND_FREQ_32_KHZ (uint8_t) ((F_CPU / 32000 / 2) - 1) #define IRSND_FREQ_36_KHZ (uint8_t) ((F_CPU / 36000 / 2) - 1) #define IRSND_FREQ_38_KHZ (uint8_t) ((F_CPU / 38000 / 2) - 1) #define IRSND_FREQ_40_KHZ (uint8_t) ((F_CPU / 40000 / 2) - 1) #define IRSND_FREQ_56_KHZ (uint8_t) ((F_CPU / 56000 / 2) - 1) #define IRSND_FREQ_455_KHZ (uint8_t) ((F_CPU / 455000 / 2) - 1) +#endif #define FDC_START_BIT_PULSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME + 0.5) #define FDC_START_BIT_PAUSE_LEN (uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME + 0.5) @@ -369,10 +387,10 @@ typedef uint8_t IRSND_PAUSE_LEN; #define LEGO_0_PAUSE_LEN (uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME + 0.5) #define LEGO_FRAME_REPEAT_PAUSE_LEN (uint16_t)(F_INTERRUPTS * LEGO_FRAME_REPEAT_PAUSE_TIME + 0.5) // use uint16_t! -static volatile uint8_t irsnd_busy; -static volatile uint8_t irsnd_protocol; -static volatile uint8_t irsnd_buffer[6]; -static volatile uint8_t irsnd_repeat; +static volatile uint8_t irsnd_busy = 0; +static volatile uint8_t irsnd_protocol = 0; +static volatile uint8_t irsnd_buffer[6] = {0}; +static volatile uint8_t irsnd_repeat = 0; static volatile uint8_t irsnd_is_on = FALSE; #if IRSND_USE_CALLBACK == 1 @@ -390,6 +408,12 @@ irsnd_on (void) if (! irsnd_is_on) { #ifndef DEBUG + +#if defined(PIC_C18) + IRSND_PIN = 0; // output mode -> enable PWM outout pin (0=PWM on, 1=PWM off) +#else + + #if IRSND_OCx == IRSND_OC2 // use OC2 TCCR2 |= (1< disbale PWM output pin (0=PWM on, 1=PWM off) +#else //AVR + #if IRSND_OCx == IRSND_OC2 // use OC2 TCCR2 &= ~(1<