This commit is contained in:
Wolfgang Hottgenroth
2016-01-18 15:31:07 +01:00
commit bf464bcd00
7 changed files with 223 additions and 0 deletions

30
src/main.cpp Normal file
View File

@ -0,0 +1,30 @@
/*
* main.cpp
*
* Created on: 16. 01. 2016
* Author: wn
*/
#include <msp430g2553.h>
#include <stdint.h>
#include <intrinsics.h>
#include <isr_compat.h>
#include "time.h"
int main() {
WDTCTL = WDTPW | WDTHOLD;
timeInit();
__enable_interrupt();
while (1) {
}
}

80
src/time.cpp Normal file
View File

@ -0,0 +1,80 @@
/*
* time.c
*
* Created on: 20.05.2014
* Author: wn
*/
#include <msp430g2553.h>
#include <isr_compat.h>
#include <stdint.h>
#include "time.h"
volatile uint16_t timestamp;
const uint16_t TICK = 1024;
uint16_t pwmVal = 128;
volatile uint16_t onTime = 500;
volatile uint16_t offTime = 200;
ISR(TIMER0_A0, TA0_ISR) {
static uint8_t state0 = 0;
static uint8_t state1 = 0;
switch (state0) {
case 0:
P1OUT |= BIT0;
state0 = 1;
break;
case 1:
P1OUT &= ~BIT0;
state0 = 0;
break;
default:
state0 = 0;
}
timestamp++;
switch (state1) {
case 0:
if (timestamp >= onTime) {
timestamp = 0;
P1OUT |= BIT1;
P1SEL &= ~BIT6;
P1OUT &= ~BIT6;
state1 = 1;
}
break;
case 1:
if (timestamp >= offTime) {
timestamp = 0;
P1OUT &= ~BIT1;
P1SEL |= BIT6;
state1 = 0;
}
break;
default:
state1 = 0;
}
}
void timeInit() {
timestamp = 0;
P1DIR |= BIT0 | BIT1 | BIT6;
P1OUT = 0;
P1SEL |= BIT6;
TACCR0 = TICK;
TACCR1 = pwmVal;
TACCTL0 = CCIE;
TACCTL1 = OUTMOD_7;
TACTL = MC_1 | ID_0 | TASSEL_2 | TACLR | TAIE;
}

18
src/time.h Normal file
View File

@ -0,0 +1,18 @@
/*
* time.h
*
* Created on: 20.05.2014
* Author: wn
*/
#ifndef TIME_H_
#define TIME_H_
void timeInit();
#endif /* TIME_H_ */