aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKing Kévin <kingkevin@cuvoodoo.info>2014-07-26 19:35:44 -0700
committerKing Kévin <kingkevin@cuvoodoo.info>2014-07-26 19:35:44 -0700
commitecff66736db66beba66345a1f952823a00b788a7 (patch)
treea7b9791b3f768335197b15c3b9131ebbd463ccb7
parent9f6fc7480e61b3bb41a0eb1f62551685bccb2d3e (diff)
add microcontroller code for MDR receiver. button turns off LED
-rw-r--r--pic/MDR/MDR.c109
-rw-r--r--pic/MDR/Makefile24
2 files changed, 133 insertions, 0 deletions
diff --git a/pic/MDR/MDR.c b/pic/MDR/MDR.c
new file mode 100644
index 0000000..1d1a179
--- /dev/null
+++ b/pic/MDR/MDR.c
@@ -0,0 +1,109 @@
+/* micro-controller firmware fot the Linear MDR receiver
+ Copyright (C) 2014 Kévin Redon <kingkevin@cuvoodoo.info>
+
+ 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/* libraries */
+#define __16f1847
+#include <pic16f1847.h>
+#include <stdint.h>
+
+/* the peripherals connected to the pins */
+#define RELAY1 _RA2 /* pin 1 */
+#define RELAY2 _RA3 /* pin 2 */
+/* pin 3 is connected to ground */
+/* pin 4 is used as master clear */
+/* pin 5 is Vss (ground) */
+#define SWITCH1 _RB0 /* pin 6 (on ground when pressed) */
+#define LED _RB1 /* pin 7 (used as sink) */
+#define SWITCH2 _RB2 /* pin 8 (on ground when pressed) */
+/* pin 9 is for a secret function, set by jumper WJ1, Vdd per default */
+/* pin 10 is not connected */
+/* pin 11 in not connected */
+#define MEMORY_CLK _RB6 /* pin 12, external 24LC256 EEPROM */
+#define MEMORY_DATA _RB7 /* pin 13, external 24LC256 EEPROM */
+/* pin 14 is Vdd (5V) */
+/* pin 15 is clonnected to external 4MHz ceramic resonator */
+/* pin 16 is clonnected to external 4MHz ceramic resonator */
+#define RADIO _RA0 /* radio signal receiver, filtered by LM358N */
+/* pin 18 is for a secret function, set by jumper WJ2, Vdd per default */
+
+/* simple functions */
+#define led_off() PORTB |= LED
+#define led_on() PORTB &= ~(LED)
+#define sleep() __asm sleep __endasm
+
+/* variables */
+
+/* configuration bits */
+uint16_t __at(_CONFIG1) __CONFIG1 = _FCMEN_ON & /* enable fail-safe clock monitor */
+ _IESO_ON & /* enable internal/external switchover (since fail-safe is enabled) */
+ _CLKOUTEN_ON & /* use CLKOUT for extrenal resonator (but it is ignored) */
+ _BOREN_NSLEEP & /* only use brown out during normal operation (not sleep) */
+ _CPD_OFF & /* no data memory code protection */
+ _CP_OFF & /* no program memory code protection */
+ _MCLRE_ON& /* use master clear */
+ _PWRTE_ON & /* use power-up timer */
+ _WDTE_OFF & /* disable watchdog */
+ _FOSC_XT; /* use external resonator */
+
+/* initialize micro-conroller */
+void init (void) {
+ ANSELA = 0; /* all pins are digital */
+ ANSELB = 0; /* all pins are digital */
+ TRISA |= RADIO; /* radio signal is an input */
+ TRISA &= ~(RELAY1|RELAY2); /* relays are outputs */
+ TRISB |= SWITCH1|SWITCH2; /* switches are inputs (with external pull-ups) */
+ TRISB &= ~(LED|MEMORY_CLK|MEMORY_DATA); /* LED is I2C memory are outputs */
+ led_off(); /* starting state */
+/*
+ IOC |= (SWITCH1|SWITCH2|SWITCH3|SWITCH4); // enable interrupt for the switches
+ GPIE = 1; // enable interrupt on GPIO
+ last_gpio = GPIO; // save current state
+
+ T1CON = _T1CKPS1 | _T1CKPS0; // set prescaler to 8
+ // 0 is set per default, but just be sure
+ TMR1ON = 0; // stop timer 1
+ TMR1GE = 0; // enable timer 1
+ TMR1CS = 0; // use internal clock / 4 (=1MHz)
+ TMR1IF = 0; // clear interrupt
+ PIE1 = 1; // enable timer 1 interrupt
+ PEIE = 1; // enable timer interrupt
+
+ GIE = 1; // enable interrups
+*/
+
+}
+
+/* funcion called on interrupts */
+/* interrupt 0 is only one on PIC16 */
+static void interrupt(void) __interrupt 0
+{
+}
+
+void main (void)
+{
+ init(); /* configure micro-controller */
+ led_on();
+ while (1) { /* a microcontroller runs forever */
+ if (PORTB&SWITCH1) {
+ led_off();
+ } else {
+ led_on();
+ }
+// sleep(); /* sleep to save power */
+ }
+}
+
diff --git a/pic/MDR/Makefile b/pic/MDR/Makefile
new file mode 100644
index 0000000..8a661d8
--- /dev/null
+++ b/pic/MDR/Makefile
@@ -0,0 +1,24 @@
+# variables
+TARGET = MDR
+PIC = 16f1847
+# software verion used:
+# pk2cmd: 1.21
+# sdcc: 3.4.0
+# gputils: 1.3.0
+
+all: flash
+
+# flash program
+flash: $(TARGET).hex
+ pk2cmd -PPIC$(PIC) -F$< -M -W -R
+
+# compile program
+compile: $(TARGET).hex
+
+# compile program C source code (includes a default code)
+$(TARGET).hex: $(TARGET).c
+ sdcc --std-c99 --opt-code-size --use-non-free -mpic14 -p$(PIC) $<
+
+# remove temporary files
+clean:
+ rm -f $(TARGET).hex $(TARGET).lst $(TARGET).asm $(TARGET).adb $(TARGET).o $(TARGET).cod