Compare commits

...

8 Commits

Author SHA1 Message Date
Wolfgang Hottgenroth
56e23d237c simplify startup display pattern, extend default timeout 2016-09-12 10:56:08 +02:00
Wolfgang Hottgenroth
c0c7d2afd0 Added tag WORKS_2 for changeset 78b8b97f294d 2016-09-12 08:00:45 +02:00
Wolfgang Hottgenroth
75fee98f11 LPM3 is not working correctly, device is booting, disabled, now it is working 2016-09-12 07:59:34 +02:00
Wolfgang Hottgenroth
4ce993230f some changes with the loops 2016-09-11 22:06:38 +02:00
Wolfgang Hottgenroth
275779c0b3 hiding leading zeros doesn't work at the moment 2016-09-11 21:18:43 +02:00
Wolfgang Hottgenroth
63d3d29852 second edition nearly working 2016-09-11 20:33:38 +02:00
Wolfgang Hottgenroth
8ad6c780f7 change in new branch 2016-09-10 18:19:52 +02:00
Wolfgang Hottgenroth
5416467068 Starting 'SecondEdition' branch 2016-09-10 18:19:25 +02:00
12 changed files with 94 additions and 48 deletions

View File

@ -7,6 +7,8 @@ P2.2 G
P2.1 C
P2.0 1
P1.5 2
P1.2 3
P1.1 LED
P1.0 T

View File

@ -7,6 +7,8 @@
#include <stdlib.h>
#include <msp430g2553.h>
#include "PontCoopScheduler.h"

View File

@ -47,64 +47,59 @@ const tPin *NUMBERS[] = { NUMBER0, NUMBER1, NUMBER2, NUMBER3, NUMBER4,
NUMBER5, NUMBER6, NUMBER7, NUMBER8, NUMBER9, ALL_PATTERN, H_PATTERN,
I_PATTERN, EMPTY_PATTERN };
const tPin DIGITS[] = { DIGIT_0, DIGIT_1, PINS_END };
const tPin DIGITS[] = { DIGIT_0, DIGIT_1, DIGIT_2, PINS_END };
uint8_t digitValues[2] = { EMPTY_ID, EMPTY_ID };
uint8_t digitValues[] = { EMPTY_ID, EMPTY_ID, EMPTY_ID };
void displayInit(void *handleArg) {
for (tPin d = DIGIT_0; d <= DIGIT_1; d++) {
for (tPin s = SEG_A; s <= SEG_F; s++) {
gpioSetPin(s, LOW);
}
for (tPin d = DIGIT_2; d >= DIGIT_0; d--) {
gpioSetPin(d, LOW);
for (tPin s = SEG_A; s <= SEG_G; s++) {
gpioSetPin(s, HIGH);
ms_active_delay(INIT_CYCLE_DELAY);
gpioSetPin(s, LOW);
}
gpioSetPin(SEG_G, HIGH);
ms_active_delay(INIT_CYCLE_DELAY);
gpioSetPin(SEG_G, LOW);
gpioSetPin(d, HIGH);
}
}
static void showNumber(uint8_t n) {
const tPin *pattern = NUMBERS[ALL_ID];
do {
for (const tPin *pattern = NUMBERS[ALL_ID]; *pattern != PINS_END; pattern++) {
gpioSetPin(*pattern, LOW);
pattern++;
} while (*pattern != PINS_END);
pattern = NUMBERS[n];
do {
}
for (const tPin *pattern = NUMBERS[n]; *pattern != PINS_END; pattern++) {
gpioSetPin(*pattern, HIGH);
pattern++;
} while (*pattern != PINS_END);
}
}
void displaySetValue(uint8_t v) {
if (v >= 100) {
digitValues[1] = H_ID;
digitValues[0] = I_ID;
} else {
digitValues[1] = v / 10;
digitValues[0] = v - digitValues[1] * 10;
}
uint32_t a,b,c,d;
a = v;
b = a / 100;
c = (a - b * 100) / 10;
d = a - c * 10 - b * 100;
digitValues[2] = (b == 0) ? EMPTY_ID : (uint8_t)b;
digitValues[1] = ((c == 0) && (b == 0)) ? EMPTY_ID : (uint8_t)c;
digitValues[0] = (uint8_t)d;
}
void displayExec(void *handleArg) {
static uint8_t activeDigit = 0;
activeDigit++;
if (activeDigit == 2) {
if (activeDigit == 3) {
activeDigit = 0;
}
const tPin *digit = DIGITS;
do {
for (const tPin *digit = DIGITS; *digit != PINS_END; digit++) {
gpioSetPin(*digit, HIGH);
digit++;
} while (*digit != PINS_END);
}
digit = DIGITS + activeDigit;
gpioSetPin(*digit, LOW);
gpioSetPin(DIGITS[activeDigit], LOW);
showNumber(digitValues[activeDigit]);
}

View File

@ -16,11 +16,12 @@
#include "button.h"
#include "gpio.h"
#include "PontCoopScheduler.h"
#include "powerDown.h"
const uint32_t EGG_TIMER_CYCLE = 1000;
const uint32_t LED_CYCLE = 250;
const uint32_t POWER_DOWN_DELAY = 120000;
const uint32_t MY_POWER_DOWN_DELAY = 120000;
const uint8_t COOKING_TIME = 120;
uint8_t restCookingTime;
@ -28,14 +29,8 @@ bool timerRunning;
bool timerStarted;
void eggTimerPowerDown(void *handleArg) {
P1DIR = 0;
P2DIR = 0;
P1OUT = 0;
P2OUT = 0;
ADC10CTL0 = 0;
LPM4;
}
void eggTimerStart(void *handleArg) {
if (! timerStarted) {
@ -62,7 +57,8 @@ void eggTimerExec(void *handleArg) {
if (restCookingTime == 0) {
// activate alarm
schAdd(eggTimerAlarm, NULL, 0, LED_CYCLE);
schAdd(eggTimerPowerDown, NULL, POWER_DOWN_DELAY, 0);
schDel(powerDown, NULL);
schAdd(powerDown, NULL, MY_POWER_DOWN_DELAY, 0);
timerRunning = false;
}
}

View File

@ -18,7 +18,7 @@ extern const uint32_t EGG_TIMER_CYCLE;
void eggTimerInit(void *handleArg);
void eggTimerExec(void *handleArg);
void eggTimerStart(void *handleArg);
void eggTimerAlarm(void *handleArg);
#endif /* EGGTIMER_H_ */

View File

@ -19,6 +19,13 @@ extern tPinCfg pinCfg[];
void gpioInitPins() {
P1OUT = 0;
P1DIR = 0;
P1REN = 0;
P2OUT = 0;
P2DIR = 0;
P2REN = 0;
for (tPin p = PINS_FIRST; p < PINS_END; p += 1) {
tPinCfg pin = pinCfg[p];
if (pin.portId == PORT1) {
@ -26,6 +33,7 @@ void gpioInitPins() {
P1DIR |= pin.bit;
P1SEL &= ~pin.bit;
P1SEL2 &= ~pin.bit;
gpioSetPin(p, pin.defaultOut);
} else if (pin.direction == PIN_IN) {
P1DIR &= ~pin.bit;
P1SEL &= ~pin.bit;
@ -43,6 +51,7 @@ void gpioInitPins() {
P2DIR |= pin.bit;
P2SEL &= ~pin.bit;
P2SEL2 &= ~pin.bit;
gpioSetPin(p, pin.defaultOut);
} else if (pin.direction == PIN_IN) {
P2DIR &= ~pin.bit;
P2SEL &= ~pin.bit;
@ -56,7 +65,6 @@ void gpioInitPins() {
P2OUT |= pin.bit;
}
}
gpioSetPin(p, pin.defaultOut);
}
}

View File

@ -49,6 +49,7 @@ typedef enum {
SEG_G,
DIGIT_0,
DIGIT_1,
DIGIT_2,
BUTTON_1,
LED_1,
PINS_END

View File

@ -18,6 +18,7 @@ tPinCfg pinCfg[PINS_END] = {
{PORT2, BIT2, PIN_OUT, LOW}, //G
{PORT2, BIT0, PIN_OUT, HIGH}, //0
{PORT1, BIT5, PIN_OUT, HIGH}, //1
{PORT1, BIT2, PIN_OUT, HIGH}, //2
{PORT1, BIT0, PIN_IN_PULLUP, LOW}, // BUTTON_1
{PORT1, BIT1, PIN_OUT, LOW}, //TESTPIN1
{PORT1, BIT1, PIN_OUT, LOW}, // LED_1
};

View File

@ -19,12 +19,17 @@
#include "measure.h"
#include "eggTimer.h"
#include "button.h"
#include "gpio.h"
#include "powerDown.h"
int main() {
WDTCTL = WDTPW | WDTHOLD;
__disable_interrupt();
// highest possible system clock
DCOCTL = DCO0 | DCO1 | DCO2;
BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3;
@ -36,6 +41,8 @@ int main() {
timeInit();
schInit();
schAdd(powerDown, NULL, 1800000, 0); // default thermometer power down timeout: 30min
// interrupts are required for delay function in displayInit();
__enable_interrupt();
displayInit(NULL);
@ -57,11 +64,7 @@ int main() {
while (1) {
schExec();
// put it into the idle loop, it is not time critical
// but should get as much time as possible to avoid
// flicker
//displayExec(NULL);
//LPM3;
}
}

23
src/powerDown.c Normal file
View File

@ -0,0 +1,23 @@
/*
* powerDown.c
*
* Created on: Sep 11, 2016
* Author: wn
*/
#include <msp430g2553.h>
void powerDown(void *handleArg) {
P1OUT = 0;
P1DIR = 0xff;
P1REN = 0;
P2OUT = 0;
P2DIR = 0xff;
P2REN = 0;
ADC10CTL0 = 0;
LPM4;
while (1);
}

14
src/powerDown.h Normal file
View File

@ -0,0 +1,14 @@
/*
* powerDown.h
*
* Created on: Sep 11, 2016
* Author: wn
*/
#ifndef POWERDOWN_H_
#define POWERDOWN_H_
void powerDown(void *handleArg);
#endif /* POWERDOWN_H_ */

View File

@ -16,6 +16,7 @@
volatile uint32_t timestamp;
ISR(TIMER0_A0, TA0_ISR) {
LPM3_EXIT;
timestamp++;
schUpdate();
}