Project

General

Profile

Statistics
| Revision:

esp-2014-15 / tp1g3 / Aula1_ex6.X / ex6.c @ 35

History | View | Annotate | Download (1.65 KB)

1
/**
2
 * *****************************************************************************
3
 * @file    timers.h
4
 * @author  TP1G3
5
 * @version V1.0
6
 * @date    Sep 2014
7
 * @brief   Simple I/O exercise 6
8
 * *****************************************************************************
9
 *
10
 *                   2014 UNIVERSIDADE DE AVEIRO
11
 */
12

    
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <stdint.h>
16
#include <xc.h>
17

    
18
#define BUTTON_RE0  PORTEbits.RE0
19

    
20
/*functions created*/
21
void config_dev(void);      // function to configure de device
22
void delay_function(void);   // delay function
23

    
24
/*
25
 *
26
 */
27
int main(int argc, char** argv) {
28
    uint16_t i;
29
    int cycle=0;
30

    
31
    config_dev();
32

    
33
    LATB = 0xAA;                    // Initial value at the output 0xAA
34
    for(i=0;i<10000;i++);           // a litle wait
35
    while(1){
36
        if (!BUTTON_RE0){            // only changes if button is goes from LOW to HIGH
37
            if(BUTTON_RE0){
38
                cycle++;
39
                for(;cycle>0;cycle--){
40
                    for(i=0;i<6;i++){   // creates the sequence ABABABAB
41
                    LATB = ~LATB;
42
                    if (!BUTTON_RE0)            // only changes if button is goes from LOW to HIGH
43
                        if(BUTTON_RE0)
44
                            cycle++;
45
                    delay_function();
46
                    }
47
                }
48
            }
49

    
50
            }
51
    }
52

    
53
    return (EXIT_SUCCESS);
54
}
55

    
56
void config_dev(){
57
    TRISB = 0;              // define all PORTB pins as output
58
    TRISEbits.TRISE0 = 1;    // define RE pin as input
59
}
60
void delay_function(){
61
    uint16_t i,j;
62

    
63
    for(i=0;i<10000;i++){
64
        for(j=0;j<250;j++)
65
            asm("nop");
66
    }
67

    
68
}