-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assign2.c
168 lines (114 loc) · 4.26 KB
/
Assign2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*_____________________________________________________________________________________________________________________
Assignment: Elec2700
Module: Assignment 2
Author: Chris Caelli & Tim Farnworth
Date: 20/4/15
Description:
This program will emulate a MIDI keyboard and produce excellent music (probably)
Notes:
Basic Structure is being implemented. The code is limited to strict C.
Current c51.exe compiler compiles the program, however gives 5 warnings of "Uncalled Functions".
This is okay as we're implimenting stub programs.
Revisions: v0.1 Alpha
_____________________________________________________________________________________________________________________*/
//--------------------------------------------------------------------------------------------------------------------
// Declarations
//--------------------------------------------------------------------------------------------------------------------
#include "c8051F120.h"
#include "Assign2.h"
#include "Methods.h"
#include "LCD.h"
/* Variables */
unsigned char gameState = 0; /* Used for switching to and from the volume and play states */
int debugcounter=0;
unsigned long old_time = 0;
//--------------------------------------------------------------------------------------------------------------------
// Abstract & Menu Methods
//--------------------------------------------------------------------------------------------------------------------
/*--------------------------------------------------------------------------------------------------------------------
Function: Main
Description: Main routine
Revisions:
--------------------------------------------------------------------------------------------------------------------*/
void main(void)
{
General_Init();
Oscillator_Init();
Timer_Init();
Voltage_Reference_Init();
DAC_Init();
Interrupts_Init();
initLCD();
P2 = 0x0;
while(1)
{
//Allow user to change current gamestate. i.e. menu or playing
Check_State_Change(); //STILL NEEDED AS OF 5:41PM 4/5/15
//Execute the current state chosen
switch (gameState)
{
case 0: /* Volume Menu */
//Clear any previous visuals
printLCD("Volume Levels");
blink();
Change_Volume();
Display_Volume();
Change_Octave();
break;
case 1: /* Play Menu */
PORT1_TO_PLAY_TONE();
break;
}
}
//This is a debug counter that should never, EVER execute. So, delete it when you have no issues at the end.
// while(1)
// {
// debugcounter +=1;
// }
}
/*--------------------------------------------------------------------------------------------------------------------
Function: General_Init
Description: Initialise ports, watchdog....
Revisions:
--------------------------------------------------------------------------------------------------------------------*/
void General_Init()
{
WDTCN = 0xde;
WDTCN = 0xad;
SFRPAGE = CONFIG_PAGE;
P2MDOUT = 0xff; // Need to make pushpull outputs to drive LEDs properly
P3MDOUT = 0x7F; // Outputs
XBR2 = 0x40;
}
/*--------------------------------------------------------------------------------------------------------------------
Function: Check_State_Change
Description: Check the MPB state, and see if user wants to change state
Revisions:
--------------------------------------------------------------------------------------------------------------------*/
void Check_State_Change()
{
if (MPB==0) /* Negative logic */
{
delay(25); //Calling a delay for 25ms
if (MPB==0)
{
while (MPB==0);
cmdLCD(CLR_DISP);
gameState = (gameState+1)%2; /* This will take the current state, add 1, and return the remainder. i.e. toggle between 1 and 0.*/
//this won't work without the delay pls.
}
}
}
unsigned char getState(void){
return(gameState);
}
void setState(unsigned char temp_state){
P2 = 0; /* Clear port 2 in every state change */
gameState = temp_state;
}
void blink(void){
if((millis() - old_time)>500){
LD1 = ~LD1;
old_time = millis();
}
}