-
Notifications
You must be signed in to change notification settings - Fork 0
/
mipslabmain.c
84 lines (65 loc) · 1.95 KB
/
mipslabmain.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
/* mipslabmain.c
This file written 2015 by Axel Isaksson,
modified 2015, 2017 by F Lundevall
Latest update 2017-04-21 by F Lundevall
This file was modified 2017-02-28 by Mattias Stahre and Gustaf Halvardsson
For copyright and licensing, see file COPYING */
#include <stdint.h> /* Declarations of uint_32 and the like */
#include <pic32mx.h> /* Declarations of system-specific addresses etc */
#include "mipslab.h" /* Declatations for these labs */
int main(void) {
/*
This will set the peripheral bus clock to the same frequency
as the sysclock. That means 80 MHz, when the microcontroller
is running at 80 MHz. Changed 2017, as recommended by Axel.
*/
SYSKEY = 0xAA996655; /* Unlock OSCCON, step 1 */
SYSKEY = 0x556699AA; /* Unlock OSCCON, step 2 */
while(OSCCON & (1 << 21)); /* Wait until PBDIV ready */
OSCCONCLR = 0x180000; /* clear PBDIV bit <0,1> */
while(OSCCON & (1 << 21)); /* Wait until PBDIV ready */
SYSKEY = 0x0; /* Lock OSCCON */
/* Set up output pins */
AD1PCFG = 0xFFFF;
ODCE = 0x0;
TRISECLR = 0xFF;
PORTE = 0x0;
/* Output pins for display signals */
PORTF = 0xFFFF;
PORTG = (1 << 9);
ODCF = 0x0;
ODCG = 0x0;
TRISFCLR = 0x70;
TRISGCLR = 0x200;
/* Set up input pins */
TRISDSET = (1 << 8);
TRISFSET = (1 << 1);
/* Set up SPI as master */
SPI2CON = 0;
SPI2BRG = 4;
/* SPI2STAT bit SPIROV = 0; */
SPI2STATCLR = 0x40;
/* SPI2CON bit CKP = 1; */
SPI2CONSET = 0x40;
/* SPI2CON bit MSTEN = 1; */
SPI2CONSET = 0x20;
/* SPI2CON bit ON = 1; */
SPI2CONSET = 0x8000;
display_init();
display_string(0, "KTH/ICT lab");
display_string(1, "in Computer");
display_string(2, "Engineering");
display_string(3, "Welcome!");
display_update();
display_image(96, icon);
labinit(); /* Do any lab-specific initialization */
InteruptFlag40ms = 0;
while( 1 )
{
if(InteruptFlag40ms == 1){
labwork(); /* Do lab-specific things again and again */
InteruptFlag40ms = 0;
}
}
return 0;
}