brainmsp430
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
brainmsp430 [2016/01/07 11:27] – admin | brainmsp430 [2019/08/06 15:11] (current) – admin | ||
---|---|---|---|
Line 6: | Line 6: | ||
*/ | */ | ||
volatile unsigned long doublemillis = 0; | volatile unsigned long doublemillis = 0; | ||
- | volatile int j = 0; | + | volatile |
- | volatile | + | const unsigned |
- | 15, | + | {1,15,14,13,12,11, |
- | 12, | + | {1, |
- | 14, | + | {1, |
- | 11, | + | {1, |
- | 10, | + | {1,12, |
- | 9, | + | {1, |
- | 8, | + | {1,12,14, |
- | 7, | + | {1, |
- | 6, | + | |
- | 5, | + | |
- | 4, | + | |
- | 7, | + | |
- | 6, | + | |
- | 5, | + | |
- | 4, | + | |
- | 7, | + | |
- | 6, | + | |
- | 5, | + | |
- | 4, | + | |
- | 5, | + | |
- | 6, | + | |
- | 7, | + | |
- | 8, | + | |
- | 9, | + | |
- | 12, | + | |
- | 10, | + | |
- | 11, | + | |
- | 12, | + | |
- | 15, | + | |
- | 12, | + | |
}; | }; | ||
- | volatile | + | const unsigned |
- | 10, | + | {0, |
- | 5, | + | {1, |
- | 15, | + | {2, |
- | 10, | + | {3, |
- | 10, | + | {4,5, |
- | 10, | + | {5,5,15, |
- | 10, | + | {6,5, |
- | 12, | + | {7, |
- | 5, | + | |
- | 4, | + | |
- | 15, | + | |
- | 5, | + | |
- | 5, | + | |
- | 5, | + | |
- | 10, | + | |
- | 15, | + | |
- | 5, | + | |
- | 5, | + | |
- | 5, | + | |
- | 5, | + | |
- | 5, | + | |
- | 5, | + | |
- | 10, | + | |
- | 10, | + | |
- | 10, | + | |
- | 5, | + | |
- | 5, | + | |
- | 15, | + | |
- | 5, | + | |
- | 30, | + | |
}; | }; | ||
- | volatile | + | const unsigned |
- | volatile int on = 0; | + | volatile |
// Declaration of functions | // Declaration of functions | ||
- | int FreqTime(int Hz); | + | unsigned |
- | int FreqCycle(int Hz , unsigned long speed); | + | unsigned |
unsigned long millis(); | unsigned long millis(); | ||
- | int blinkms(int Millis); | + | unsigned long blinkms(unsigned long Millis); |
- | int CountByTime(int duration, int ArrayLength); | + | unsigned |
// MAIN program | // MAIN program | ||
int main(void) { | int main(void) { | ||
Line 86: | Line 42: | ||
WDTCTL = WDT_MDLY_0_5; | WDTCTL = WDT_MDLY_0_5; | ||
IFG1 &= ~WDTIFG; | IFG1 &= ~WDTIFG; | ||
- | IE1 |= WDTIE; // Enable WDT interrupt | + | IE1 |= WDTIE; // Enable WDT interrupt |
- | P1DIR | + | P1SEL = 0x00; // Set all Pins to GPIO Pins, no clock sources, nothing |
- | | + | P1SEL2 = 0x00; // Set all Pins to GPIO Pins, no clock sources, nothing |
+ | P2SEL = 0x00; | ||
+ | P2SEL2 = 0x00; | ||
+ | P3SEL = 0x00; | ||
+ | P3SEL2 = 0x00; | ||
+ | | ||
+ | P1REN = 0x30; // Set P1.4 - P1.5 pull down resistor | ||
+ | | ||
+ | P2DIR = 0xF8; // Set P2.0 - P2.2 as Intput and P2.3 - P2.7 as Output | ||
+ | P2REN = 0x07; // Set P2.0 - P2.2 pull down resistor | ||
+ | P2OUT = 0x00; // Set P2.0 - P2.7 to 0 | ||
+ | P3DIR = 0xFF; | ||
+ | P3OUT = 0x00; | ||
// Timer_A | // Timer_A | ||
TA0CCR0 = 1250; // Count limit for 400Hz at !MHz (1000000 / 400 / 2) | TA0CCR0 = 1250; // Count limit for 400Hz at !MHz (1000000 / 400 / 2) | ||
Line 97: | Line 65: | ||
TA1CTL = TASSEL_2 + MC_1; // Timer A1 with SMCLK, count UP | TA1CTL = TASSEL_2 + MC_1; // Timer A1 with SMCLK, count UP | ||
_EINT(); //enable interrupts | _EINT(); //enable interrupts | ||
+ | // convert input of PIN 2.0 - 2.2 to programnumber. Onöy once at startup. So no switching during program | ||
+ | volatile int ProgNo = P2IN & 0x07; | ||
// Endless loop | // Endless loop | ||
| | ||
- | j = CountByTime(brainDuration[j], | + | j = CountByTime(brainDuration[ProgNo][j], ArrayLength[ProgNo]); |
- | if (j < ArrayLength){ | + | if (j < ArrayLength[ProgNo]){ |
- | on = blinkms(FreqTime(brainFq[j])); | + | on = blinkms(FreqTime(brainFq[ProgNo][j])); |
- | TA1CCR0 = FreqCycle(brainFq[j]+400, | + | TA1CCR0 = FreqCycle(brainFq[ProgNo][j]+400, 1000000); |
+ | int brightness = ((P1IN & 0x30) >> 4)+5; // brightness encoded on switches on PIN 1.4 and 1.5 | ||
if (on){ | if (on){ | ||
- | P1OUT |= 0x03; | + | for (int i = 0; i < 10; i++){ |
+ | // poor mans PWM | ||
+ | if (i< | ||
+ | P1OUT |= 0x03; | ||
+ | } | ||
+ | |||
+ | else{ | ||
+ | P1OUT &= 0xFC; | ||
+ | } | ||
+ | } | ||
} | } | ||
else{ | else{ | ||
- | P1OUT &= 0xFC; | + | P1OUT &= 0xFC; |
} | } | ||
} | } | ||
else{ | else{ | ||
- | P1OUT &= 0x00; | + | P1DIR = 0xFF; // Set P1.0 - P1.7 as output |
- | P1OUT &= 0x00; | + | P2DIR = 0xFF; // Set P2.0 - P2.7 as output |
- | _BIS_SR(LPM3_bits); | + | P1OUT = 0x00; |
- | } | + | P2OUT = 0x00; |
+ | __dint(); | ||
+ | _BIS_SR(LPM4_bits); | ||
+ | } | ||
} | } | ||
| | ||
Line 122: | Line 105: | ||
// blink in the rhythm of given ms | // blink in the rhythm of given ms | ||
- | int blinkms(int Millis){ | + | unsigned long blinkms(unsigned long Millis){ |
static unsigned long PreviousMillis = 0; | static unsigned long PreviousMillis = 0; | ||
- | static int back = 0; | + | static |
unsigned long CurrentMillis = millis(); | unsigned long CurrentMillis = millis(); | ||
if (CurrentMillis - PreviousMillis >= Millis){ | if (CurrentMillis - PreviousMillis >= Millis){ | ||
Line 133: | Line 116: | ||
} | } | ||
// count 1 up, if time in ms done | // count 1 up, if time in ms done | ||
- | int CountByTime(int duration, int ArrayLength){ | + | unsigned |
static unsigned long PreviousMillis = 0; | static unsigned long PreviousMillis = 0; | ||
- | static int back = 0; | + | static |
unsigned long Millis = duration * 1000; | unsigned long Millis = duration * 1000; | ||
unsigned long CurrentMillis = millis(); | unsigned long CurrentMillis = millis(); | ||
Line 146: | Line 129: | ||
// Convert frequency to ms | // Convert frequency to ms | ||
- | int FreqTime(int Hz){ | + | unsigned |
- | int v = 1000 / Hz / 2; | + | unsigned |
return v; | return v; | ||
} | } | ||
// Convert frequency to Cycles by given Clockspeed | // Convert frequency to Cycles by given Clockspeed | ||
- | int FreqCycle(int Hz, unsigned long speed){ | + | unsigned |
- | int v = speed / Hz / 2; | + | unsigned |
return v; | return v; | ||
} | } | ||
Line 176: | Line 159: | ||
P1OUT ^= 0x08; // Toggle output P1.3 | P1OUT ^= 0x08; // Toggle output P1.3 | ||
} | } | ||
- | |||
</ | </ |
brainmsp430.1452166076.txt.gz · Last modified: 2016/01/07 11:27 by admin