-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
139 lines (118 loc) · 2.9 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
#include "stm32f4xx.h"
#include "uart.h"
#include "systick.h"
#include "spi.h"
#include "rc522.h"
#include "rtc.h"
#include "lcd.h"
int main(void){
/* Clock update */
SystemCoreClockUpdate();
/* Initialization section */
//Variables
uint8_t CardID[4];
uint8_t status;
rtcDate data;
rtcTime czas;
uint8_t temp;
char buffer[100];
//SysTick
SysTick_Init();
//LCD
LCD_Init();
//UART
UART2_Init();
UART1_Init();
//RTC
RTClock_Init();
//SPI
SPI1_Init();
//RC522
RC522_Init();
/* PROGRAM TESTOWY DO WYSWIETLENIA WERSJI RC522 NA LCD */
LCD_clear();
LCD_goTo(0,0);
LCD_writeTxt("Wersja RC522:");
LCD_goTo(0,1);
temp = RC522_readReg(VersionReg); //Read version of chip -> 0x12 probably counterfit chip (info google)
sprintf(buffer, "0x%x", temp);
LCD_writeTxt(buffer);
Delay_ms(3000);
while(1){
/* OBSLUGA PRZESYLU DANYCH DO FIREBASE */
/*
switch (statusUART1){ //STATE MACHINE
case 49: //Read legitka UID
for (int i = 0; i<4; i++){
CardID[i]=0;
}
status = RC522_checkID(CardID);
while(status != OK){
status = RC522_checkID(CardID);
}
if (status == OK){
RC522_dumpUIDtoNodeMCU(CardID);
RC522_dumpUIDtoSerial(CardID);
}
statusUART1 = 0;
break;
case 50: //Read plytka UID
for (int i = 0; i<4; i++){
CardID[i]=0;
}
status = RC522_checkID(CardID);
while(status != OK){
status = RC522_checkID(CardID);
}
if (status == OK){
RC522_dumpUIDtoNodeMCU(CardID);
RC522_dumpUIDtoSerial(CardID);
}
statusUART1 = 0;
break;
case 51: //Get time and date form RTC
RTClock_getTime(&czas);
RTClock_getDate(&data);
RTClock_fullToNodeMCU(&czas, &data);
statusUART1 = 0;
break;
default: //Restart state machine
break;
}
*/
/* PROGRAM TESTOWY DO SPRAWDZENIA CZYTNIKA */
/**/
status = RC522_checkID(CardID);
//RC522_firmwareVer();
Delay_ms(1000);
if (status == 0){
//RC522_dumpUIDtoSerial(CardID);
sprintf(buffer, "%x%x%x%x", CardID[0],CardID[1],CardID[2],CardID[3]);
LCD_clear();
LCD_goTo(0,0);
LCD_writeTxt(buffer);
Delay_ms(2000);
}
else{
//UART2_sendString("Brak karty!\r\n");
LCD_clear();
LCD_goTo(0,0);
LCD_writeTxt("Brak karty!");
Delay_ms(2000);
}
/* PROGRAM TESTOWY DO SPRAWDZENIA RTC */
/**/
RTClock_getTime(&czas);
RTClock_getDate(&data);
//RTClock_fullToSerial(&czas, &data);
//UART2_sendString("\r\n");
LCD_clear();
LCD_goTo(0,0);
sprintf(buffer, "%u/%u/%u", data.day, data.month, data.year);
LCD_writeTxt(buffer);
LCD_goTo(0,1);
sprintf(buffer, "%u:%u:%u", czas.hours, czas.minutes, czas.seconds);
LCD_writeTxt(buffer);
Delay_ms(2000);
}
}