Escolar Documentos
Profissional Documentos
Cultura Documentos
h"
#include "Data.h"
#include <string.h>
static int frequency = 256; //This is the pulse frequency for the LED's
static int PWM_Period = 32768/frequency;
static int TA0_ISR_interrupt_interval = frequency/32768; //This is the time it
takes to fire each interrupt.
static int modulation__count_second = 1/TA0_ISR_interrupt_interval; //This is the
number of counts required for 1 second to pass.
static int modulation_step_period = modulation__count_second/4; //The total period
is therefore 0.25*1440 = 360 seconds.
void InitializePWM(void)
{
P1DIR |= BIT6; // P1.6 output
P1SEL |= BIT6; // P1.6 TA0/1 tethered with output pin
void InitializeUART(void)
{
P1SEL |= RXD + TXD; // P1.1 = RXD, P1.2 = TXD
P1SEL2 |= RXD + TXD; // P1.1 = RXD, P1.2 = TXD
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Disable WDT
InitializePWM();
InitializeUART();
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void)
{
static int modulation_event_counter = 0;
static int intensity_index_counter = 0;
if (modulation_event_counter == modulation_step_period)
{
if (frame_received_flag == 1) // If user sends a new "time of day" via
UART, this overrides the the current clock time.
{
intensity_index_counter = true_time;
intensity_index_counter++; // index value that is used to
callout the corresponding value in the array.
TACCR1 = intensity_profile[intensity_index_counter];
frame_received_flag = 0;
}
else // otherwise continue modulating with current clock time.
{
intensity_index_counter++;
TACCR1 = intensity_profile[intensity_index_counter];
}
modulation_event_counter = 0;
}
else
{
modulation_event_counter++;
}
}
//UART RX USCI Interrupt. This triggers when the USCI receives a char.
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if(current_time_array_index == MAX_BUF_LEN-1) //protect from buffer overflow
{
current_time_array_index = 0;
}
if (current_time_array_index == 1)
{
true_time = (value1 - '0');
}
if (current_time_array_index == 2)
{
true_time = (value1 - '0')*10 + (value2 - '0');
}
if (current_time_array_index == 3)
{
true_time = (value1 - '0')*100 + (value2 - '0')*10 + (value3 -
'0');
}
if (current_time_array_index == 4)
{
true_time = (value1 - '0')*1000 + (value2 - '0')*100 + (value3 -
'0')*10 + (value4 - '0');
}
}
//Resets
Current_Time[0] = 0;
Current_Time[1] = 0;
Current_Time[2] = 0;
Current_Time[3] = 0;
value1 = 0;
value2 = 0;
value3 = 0;
value4 = 0;
}
}