Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
launchpad.c
Go to the documentation of this file.
1 #include<msp430g2553.h>
2 #include<string.h>
3 #include <launchpad.h>
4 
9 void desabWDT()
10 {
11  WDTCTL = WDTPW|WDTHOLD;
12 }
13 
18 void botao()
19 {
20  P1DIR &= ~BOTAO;
21  P1OUT |= BOTAO;
22  P1REN |= BOTAO;
23 }
24 
33 void hled(unsigned char numled)
34 {
35  /*numled é LED1 ou LED2 */
36  P1DIR|=numled;
37 }
38 
39 /* sensibilidade ao botão */
40 char readbotao(void)
41 {
42  unsigned volatile sig;
43  if ((P1IN & BOTAO) == BOTAO)
44  sig = 1;
45  else
46  sig = 0;
47 
48  return sig;
49 
50 }
51 
52 /* Esperar equanto botão não/é pressionao */
53 void waitbton(unsigned char sinal)
54 {
55  if (sinal==SOLTA)
56  while(!readbotao())
57  {}
58  else if (sinal == APERTA)
59  while(readbotao())
60  {}
61 }
62 
63 /* Acender led */
64 void ligled(char numled)
65 {
66  P1OUT |= numled;
67 }
68 
69 /* Apagar led */
70 void desled(char numled)
71 {
72  P1OUT &= ~numled;
73 }
74 
75 /* Alternar led */
76 void alterled(unsigned volatile numled)
77 {
78  P1OUT ^= numled;
79 }
80 
81 /* delay coxa! -- count 1000 */
82 void dly_coxa(int numcic)
83 {
84  volatile unsigned int count1 = 0, count2 = 0;
85 
86  for (count1 = 0; count1< numcic; count1++)
87  {
88  for(count2 = 0; count2 < 1000; count2++)
89  {
90  }
91  }
92 }
93 
94 /* configurar clock em 1MHz */
95 void dco1mhz()
96 {
97  /* BASEADO EM EXEMPLOS */
98 
99  DCOCTL = 0;
100  BCSCTL1 = CALBC1_1MHZ;
101  DCOCTL = CALDCO_1MHZ;
102 }
103 
119 void hserial()
120 {
121  P1SEL |= PIN_TX + PIN_RX ; /* P1.1 = RXD, P1.2=TXD */
122  P1SEL2 |= PIN_TX + PIN_RX ; /* P1.1 = RXD, P1.2=TXD */
123 
124  UCA0CTL1 |= UCSSEL_2; /* SMCLK */
125  UCA0BR0 = 104; /* 1MHz 9600 */
126  UCA0BR1 = 0; /* 1MHz 9600 */
127  UCA0MCTL = UCBRS0; /* Modulation UCBRSx = 1 */
128  UCA0CTL1 &= ~UCSWRST; /* **Initialize USCI state machine** */
129 }
130 
131 /* le um char da uart */
132 char getchar()
133 {
134  while(!(IFG2 & UCA0RXBUF));
135  return UCA0RXBUF;
136 }
137 
138 int putchar(int caracter)
139 {
140  UCA0TXBUF = caracter;
141 
142  return 0;
143 }
144 
145 void wsserial(char *st)
146 {
147  volatile int cont = 0, len = strlen(st);
148 
149  for(cont=0; cont<len; cont++)
150  {
151  putchar(st[cont]);
152  dly_coxa(1);
153  }
154 }
155 
156 
157 void setMultitimes()
158 {
159  CCTL0 = CCIE; // CCR0 interrupt enabled
160  CCR0 = T_100US;
161  TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
162 }
163 
#define PIN_TX
Definition: launchpad.h:20
#define T_100US
Definition: launchpad.h:25
#define BOTAO
Definition: launchpad.h:5
void ligled(char numled)
Definition: launchpad.c:64
void dly_coxa(int numcic)
Definition: launchpad.c:82
__END_NAMESPACE_STD char char __BEGIN_NAMESPACE_STD size_t strlen(const char *__s) __THROW __attribute_pure__ __nonnull((1))
void hled(unsigned char numled)
Enable LED.
Definition: launchpad.c:33
void desled(char numled)
Definition: launchpad.c:70
void hserial()
char readbotao(void)
Definition: launchpad.c:40
void wsserial(char *st)
#define APERTA
Definition: launchpad.h:6
#define PIN_RX
Definition: launchpad.h:21
#define SOLTA
Definition: launchpad.h:7
void waitbton(unsigned char sinal)
Definition: launchpad.c:53
void alterled(unsigned volatile numled)
Definition: launchpad.c:76
void dco1mhz()
Definition: launchpad.c:95
void botao()
Enable the button.
Definition: launchpad.c:18
char getchar()
void desabWDT()
Desable Watchdog.
Definition: launchpad.c:9
void setMultitimes()
int putchar(int caracter)