Saturday, 23 November 2013

FYP 2 : Week 10 ~ Test the project and finished the frame door

Welcome again to my blog here....So far week 10 now...^.^....

Week 10 ~ Test the hardware and during the frame door Supervisor office.

For the week 10 22/11( Friday). for the week 10 i very near for FYP project presentation, still have 4 week left, so test the hardware and bring the complete frame door to my Supervisor office to test the hardware and construct the frame door.

During the test the hardware, need make sure the connection between RFID reader and Controller. Very important is Pin VCC and Pin GND because if mistake to connect the controller hardware IC will be broke.
After that, wiring the motion sensor at top at the door, then the controller and the reader will put at the table.

Concept test the hardware is start from when the student scan the ID card at RFID reader, then the reader will transfer the data to controller will have control the LCD to display the date and time. After that, the controller will save the date and time at EEPROM memory. Then controller will turn On the motion sensor, waiting the student to across the door. After, student the across the door the motion sensor will detect the object, sent the data to the controller and controller will going to save the database into the mirco SD card. Lastly, take out the mirco Sd card put into the laptop the open the file as MIKRO00A to check attendance student date and time from the database.

For the first time test the program and the hardware, the program is working complete and the hardware also, but the problem is waiting time around 20s to turn On the motion sensor and that is too long time to use. After that, after detect from motion sensor also have to wait around 10s to save the database into the micro SD card. So need to change the time to be short and faster.

Refer the figure 1 to more detail about the hardware.




Refer to figure 2 to more detail about the frame door.
Figure 2 : frame door


Thanks to view and read my blog here.....

Remember forget to continue to read following week....

Have a nice day and happy forever.....^.^....







Saturday, 16 November 2013

FYP 2 : Week 9 ~ Discuss with Supervisor Structural of the project.

Welcome to my Blog here.....hahaha...Enjoy it...

Week 9 ~ to discuss with Supervisor the structural of the project.

For the week 9 15/11 (Firday). I suggest the structural of the project as a frame door, this is because my project is student attendance system. Then the consent of the project is when a student using the id card to scan the RFID reader, the RDIF reader will receive the date from the student. After that, the date will sent to the controller system and display the touch screen button to touch. And then, the date will save into EEPROM such as micro SD card after student across  the motion sensor. Lastly, can check the ID code from the student, date and time to scan.

So supervisor also agree my idea, and i will going to using the frame door material is PVC make it to be like a door shape. And the motion sensor will into the center door, easy to detect the student after scan the card. Refer the figure 1 to under more detail.


Figure 1 : Structural of PVC


Thank you to read my blog here, hehe...

Remember to read week 10....hehehe

Have a nice day......Gambateh......




Saturday, 2 November 2013

FYP 2 : Week 8 ~ Programming

Welcome to my blog here again.....Enjoy it....Gambateh...

Week 8 ~ Do the program for the project.

For the week 8 8/11 ( Friday).C language program is my main program for the project and i using MicroC Pro as the software to create my program. Refer the program below.

 #include <built_in.h>
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

sbit OUT at RB1_bit;
sbit RDY_CLK at RB2_bit;
sbit SEN_MOV at RB3_bit;
sbit SHD at RB4_bit;
sbit MOD at RB5_bit;

sbit OUT_Direction at TRISB1_bit;
sbit RDY_CLK_Direction at TRISB2_bit;
sbit SEN_MOV_Direction at TRISB3_bit;
sbit SHD_Direction at TRISB4_bit;
sbit MOD_Direction at TRISB5_bit;

//char txt1[] = "RFID";
//char txt2[] = "MASUK";
//char txt3[] = "TUNGGU";char txt4[] = "SAVE";

unsigned short sync_flag,
               one_seq,                           // counts the number of 'logic one' in series
               data_in,                            // gets data bit depending on data_in_1st and data_in_2nd
               cnt, k,  M,                    
               tmp, b, v, Save_Mem,
               cnt1, cnt2;                            // auxiliary counters
unsigned short data_index;                   // marks position in data arrey
char i;
char _data[256], test[8];
char data_valid[64];
char bad_synch;                                    
char seconds, minutes, hours, day, month, year;

void Interrupt() {

  if (INT2IF_bit && INT2IE_bit) {
      cnt++;                  // count interrupts on INT1 pin (RB1)
      INT2IF_bit = 0;
     }

  else if (INT1IE_bit && INT1IF_bit) {
     cnt = 0;
     sync_flag = 1;
     INT1IF_bit = 0;
     INT1IE_bit = 0;
     INT2IF_bit = 0;
     INT2IE_bit = 1;
   }
   else if (INT3IE_bit && INT3IF_bit) {
   Save_Mem = 1;
   TMR0IE_bit = 0;
   TMR0IF_bit = 0;
   INT3IE_bit = 0;
   INT3IF_bit= 0;
   }
   else if (TMR0IF_bit && TMR0IE_bit) {
   Save_Mem = 1 ;
   TMR0IE_bit = 0;
   TMR0IF_bit = 0;
   INT3IE_bit = 0;
   INT3IF_bit= 0;
   }
}


char CRC_Check(char *bit_array) {

char row_count, row_bit, column_count;
char row_sum, column_sum;
char row_check[5];
char column_check[11];

                                                                          // row parity check:
   row_count = 9;                                             // count rows
   while (row_count < 59) {
     column_count = 0;                                     // count columns
     while (column_count < 5) {
       row_check[column_count] = bit_array[row_count+column_count];
       column_count++;
     }
     row_bit = 0;                                              // count row bits
     row_sum = 0;
     while (row_bit < 4) {
       row_sum = row_sum + row_check[row_bit];
       row_bit++;
     }

     if (row_sum.B0 != row_check[4].B0) {
       return 0;
     }
     row_count = row_count + 5;
   }
                                                                        // end row parity check

                                                                          // column parity check
   column_count = 9;                                          // count columns
   while (column_count < 13) {
     row_bit = 0;                                                      // count column bits
     row_count = 0;                                                  // count rows
     while (row_bit < 11) {
       column_check[row_bit] = bit_array[column_count+row_count];
       row_bit++;
       row_count = row_count + 5;
     }

     row_bit = 0;                                                         // count column bits
     column_sum = 0;
     while (row_bit < 10) {
       column_sum = column_sum + column_check[row_bit];
       row_bit++;
     }

     if (column_sum.B0 != column_check[10].B0) {
       return 0;
     }
     column_count++;
   }
   // end column parity check
   if (bit_array[63] == 1) {
     return 0;
   }
   return  1;
}

void Transform_RTC() {
  seconds  =  ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F);                  
  minutes  =  ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F);                
  hours    =  ((hours & 0xF0)  >> 4)*10  + (hours & 0x0F);                        
  year     =   (day & 0xC0) >> 6;                                                                
  day      =  ((day & 0x30) >> 4)*10    + (day & 0x0F);                              
  month    =  ((month & 0x10)  >> 4)*10 + (month & 0x0F);                      
}

void Read_RTC() {

  I2C1_Start();                                         // Issue start signal
  I2C1_Wr(0xA0);                                  // Address PCF8583, see PCF8583 datasheet
  I2C1_Wr(2);                                           // Start from address 2

  I2C1_Repeated_Start();                        // Issue repeated start signal
  I2C1_Wr(0xA1);                               // Address PCF8583 for reading R/W=1
  seconds = I2C1_Rd(1);                  
  minutes = I2C1_Rd(1);                  
  hours = I2C1_Rd(1);                          
  day = I2C1_Rd(1);                        
  month = I2C1_Rd(0);  
  I2C1_Stop();                                      // Issue stop signal
  day = day & 0x3F;                             // Re-format day data
}
//-------------------- Output values to LCD
void Display_RTC() {

   Lcd_Chr(1, 6, (day / 10)   + 48);                   // Print tens digit of day variable
   Lcd_Chr(1, 7, (day % 10)   + 48);                // Print oness digit of day variable
   Lcd_Chr(1, 9, (month / 10) + 48);
   Lcd_Chr(1,10, (month % 10) + 48);
   Lcd_Chr(1,15,  year        + 49);                   // Print year variable + 8 (start from year 2008)

   Lcd_Chr(2, 6, (hours / 10)   + 48);
   Lcd_Chr(2, 7, (hours % 10)   + 48);
   Lcd_Chr(2, 9, (minutes / 10) + 48);
   Lcd_Chr(2,10, (minutes % 10) + 48);
   Lcd_Chr(2,12, (seconds / 10) + 48);
   Lcd_Chr(2,13, (seconds % 10) + 48);
}

//------------------ Performs project-wide init
void Init_RTC() {

  I2C1_Init(100000);                                      // Initialize Soft I2C communication

  Lcd_Init();                                                    // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                          // Clear LCD display
  Lcd_Cmd(_LCD_CURSOR_OFF);             // Turn cursor off

  Lcd_Out(1,1,"Date:");                                 // Prepare and output static text on LCD
  Lcd_Chr(1,8,':');
  Lcd_Chr(1,11,':');
  Lcd_Out(2,1,"Time:");
  Lcd_Chr(2,8,':');
  Lcd_Chr(2,11,':');
  Lcd_Out(1,12,"201");
}

//void Display_Intro(){

  //Lcd_Init();                                                  
  //Lcd_Cmd(_LCD_CLEAR);                          
  //Lcd_Cmd(_LCD_CURSOR_OFF);        
  //Lcd_Out(1,6,txt3);              
  //Lcd_Out(2,6,txt4);              
 // Delay_ms(2000);
 // Lcd_Cmd(_LCD_CLEAR);            

//  Lcd_Out(1,1,txt1);              
 // Lcd_Out(2,5,txt2);              
 // Delay_ms(2000);

//}




// main program

void main() {

  ADCON1 = 0x0F;                             // AD converter off
  CMCON = 7;
   k = 0;
  OUT_Direction = 1;                          // RFID TX
  RDY_CLK_Direction = 1;                // RFID RX
  SEN_MOV_Direction = 1;               // motion sensor
  SHD_Direction = 0;                            // RFID
  MOD_Direction = 0;                          // RFID
  //TrisB0_bit = 1;
  Init_RTC();                                     // Initialize Clock
  SHD = 0;
  MOD = 0;
  Lcd_Init ();
  //Display_Intro() ;
  UART1_Init(19200);                         // Initialise USART communication
  Delay_ms(100);
  UART1_Init(19200);
  sync_flag = 0;                              // sync_flag is set when falling edge on RB0 is detected
  one_seq = 0;                                // counts the number of 'logic one' in series
  data_in = 0;                              // gets data bit
  data_index = 0;                             // marks position in data arrey
  cnt = 0;                                    // interrupt counter
  cnt1 = 0;                                  // auxiliary counter
  cnt2 = 0;                                     // auxiliary counter
     Lcd_Cmd(_LCD_CLEAR);                   // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);             // Cursor off
    Lcd_Out(1,6,"RFID CLOCK IN");                   // Write text in first row
   delay_ms(2000);
     Lcd_Cmd(_LCD_CLEAR);                    // Clear display
  // setup interrupts
  INTEDG1_bit = 0;                     // Interrupt on falling edge on RB0
  INTEDG2_bit = 1;                     // Interrupt on rising edge on RB1
  INT1IF_bit = 0;                         // Clear INT0IF
  INT2IF_bit = 0;                         // Clear INT1IF
  // INT1IP_bit = 1;
 //  INT2IP_bit = 1;
  INT1IE_bit = 0;                         // turn OFF interrupt on INT0
  INT2IE_bit = 0;                          // turn OFF interrupt on INT1
  //Int0IE_bit = 1;
  GIE_bit = 1;                                 // enable GIE
  M = 0;

  while (1) {
    bad_synch = 0;                  // set bad synchronization variable to zero
    cnt = 0;                                // reseting interrupt counter
    sync_flag = 0;                      // reseting sync flag
    INT2IF_bit = 0;
    INT2IE_bit = 0;                   // disable external interrupt on RB1 (for sync and sample)
    INT1IF_bit = 0;
    INT1IE_bit = 1;                      // enable external interrupt on RB0 (start sync procedure)
    //GIE_bit = 1;
    T0CON = 0b10000101;               // Timer0 Control Register

    while (sync_flag == 0) {                   // waiting for falling edge on RB0
    Read_RTC();                                // Read time from RTC(PCF8583)
    Transform_RTC();                     // Format date and time
    Display_RTC();                        // waiting for card reader. while waiting
     asm nop                                    // display shows actual time
    }

    while (cnt != 16) {                      // waiting 16 clocks on RB1 (positioning for sampling)

     asm nop                                  // waiting for 16 bit data after card reader being touched
    }

    cnt = 0;
    _data[0] = OUT & 1;

    for (data_index = 1; data_index != 0; data_index++) {                // getting 128 bits of data from RB0
      while (cnt != 32) {                                                          // getting bit from RB0 every 32 clocks on RB1
        asm nop
      }
      cnt = 0;                                                                 // reseting interrupt counter
      _data[data_index] = OUT & 1;                             // geting bit
      if(data_index & 1)
      if (!(_data[data_index] ^ _data[data_index-1]))
         {
            bad_synch = 1;
            break;                                                          //bad synchronisation
         }
    }

    INT2IE_bit = 0;                                                // disable external interrupt on RB1 (for sync and sample)
    if (bad_synch)
     continue;                                                               // try again
    cnt1 = 0;
    one_seq = 0;
    for(cnt1 = 0; cnt1 <= 127; cnt1++) {                     // we are counting 'logic one' in the data array
      if (_data[cnt1 << 1] == 1) {
        one_seq++;
        }
      else {
        one_seq = 0;
        }

      if (one_seq == 9) {                                           // if we get 9 'logic one' we break from the loop
          break;
    }
    }                                                                        //   (the position of the last  'logic one' is in the cnt1)
    if ((one_seq == 9) && (cnt1 < 73)) {                     // if we got 9 'logic one' before cnt1 position 73
                                                                                     //   we write that data into data_valid array
       data_valid[0] = 1;                                            //   (it has to be before cnt1 position 73 in order
       data_valid[1] = 1;                                               //    to have all 64 bits available in data array)
       data_valid[2] = 1;
       data_valid[3] = 1;
       data_valid[4] = 1;
       data_valid[5] = 1;
       data_valid[6] = 1;
       data_valid[7] = 1;
       data_valid[8] = 1;
       for(cnt2 = 9; cnt2 <= 63; cnt2++) {  // copying the rest of data from the data array into data_valid array
          cnt1++;
          data_valid[cnt2] = _data[cnt1 << 1];
        }
       if (CRC_Check(data_valid) == 1) {                 // if data in data_valid array pass the CRC check

            UART1_Write_Text("CRC CHECK OK!");            // Writing of the CRC Check confirmation through USART communication
             M = M + 1;
            UART1_Write(13);                                       // Cariage return (view ASCII chart)
            UART1_Write(10);                                        // Line Feed (view ASCII chart)
         
         
         
            for (i = 0; i <= 64; i++){                         // This part of the code
                   k = k + 1;                                      //  dislays the number of the specific RfID CARD
                if (data_valid[i] == 0) {
                  Uart1_Write('0');
                  }
                else {
                  Uart1_Write('1');                           // at the end of this for loop you will get a string of "0" and "1"
                  }
            }

    Lcd_Cmd(_LCD_CLEAR);                                 // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);                      // Cursor off
    Lcd_Out(1,6,"WAIT");                                       // wait for motion sensor timer
                                                                             //delay_ms (2000);
 
                                                                             // Clear display

          b = 0;  v = 0;
          for (v = 0; v < 8; v++) {                           // save code and time in memory
    for (i = 0; i < 8; i++){                                   // MMC not ready.
                                                                         // this part will be used to
        tmp = tmp ^ data_valid[i + 8*v]<<i;             // slot memory sub-routine
          }
          test[v] = tmp;
             // b = b + 1;
       
         TMR0IF_bit = 0;                                 // activate Timer interupt
         TMR0IE_bit = 1;
         INT3IE_bit = 1;
         INT3IF_bit= 0;                                    // activate motion sensor
         while (Save_Mem == 0) {                  // waiting signal from timer or motion
                                                                   // if student did not pass thru the motion sensor
         asm nop                                             // in 3 min the timer int is activated
    }
     Lcd_Cmd(_LCD_CLEAR);                   // clear display and restart the new card reader
     Save_Mem = 0;
        }

                                                                       // specific to a single RfID CARD
            UART1_Write(13);                           // Cariage return (view ASCII chart)
            UART1_Write(10);                           // Line Feed (view ASCII chart)
            Delay_ms(500);

        }
     }

   }
}


This is my complete program for my project that is student attendance system, but have to download to PIC 18F87k22 at controller hardware. PIC 18F87K22 is more faster when compile and download the program into PIC. After that, i will going to test the program and the hardware on week 10.


Thank you to read my blog here....

Remember read week 9 and 10, because have any difference....hahaha.....

Have a nice day.....