-
Notifications
You must be signed in to change notification settings - Fork 2
/
Setup.c
63 lines (53 loc) · 1.19 KB
/
Setup.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
//Contains functions to setup MCU; a single place to put all the function calls required to initialise clocks, ports, interrupts, ADC, SPI, wireless module and timer
#include "Setup.h"
#include "Config.h"
#include "adc.h"
#include "cpuclockinit.h"
#include "initPorts.h"
#include "MazeManipulation.h"
#include "softDelay.h"
#include "spi.h"
#include "nRF24L01.h"
#include "Interrupt.h"
#include "TimerA.h"
void SetupCpu (void)
{
cpuClockInit();
PortsInit();
InitInterrupt();
AdcInit();
spiInit();
rfPwrDown();
rfWriteReg(REG_STATUS,TX_DS); //Ensure that all interrupts are cleared
rfWriteReg(REG_STATUS,RX_DR); // on wireless module
rfWriteReg(REG_STATUS,MAX_RT);
rfConfig();
rfWriteReg(REG_RF_CH,1);
rfFlushRx();
TimerAInit();
}
void SetupCode (void)
{
unsigned char StartX = 3;
unsigned char StartY = 3;
ClearMaze(); //Clear out maze and set outside walls
SetMouseY(StartY); //Start in bottom left
SetMouseX(StartX);
SetMouseHeading(NORTH);
}
void WaitForSwitch (void)
{
while (!SWITCH) softDelay(1000);
while (SWITCH) softDelay(1000);
softDelay(1000);
}
unsigned char IfSwitch (void)
{
if (SWITCH)
{
while (SWITCH) softDelay(1000);
softDelay(1000);
return 1;
}
return 0;
}