Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "msp430g2553.h"
- void configTimer() {
- TA0CTL |= (TASSEL_2 | ID_3); //Configuração
- TA0CCR0 = 62500 - 1; //Define o contador
- TA0CCTL0 = CCIE; //Liga interrupção do timer
- }
- void startTimer() {
- TA0CTL &= ~MC_0;
- TA0CTL |= MC_1;
- }
- void paraTimer() {
- TA0CTL &= ~MC_1;
- TA0CTL |= MC_0;
- }
- void configLeds() {
- P1DIR |= (BIT0 | BIT6);
- P1OUT &= ~(BIT0 | BIT6);
- }
- void configSensor() {
- P1DIR &= ~BIT3;
- P1REN |= BIT3;
- P1OUT |= BIT3;
- }
- void acendeLeds() {
- P1OUT |= (BIT0 | BIT6);
- }
- void apagaLeds() {
- P1OUT &= ~(BIT0 | BIT6);
- }
- unsigned char contTimer = 0;
- void main( void )
- {
- WDTCTL = WDTPW + WDTHOLD;
- configLeds();
- configSensor();
- _BIS_SR(GIE); //Habilita as interrupções
- configTimer();
- while(42) {
- if((P1IN & BIT3) == 0) { //Se botão está pressionado
- acendeLeds();
- startTimer();
- }
- }
- }
- #pragma vector = TIMER0_A0_VECTOR
- __interrupt void tempo0(void) {
- contTimer++;
- if(contTimer == 20) {
- apagaLeds();
- contTimer = 0;
- paraTimer();
- }
- TA0CCTL0 &= ~CCIFG;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement