Friday 14 March 2014

EDIT THE SOFTWARE

WEEK 6

As for the develoment of this project, this project will depends on program that I compile. By using PIC Compiler software, I construct the program and there were a lot of mistakes also more things to learn to do the program. To complete and perfecting the program, I do lot a lot of research and ask my friend to teach me. Finally i have done the software.


#include <16f877A.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N)
#fuses hs,noprotect,nowdt,nolvp

#byte PORTD=6
#byte PORTC=7

byte count;

int buffer[3];
int i;

void detect_card();
void event();

void main()
{
   set_tris_d(0);
   set_tris_c(0b10000011);
   count=0;

   output_low(PIN_C2);
   delay_ms(1000);
   output_high(PIN_C2);

   output_low(pin_b0);
   output_LOW(pin_b1);

   buffer[0]=0;
   buffer[1]=0;
   buffer[2]=0;

   do
   {   detect_card();


       printf("Hex: %X%X%X  ",buffer[2],buffer[1],buffer[0]);
       if(buffer[2]==0x7E&& buffer[1]==0x0D && buffer[0]==0x76)
       {

       output_high(pin_D0);

       delay_ms(5000);
       output_low(pin_D0);



       }

       else
       {

         output_low(pin_D0);

       }

   }while(1);
}

void detect_card()
{
      for(i=0; i<26;i++)
      {       while(input(PIN_C0)==1 && input(PIN_C1)==1);
               if(input(PIN_C0)==0 )
               {       if(i!=0 && i != 25)
                        {    shift_left(buffer,3,0); }
               }
               if(input(PIN_C1)==0)
               {        if(i!=0 && i != 25)
                        {shift_left(buffer,3,1); }
               }
               delay_us(500);
      }
}

B0= output relay to start motor run, B1= output relay to buzer that shows wrong card
When touch card for one time, b0 will count 1, b0 will high
When touch card for two times, b0 will count 2, b0 will low
When another touch card will identified, b1 will high for 5 seconds and then will be low


No comments:

Post a Comment