//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h>
// part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
void delay_sec(int sec);
int card_data(char *);
char card[6][7]={"B6AAFF\0", "CD84AA\0", "BACD94\0", "FC4956\0", "F1C9DB\0", "D15466\0"};
BYTE rxBuf[8];
const BYTE txCBuf[] = { 0x00, // Slave internal sub-address 0
0x00,0x40,0x12, // Seconds and minutes in BCD
0x02, // Day of Week, Monday
0x23,0x03,0x09, // Day-Month-year 23-Mar-09
0x93 }; // Enable clock output
char s[7][4]={"SUN\0","MON\0","TUE\0","WED\0","THU\0","FRI\0","SAT\0"};
char st[2][4]={"IN1\0","OUT\0"};
void main()
{
char ch[16]="\0\0\0\0\0\0\0";
char buff[23]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char ch1[23];
char rd[23];
char card[7];
char * strPtr;
int i=0,j=0,sts,m=0;
int no;
BYTE bError;
WORD count=0;
BYTE status;
BYTE l,k,n;
RX8_1_CmdReset();
RX8_1_EnableInt();
RX8_1_Start(RX8_PARITY_NONE);
UART_1_Start(UART_PARITY_NONE);
M8C_EnableGInt ; // Turn on interrupts
LCD_1_Start();
E2PROM_1_Start();
I2Cm_1_Start();
PRT0DR==0x00;
UART_1_CPutString("WELCOME TO MY PROJECT");
UART_1_PutCRLF();
UART_1_CPutString("RFID ATTENDANCE SYSTEM");
UART_1_PutCRLF();
UART_1_PutCRLF();
LCD_1_Position(0,0);
LCD_1_PrCString(" WELCOME TO ");
LCD_1_Position(1,0);
LCD_1_PrCString("RFID ATTENDANCE");
delay_sec(2);
LCD_1_Control(0x01);
LCD_1_Position(0,0);
LCD_1_PrCString("Do u want set");
LCD_1_Position(1,0);
LCD_1_PrCString("Time 'Yes' r 'No'");
delay_sec(1);
LCD_1_Control(0x01);
LCD_1_Position(0,0);
LCD_1_PrCString("Press the key");
LCD_1_Position(1,0);
LCD_1_PrCString("'Yes' r 'No'");
while(PRT0DR==0x00);
if((PRT0DR & 0x01) == 0x01)
status = I2Cm_1_bWriteCBytes(0x68,txCBuf,9,I2Cm_1_CompleteXfer); // NAK the slave to signify
// In a endless loop, keep reading the time from the DS1307
LCD_1_Control(0x01);
while(1){
I2Cm_1_bWriteCBytes(0x68,txCBuf,1,I2Cm_1_NoStop );
status = I2Cm_1_fReadBytes(0x68,rxBuf,7,I2Cm_1_RepStart );
if(status == 0) {
// Flag an error condition
}
I2Cm_1_fSendStart(0x68,I2Cm_1_WRITE); // Do a write
I2Cm_1_fWrite(0x00);
I2Cm_1_fSendRepeatStart(0x68,I2Cm_1_READ); // Do a read
for(i = 0; i < 7; i++) {
rxBuf[i] = I2Cm_1_bRead(I2Cm_1_ACKslave); // Read first 6 bytes,
}
rxBuf[7] = I2Cm_1_bRead(I2Cm_1_NAKslave);
LCD_1_Position( 0,0);
for(i=3; i<7;i++) { // NAK the slave to signify
if(i==3){
k=rxBuf[i]-1;
LCD_1_PrString(s[k]);
LCD_1_PrCString(" ");
}
else{
LCD_1_PrHexByte(rxBuf[i]);
if(i==4||i==5)
LCD_1_PrCString("-");
}
}
LCD_1_Position( 1,0);
LCD_1_PrCString("TIME: ");
LCD_1_PrHexByte(rxBuf[2]);
LCD_1_PrCString(":");
LCD_1_PrHexByte(rxBuf[1]);
LCD_1_PrCString(":");
LCD_1_PrHexByte(rxBuf[0]);
delay_sec(1);
LCD_1_Control(0x01);
LCD_1_Position( 0,0);
LCD_1_PrCString("WELCOME COLLEGE");
LCD_1_Position(1,0);
LCD_1_PrCString("ATTENDENCE SYSTM");
delay_sec(2);
if(RX8_1_bCmdCheck)
if(strPtr = RX8_1_szGetParam()){
UART_1_CPutString("\r\n Reader:");
for(i=0;i<15;i++)
ch[i]= *(strPtr+i);
UART_1_PutString(ch);
UART_1_CPutString("\r\n Extract data:");
for(i=6;i<12;i++)
card[i-6]=ch[i];
UART_1_PutString(card);
UART_1_PutCRLF();
}
RX8_1_CmdReset();
delay_sec(1);
LCD_1_Control(0x01);
no=card_data(card);
if(ch[0]!='\0'){
LCD_1_Control(0x01);
if(no!=9){
LCD_1_Position(0,5);
LCD_1_PrCString("HELLO");
}
switch(no)
{
case 1: LCD_1_Position(1,0);
LCD_1_PrCString("Mr SIVA PRASAD");
UART_1_CPutString("HELLO Mr SIVA PRASAD ");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1001 ");
UART_1_PutCRLF();
break;
case 2: LCD_1_Position(1,0);
LCD_1_PrCString("Mr AMIT KUMAR");
UART_1_CPutString("HELLO Mr AMIT KUMAR");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1002 ");
UART_1_PutCRLF();
break;
case 3: LCD_1_Position(1,0);
LCD_1_PrCString("Mr RAJANEESH");
UART_1_CPutString("HELLO Mr RAJANEESH");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1003 ");
UART_1_PutCRLF();
break;
case 4: LCD_1_Position(1,2);
LCD_1_PrCString("MISS VIJAYA");
UART_1_CPutString("HELLO MISS VIJAYA");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1004 ");
UART_1_PutCRLF();
break;
case 5: LCD_1_Position(1,1);
LCD_1_PrCString("MISS SIRISHA");
UART_1_CPutString("HELLO MISS SIRISHA");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1005 ");
UART_1_PutCRLF();
break;
case 6: LCD_1_Position(1,0);
LCD_1_PrCString("MISS NAGARATHNA");
UART_1_CPutString("HELLO MISS NAGARATHNA");
UART_1_PutCRLF();
UART_1_CPutString("STUDENT NO: 1006 ");
UART_1_PutCRLF();
break;
default: LCD_1_Control(0x01);
LCD_1_Position(0,0);
LCD_1_PrCString("HELLO THIS IS");
LCD_1_Position(1,0);
LCD_1_PrCString("INVALID CARD");
break;
}
delay_sec(2);
for(i=0;i<23;i++)
ch1[i]='\0';
if(no>0 && no<=9){
LCD_1_Control(0x01);
LCD_1_Position(0,0);
LCD_1_PrCString("NOW PRESS THE");
LCD_1_Position(1,0);
LCD_1_PrCString(" IN OUT QUIT ");
while(PRT0DR==0x00);
LCD_1_Control(0x01);
if((PRT0DR & 0x01) == 0x01)
sts=1;
else if((PRT0DR & 0x02) == 0x02)
sts=0;
else if((PRT0DR & 0x04) == 0x04)
sts=2;
if(sts==1){
LCD_1_Position(0,0);
LCD_1_PrCString("GOOD MORNING");
LCD_1_Position(1,0);
LCD_1_PrCString("NOW YOU ARE IN");
}
else if(sts==0){
LCD_1_Position(0,0);
LCD_1_PrCString("NOW YOU ARE OUT");
LCD_1_Position(1,0);
LCD_1_PrCString("GOOD NIGHT BYE");
}
else if(sts==2){
LCD_1_Position(0,0);
LCD_1_PrCString("NOW YOU ARE QUIT");
LCD_1_Position(1,2);
LCD_1_PrCString("GOOD BYE");
UART_1_PutCRLF();
}
}
delay_sec(2);
if(sts!=2){
for(i=0;i<6;i++)
ch1[i]=card[i];
for(i=0;i<3;i++){
if(sts==1)
ch1[i+6]=st[0][i];
else if(sts==0)
ch1[i+6]=st[1][i];
}
m=9;
status = I2Cm_1_fReadBytes(0x68,rxBuf,7,I2Cm_1_RepStart );
if(status == 0) {
}
I2Cm_1_fSendStart(0x68,I2Cm_1_WRITE);
I2Cm_1_fWrite(0x00);
I2Cm_1_fSendRepeatStart(0x68,I2Cm_1_READ);
for(i = 0; i < 7; i++) {
rxBuf[i] = I2Cm_1_bRead(I2Cm_1_ACKslave);
ch1[m] = (rxBuf[i]/16)+48;
m++;
ch1[m] =(rxBuf[i]%16)+48;
m++;
}
rxBuf[7] = I2Cm_1_bRead(I2Cm_1_NAKslave);
LCD_1_Control(0x01);
bError = E2PROM_1_bE2Write(count,ch1,23,25);
if(no!=0)
if ( bError == E2PROM_1_NOERROR ) {
if(sts==1)
UART_1_CPutString("ENTER TIME :");
else if(sts==0)
UART_1_CPutString("EXIT TIME :");
UART_1_PutChar(ch1[13]);
UART_1_PutChar(ch1[14]);
UART_1_CPutString(":");
UART_1_PutChar(ch1[11]);
UART_1_PutChar(ch1[12]);
UART_1_CPutString(":");
UART_1_PutChar(ch1[9]);
UART_1_PutChar(ch1[10]);
UART_1_CPutString(" ");
UART_1_PutChar(ch1[15]);
UART_1_PutChar(ch1[16]);
UART_1_CPutString(" ");
UART_1_PutChar(ch1[17]);
UART_1_PutChar(ch1[18]);
UART_1_CPutString("-");
UART_1_PutChar(ch1[19]);
UART_1_PutChar(ch1[20]);
UART_1_CPutString("-");
UART_1_PutChar(ch1[21]);
UART_1_PutChar(ch1[22]);
UART_1_PutCRLF();
UART_1_PutCRLF();
LCD_1_Position(0,0);
if(sts==1)
LCD_1_PrCString("YOUR ENTER TIME");
else if(sts==0)
LCD_1_PrCString("YOUR EXIT TIME");
LCD_1_Position(1,4);
LCD_1_WriteData(ch1[13]);
LCD_1_WriteData(ch1[14]);
LCD_1_PrCString(":");
LCD_1_WriteData(ch1[11]);
LCD_1_WriteData(ch1[12]);
LCD_1_PrCString(":");
LCD_1_WriteData(ch1[9]);
LCD_1_WriteData(ch1[10]);
count=count+23;
}
else {
UART_1_PutCRLF();
UART_1_CPutString("DATA NOT STORED IN EEPROM");
UART_1_PutCRLF();
}
delay_sec(2);
}
if(count>=115){
for(count=0;count<115;count++){
UART_1_CPutString("STUDENT details:");
E2PROM_1_E2Read(count, rd, 23);
UART_1_PutString(rd);
UART_1_PutCRLF();
count=count+22;
//E2PROM_1_bE2Write(count,buff,23,25);
for(i=0;i<=23;i++)
rd[i]='\0';
}
count=0;
}
}
for(i=0;i<8;i++)
ch[i]='\0';
for(i=0;i<6;i++)
card[i]='\0';
LCD_1_Control(0x01);
LCD_1_Position(0,0);
LCD_1_PrCString("NOW PLEASE SHOW");
LCD_1_Position(1,3);
LCD_1_PrCString("YOUR CARD");
delay_sec(2);
LCD_1_Control(0x01);
LCD_1_Position(0,0);
}
delay_sec(1);
}
int card_data(char ch[]){
int i=0,j=0;
while(j<9){
while(ch[i]==card[j][i]&&ch[i]!='\0'&&card[j][i]!='\0')
i++;
if(ch[i]=='\0'&&card[j][i]=='\0')
return(j+1);
i=0;
j++;
}
return(0);
}
void delay_sec(int sec)
{
int i,j,secd;
for (secd=0;secd<=sec;secd++)
for(i=0;i<=2;i++)
for (j= 0;j<=20480;j++)
{
}
}
No comments:
Post a Comment