📄 ear.c
字号:
/*********************************Sheena************************************/
#include "reg52\reg52.h"
#include "stdlib\stdlib.h"
#include "delay\delay.h"
#include "string\string.h"
//#include "keyboard\keyboard.h"
#include "date\date.h"
#include "time\time.h"
//#include "128x64\128x64.h"
#include "2x16LCD\2x16LCD.h"
#include "bmps\JBB.h"
#include "bmps\common.h"
#include "bmps\clock.h"
#include "bmps\calender.h"
#ifndef NULL
#define NULL ((void*)('\0'))
#endif
sbit GREEN_LED = 0x97;
sbit RED_LED = 0x94;
sbit BUZZER = 0x92;
sbit CMD_RECEIVED = 0x96;
sbit CMD_ACKNOWLEDGE = 0x95;
sbit COM_SELECT = 0xB3;
#define kbhit() (RI)
#define RESET_DATABASE 'R' /* Delete all records */
#define RECORD_COUNTS 'C' /* Get record counts */
#define ATTENDANCE_RECORDS 'A' /* Get attendance records */
#define FAIL_SAFE_ATTENDANCE_RECORDS 'S' /* */
#define SET_DATE 'D' /* Set system date */
#define SET_TIME 'T' /* Set system time */
#define GET_DATE 'G' /* Get system date */
#define GET_TIME 'H' /* Get system time */
#define REGISTER 'E' /* Register RFID */
#define RUN 'F' /* */
#define DISPLAY_RFID 'I' /* Identification */
#define RESEND_COMMAND() RC = 0; delay(5000); RC = 1;
#define RFID_RECEIVED() (rfid_received)
#define RFID_PROCESSED() rfid_received = 0; rfid_processed = 1;
#define COMMAND_RECEIVED() (!CMD_RECEIVED)
#define COMMAND_PROCESSED() CMD_PROCESSED = 0; \
delay(25000); \
CMD_PROCESSED = 1;
#define PROCESS_START() GREEN_LED = 1; RED_LED = 0;
#define PROCESS_END() GREEN_LED = 0; \
RED_LED = 1;
#define BUZZER_ON() BUZZER = 1;
#define BUZZER_OFF() BUZZER = 0;
/* Application specific code */
#define RFID_LENGTH 10
#define MAX_RECORD_COUNTS 2500
/* Data for serial interrupt */
char rfid[15];
unsigned char index = 0;
char rfid_received = 0;
char rfid_processed = 1;
char xdata display_rfid;
char cr[] = {'\n', 13, 0};
typedef struct
{
char rfid[14]; //14 bytes
struct date d; //4 bytes
struct time t; //4 bytes
}AttendanceRecord; //22 bytes
AttendanceRecord xdata attendance_records[MAX_RECORD_COUNTS];
int xdata record_counts;
int xdata fail_safe_record_counts;
char date_str[10];
char time_str[10];
char xdata reset_mode;
void transmit(char *str);
void updatescreen();
/*
char *readcommand(char *command)
{
int i = 0;
char alpha = 0;
char num = 0;
CMD_ACKNOWLEDGE = 0;
while(1)
{
*(command + i) = getkey();
if(*(command + i) == '\r')break;
if(*(command + i) >= 'A' && *(command + i) <= 'Z')alpha = 1;
if(*(command + i) >= '0' && *(command + i) <= '9')num = 1;
if(!alpha && !num)
{
PROCESS_START();
CMD_ACKNOWLEDGE = 1;
reset_mode = 0;
ENABLE_WATCHDOG();
while(1);
}
alpha = 0;
num = 0;
i++;
}
*(command + i) = '\0';
return command;
}
*/
char *readcommand(char *command)
{
/*
* We are using RX interrupt for receiving commands,
* hence the buffer and flag names are bit confusing
*/
rfid_received = 0;
rfid_processed = 1;
CMD_ACKNOWLEDGE = 0;
//ENABLE_WATCHDOG();
while(!RFID_RECEIVED());
strstrcpy(command, rfid);
rfid_received = 0;
rfid_processed = 1;
return command;
}
void lcd2x16displaystr(int x,int y,char *str) // function that displays string to specific quard of lcd
{
gotoxy(x,y);
puts(str);
}
void processcommand(char *cmd)
{
char str[10];
int i;
struct date d;
struct time t;
char command = *(cmd + 0);
char *val = cmd + 1;
//PROCESS_START();
lcd2x16displaystr(1, 2, "Command process");
if(command == GET_DATE)
{
datetostr(&today, str);
transmit("Date : ");
transmit(str);
transmit(cr);
}
if(command == SET_DATE)
{
if(val[0] != 0)
{
transmit(val);
transmit(cr);
strtodate(val, &d);
datesetdate(&d);
}
}
if(command == GET_TIME)
{
timetostr(&now, str);
transmit("Time : ");
transmit(str);
transmit(cr);
}
if(command == SET_TIME)
{
if(val[0] != 0)
{
strtotime(val, &t);
timesettime(&t);
}
}
if(command == RESET_DATABASE)
{
transmit("Resetting database");
transmit(cr);
record_counts = 0;
fail_safe_record_counts = 0;
}
if(command == RECORD_COUNTS)
{
itoa(record_counts, str, 10);
transmit("Record counts : ");
transmit(str);
transmit(cr);
}
if(command == ATTENDANCE_RECORDS)
{
for(i = 0; i < record_counts; i++)
{
itoa(i + 1, str, 10);
transmit("["); //01
transmit(attendance_records[i].rfid); //10
transmit(" "); //05
datetostr(&attendance_records[i].d, str);
str[2] = '/';
transmit(str); //05
transmit(" "); //05
timetostr(&attendance_records[i].t, str);
str[2] = ':';
transmit(str); //05
transmit("]"); //01
}
}
if(command == FAIL_SAFE_ATTENDANCE_RECORDS)
{
for(i = 0; i < fail_safe_record_counts; i++)
{
delay(20000);
itoa(i + 1, str, 10);
transmit("["); //01
transmit(attendance_records[i].rfid); //10
transmit(" "); //05
datetostr(&attendance_records[i].d, str);
str[2] = '/';
transmit(str); //05
transmit(" "); //05
timetostr(&attendance_records[i].t, str);
str[2] = ':';
transmit(str); //05
transmit("]"); //01
}
}
if(command == DISPLAY_RFID)
{
display_rfid = ~display_rfid;
}
updatescreen();
//PROCESS_END();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -