-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_touch_lcd.c
152 lines (129 loc) · 4.64 KB
/
main_touch_lcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <msp430.h>
#include "CTS_Layer.h"
#include "lcd.h"
#include "lcd_charset.h"
// Uncomment to have this compiler directive run characterization functions only
// Comment to have this compiler directive run example application
//#define ELEMENT_CHARACTERIZATION_MODE
#define DELAY 1000 // Timer delay timeout count, 5000*0.1msec = 500 msec
// was 5000
struct Element * keyPressed; // Pointer to the Element structure
#ifdef ELEMENT_CHARACTERIZATION_MODE
// Delta Counts returned from the API function for the sensor during characterization
unsigned int wheelCnt[5]; // Becuase the Wheel is composed of five elements
#endif
// Sleep Function
// Configures Timer A to run off ACLK, count in UP mode, places the CPU in LPM3
// and enables the interrupt vector to jump to ISR upon timeout
void sleep(unsigned int time)
{
TA0CCR0 = time;
TA0CTL = TASSEL_1+MC_1+TACLR;
TA0CCTL0 &= ~CCIFG;
TA0CCTL0 |= CCIE;
__bis_SR_register(LPM3_bits+GIE);
__no_operation();
}
// Main Function
void main(void)
{
uint8_t last = 0;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_16MHZ; // Set DCO to 1, 8, 12 or 16MHz
DCOCTL = CALDCO_16MHZ;
BCSCTL1 |= DIVA_0; // ACLK/1 [ACLK/(0:1,1:2,2:4,3:8)]
//BCSCTL2 |= DIVS_3; // SMCLK/8 [SMCLK/(0:1,1:2,2:4,3:8)]
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO Clock Source
P1OUT |= BIT0; // P1.0 out
P1DIR |= BIT0; // P1.0 high
P2DIR |= BIT0 | BIT1 | BIT4 | BIT5; // Configure Port 2 pins outputs
// Initialize Baseline measurement
TI_CAPT_Init_Baseline(&button_bar);
// Update baseline measurement (Average 5 measurements)
TI_CAPT_Update_Baseline(&button_bar,5);
SPISetup(); // Initialize SPI Display
//drawBitmap(blackbird_96_64, 96, 8, 0, 0);
clear();
//setcharmode(1); //largechars
//writeString(2,1,"Press button!");
// Main loop starts here
while (1)
{
#ifdef ELEMENT_CHARACTERIZATION_MODE
// Get the raw delta counts for element characterization
TI_CAPT_Custom(&button_bar,wheelCnt);
__no_operation(); // Set breakpoint here
#endif
#ifndef ELEMENT_CHARACTERIZATION_MODE
// Return the pointer to the element which has been touched
keyPressed = (struct Element *)TI_CAPT_Buttons(&button_bar);
// If a button has been touched, then take some action
if(keyPressed)
{
// Up Element
if(keyPressed == &a_element)
{
P1OUT |= BIT0; // Turn on center LED
if (last != 2) {
clear();
last = 2;
drawBitmap(big_1, 32, 6, 32, 1);
//writeString(4,3,"A Pressed");
}
}
if(keyPressed == &b_element)
{
P1OUT |= BIT0; // Turn on center LED
if (last != 3) {
clear();
last = 3;
drawBitmap(big_2, 32, 6, 32, 1);
//writeString(4,3,"B Pressed");
}
}
if(keyPressed == &c_element)
{
P1OUT |= BIT0; // Turn on center LED
if (last != 1) {
clear();
last = 1;
drawBitmap(big_3, 32, 6, 32, 1);
//writeString(4,3,"C Pressed");
}
}
if(keyPressed == &d_element)
{
P1OUT |= BIT0; // Turn on center LED
if (last != 4) {
clear();
last = 4;
drawBitmap(big_4, 32, 6, 32, 1);
//writeString(4,3,"D Pressed");
}
}
}
else
{
P1OUT &= ~(BIT0); // Turn off center LED
if (last != 0)
{
drawBitmap(blackbird_96_64, 96, 8, 0, 0);
//writeString(4,4,"Press a button");
last = 0;
}
}
// Put the MSP430 into LPM3 for a certain DELAY period
sleep(DELAY);
#endif
}
} // End Main
/******************************************************************************/
// Timer0_A0 Interrupt Service Routine: Disables the timer and exists LPM3
/******************************************************************************/
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ISR_Timer0_A0(void)
{
TA0CTL &= ~(MC_1);
TA0CCTL0 &= ~(CCIE);
__bic_SR_register_on_exit(LPM3_bits+GIE);
}