-
Notifications
You must be signed in to change notification settings - Fork 2
/
initPorts.c
70 lines (52 loc) · 1.43 KB
/
initPorts.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
//Initialises all I/O ports on MCU
#include <io.h>
#include "initPorts.h"
#include "led.h"
#include "Motor2.h"
/*
Initialise all ports on microcontroller board.
*/
void PortsInit(void)
{
//Port 1 is LedsLower
P1SEL = 0x00; // All digital signal i/o: [0000|0000] = 0x00
P1DIR = 0xFF; //All output: [1111|1111] = 0xFF
P2SEL = 0x00; //All digital signal i/o: [0000|0000] = 0x00
P2DIR = 0xFB; //2.2 is input IRQ for wireless,2.3 is output [!CS] for nRF, 2.4 is output[CE] for wireless
//rest are output: [1111|1011] = 0xFB
P2IE = 0x04; //Enable interrupt for P2.2 [0000|0100] = 0x04
P2IES = 0x04; //Edge Select is H2L [\] [0000|0100] = 0x04
P3SEL = 0x0E; //P3Bits [1,2,3] are SPI, rest are Di/o [0000|1110] = 0x0E, note:3.5 is switch
P3DIR = 0xCA; //[1,3,6,7] output1, [0,2,4,5] input0: [1100|1010] = 0xCA
P4SEL = 0x00; //All digital signal i/o: [0000|0000] = 0x00
P4DIR = 0xFF; //All output: [1111|1111] = 0xFF
P5SEL = 0x00; //All digital signal i/o: [0000|0000] = 0x00 // Port 5 is all used for motors
P5DIR = 0xFF; //All output: [1111|1111] = 0xFF
P6SEL = 0xFF; //ALL Function [ADC]: [1111|1111] = 0xFF
P6DIR = 0x00; //ALL Input: [0000|0000] = 0x00
LED1OFF;
LED2OFF;
LED3OFF;
LED4OFF;
LED5OFF;
LED6OFF;
LED7OFF;
LED8OFF;
/* LED9OFF;
LED10OFF;
LED11OFF;
LED12OFF;
LED13OFF;
LED14OFF;
LED15OFF;
LED16OFF;
*/
M1P1OFF;
M1P2OFF;
M1P3OFF;
M1P4OFF;
M2P1OFF;
M2P2OFF;
M2P3OFF;
M2P4OFF;
}