-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
168 lines (152 loc) · 3.01 KB
/
main.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
/*
* main.c
*
* Created: 2/4/2015 1:58:00 PM
* Author: Victor Accarini
*/
#define F_CPU 4000000UL
#define BAUD 9600
#define MYBAUD F_CPU/16/BAUD-1
#include <avr/io.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <string.h>
#include "util.h"
#include "functions.h"
#include "mem.h"
//Interrupt Service Routine for INT0
ISR(INT0_vect)
{
unsigned char *ADC = (unsigned char *)ADC_PB_Address;
//Enable Output
PORTB |= (1 << ADC_Output);
DDRB |= (1 << PB2); //Output Enable
_delay_us(1);
//Read data from 8255 PORTB
ADC_Data = (*ADC);
//Send Data to LEDs
ADC = ADC_PA_Address;
(*ADC_DataAddress) = (unsigned char)~(ADC_Data);
//Disable Output
PORTB &= ~(1 << ADC_Output);
}
// Clock Generation for ADC
ISR(TIMER0_COMP_vect)
{
TCNT0 = 0;
}
// Main program
int main(void)
{
unsigned char *cp;
unsigned int i, off1, off2, off3;
unsigned char str[160], arg1[15], arg2[15], arg3[15];
unsigned int hexnum;
// Systems Initializations
_Init_Mem();
_Init_UART(MYBAUD);
_Init_Peripheral();
_Init_ADC();
_Enable_SPI();
EnableInterrupts();
ADC_DataAddress = (unsigned char*)0x4000;
//while(1)
//{
for (i = 0; i < 512; i++)
{
_ADC_Start();
_delay_ms(10);
DisableInterrupts();
_SPI_Send_Data(i,ADC_Data);
EnableInterrupts();
}
for (i = 0; i < 512; i++)
{
DisableInterrupts();
Hex2Asc(_SPI_Receive_Data(i),str);
EnableInterrupts();
putLine(str);
}
//Input command
//getLine(str);
//putLine(str);
/*//Read the input looking for a valid command
if (str[0] == 'F') //Fill function
{
i = 2;
off1 = i;
while (str[i] != ' ') //Get first argument
{
arg1[i-off1] = str[i];
i++;
}
arg1[i-off1] = '\0';
i++;
off2 = i;
while (str[i] != ' ') //Get second argument
{
arg2[i-off2] = str[i];
i++;
}
arg2[i-off2] = '\0';
i++;
off3 = i;
while (str[i] != '\r' && str[i] != '\n') //Get second argument
{
arg3[i-off3] = str[i];
i++;
}
arg3[i-off3] = '\0';
F(arg1,arg2,arg3);
}
else if (str[0] == 'D') //Display function
{
i = 2;
off1 = i;
while (str[i] != ' ') //Get first argument
{
arg1[i-off1] = str[i];
i++;
}
arg1[i-off1] = '\0';
i++;
off2 = i;
while (str[i] != ' ') //Get second argument
{
arg2[i-off2] = str[i];
i++;
}
arg2[i-off2] = '\0';
D(arg1,arg2);
}//*/
//}//End while loop
/*
if (strcmp(str, "Start") == 0){
PORTB = 0x00;
}
putLine("Microprocessor - Lab");
putLine("Nailed it");
putLine("---------------------");
putLine("Wait for it.");
putLine("LED Blinking in....");
putLine("5");
_delay_ms(1000);
putLine("4");
_delay_ms(1000);
putLine("3");
_delay_ms(1000);
putLine("2");
_delay_ms(1000);
putLine("1");
_delay_ms(1000);
while(1)
{
PORTB = 0x00;
_delay_ms(500);
PORTB = 0x01;
_delay_ms(500);
}
*/
return 0;
}