-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
181 lines (146 loc) · 3.04 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
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* main.c
*
* Created: 05-11-2017 22:46:55
* Author : SOURABH KHEMKA
*/
#include <avr/io.h>
#include <util/delay.h>
/* Prototypes */
void USART_Init (unsigned int baud);
void USART_Transmit (unsigned char data);
unsigned char USART_Receive (void);
#define SETBIT(ADDRESS, BIT) (ADDRESS |= (1 << BIT))
#define CLEARBIT(ADDRESS, BIT) (ADDRESS &= ~(1 << BIT))
#define CHECKBIT(ADDRESS, BIT) (!(ADDRESS & (1 << BIT)))
#define LED1 PE6 //Connected to PORTE
#define LED2 PE7 //Connected to PORTE
void timer_init()
{
TCCR1B |= (1<<CS12) | (1<<CS10);
TCNT1 = 0;
}
void transmit(int num)
{
if (num == 0)
{
USART_Transmit_Number(48);
USART_Transmit_Number(48);
}
int mod=1,temp, numb;
numb = num;
while(num != 0)
{
num = num / 10;
mod *= 10;
}
mod /= 10;
while(mod > 0)
{
USART_Transmit_Number((numb/mod)+48);
numb = numb % mod;
mod = mod/10;
}
}
int main (void)
{
//char message[] = "WELCOME MONITOR TO ROBOLUTION's AVR!\r\n";
int i=0, sec=0, min=0, hour=0;
/* Set the baudrate to 19.2 kbps using a 16.00 MHz crystal
Fuse bits set to handle CPU with external Crystal Oscillator */
unsigned char a=100;
USART_Init (12);//12 :: 9600
DDRE = 0xC0;
timer_init();
while (1)
{
if(TCNT1 > 1952)
{
char message3[] = "\r\n";
while(message3[i] != '\0')
{
USART_Transmit(message3[i++]);
//_delay_ms(500);
}
i = 0;
char message4[] = "\033[1A";
while(message4[i] != '\0')
{
USART_Transmit(message4[i++]);
//_delay_ms(500);
}
i = 0;
char message5[] = "\033[K";
while(message5[i] != '\0')
{
USART_Transmit(message5[i++]);
//_delay_ms(500);
}
i = 0;
TCNT1 = 0;
sec++;
PORTE |= (1<<PE7)|(1<<PE6);
if(sec == 60)
{
sec = 0;
min++;
if (min == 60)
{
hour++;
min = 0;
}
}
transmit(hour);
char message1[] = "::";
while(message1[i] != '\0')
{
USART_Transmit(message1[i++]);
//_delay_ms(500);
}
i = 0;
transmit(min);
char message2[] = "::";
while(message2[i] != '\0')
{
USART_Transmit(message2[i++]);
//_delay_ms(500);
}
i = 0;
transmit(sec);
}
/////////
}
return 0;
}
//Initialize USART
void USART_Init (unsigned int baud)
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x0C; //9600BPS at 14745600Hz
UBRR1H = 0x00;
UCSR1B = 0x98;
}
//Read and Write functions
void USART_Transmit (unsigned char data)
{
/* Wait for empty transmit buffer */
while (!(UCSR1A & (1 << UDRE1)));
/* Put data into buffer, transmits the data */
UDR1 = data;
}
void USART_Transmit_Number (unsigned char data)
{
/* Wait for empty transmit buffer */
while (!(UCSR1A & (1 << UDRE1)));
/* Put data into buffer, transmits the data */
UDR1 = data;
}
unsigned char USART_Receive (void)
{
/* Wait for data to be received */
while (!(UCSR1A & (1 << RXC1)));
/* Get and return received data from buffer */
return UDR1;
}