PR29 programming

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR29 programming

Postby Suria » Sat Dec 31, 2011 11:28 am

i would like to ask regarding the programming.

i understand that the programs given are pr29.c, pr29.hex,uart_io.c and uart_io.h. i understand that pr29.hex is the end product right? we just have to mount it to the pic right?

i made some changes to the pr29.c, how about the uart_io.c and uart_io.h? can i mount it to the pic at one time?

can you tell about the procedure on how to install the programming? cause i don't understand regarding the uart_io.c. your help is truly appreciated.

thanks.

[p/s: i'm just a newbie in programming :) ]
Suria
Novice
 
Posts: 24
Joined: Sat Dec 31, 2011 11:21 am

Re: PR29 programming

Postby ABSF » Sun Jan 01, 2012 5:59 pm

Suria WROTE:i understand that the programs given are pr29.c, pr29.hex,uart_io.c and uart_io.h. i understand that pr29.hex is the end product right? we just have to mount it to the pic right?


correct.
Suria WROTE:i made some changes to the pr29.c, how about the uart_io.c and uart_io.h? can i mount it to the pic at one time?

can you tell about the procedure on how to install the programming? cause i don't understand regarding the uart_io.c. your help is truly appreciated.


Once you have changed the pr29.c, you need to recompile the whole program again. The uart_io.c and uart_io.h are library files and need to be included during compilation under "source" and "header" folders. The newly produced .hex can be used to program your PIC mcu.

What do you mean by "install the programming"? You should be able to find the above procedures on internet under "pic tutorial" or some of the files inside the earlier PRxx projects in cytrom main site.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR29 programming

Postby Suria » Wed Jan 04, 2012 4:06 pm

thanks allen :)

another question.. what is the 0x00, 0x30 means in the programming? thanks :D
Suria
Novice
 
Posts: 24
Joined: Sat Dec 31, 2011 11:21 am

Re: PR29 programming

Postby ABSF » Wed Jan 04, 2012 5:08 pm

Suria WROTE:thanks allen :)

another question.. what is the 0x00, 0x30 means in the programming? thanks :D


That's how C represent Hex numbers. 0x30 means hexadecimal number 30 or 3*16+0= 48 decimal. 0b00110011 means binary number.

Some languages use H'0030' or 0030H or $0030. You should be able to find it in the first few chapters of the C Manual under "number conventions".

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR29 programming

Postby Suria » Fri Jan 06, 2012 4:36 pm

Once you have changed the pr29.c, you need to recompile the whole program again. The uart_io.c and uart_io.h are library files and need to be included during compilation under "source" and "header" folders. The newly produced .hex can be used to program your PIC mcu.


how to recompile the whole program? :shock:
Suria
Novice
 
Posts: 24
Joined: Sat Dec 31, 2011 11:21 am

Re: PR29 programming

Postby ober » Fri Jan 06, 2012 5:52 pm

Suria WROTE:how to recompile the whole program? :shock:


DIY project is meant for Do It Yourself project. You need to solder the component according to layout in Details Description, study the document and of course learn from it. There are plenty of step to follow :D Anyway, many have did it and I am sure you can do it.

To compile a C project, please refer to Open and Create Project for PIC16F, which you can find it under all related DIY product page, including PR25 and PR29 or simply refer to this youtube presentation:
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: PR29 programming

Postby Suria » Fri Jan 06, 2012 6:43 pm

what can i do if this occur?
Attachments
Untitled.png
Suria
Novice
 
Posts: 24
Joined: Sat Dec 31, 2011 11:21 am

Re: PR29 programming

Postby ABSF » Fri Jan 06, 2012 9:12 pm

PR29.JPG


You should get the same screen like mine. All the required files should be in their folders on the left corner.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR29 programming

Postby Suria » Fri Jan 06, 2012 9:49 pm

CODE: SELECT_ALL_CODE
#include<pic.h>
#include<htc.h>               /* to enable access to eeprom */
#include<uart_io.h>            /* to enable another programmed UART */

_config ( 0x3F32 );            /* configuration for the microcontroller */

/* defining LED */
#define LEDRED      RA0         /* red LED */
#define LEDYELLOW    RA1         /* yellow LED */

/* defining LCD Pins */
#define rs         RC4         /* RS pin of the LCD Display */
#define e         RC5         /* E Pin of the LCD Display */
#define lcd_data   PORT_B      /* LCD 8-bit data port */

/* defining Push Buttons */
#define button_1   RA2         /* Push Button 1 */
#define button_2   RA3         /* Push Button 2 */
#define button_3   RA4         /* Push Button 3 */

/* defining Buzzer */
#define Buzzer      RA5         /* Buzzer */

/* acknowledgement reply form module */
#define success      0x00      /* success */
#define fail         0x01      /* fail */
#define no_user      0x05      /* no user */
#define user_exist   0x07      /* user exist */
#define timeout      0x08      /* timeout */
#define access         0x03      /* access allowed */

void send_config(usigned char data);
void delay(usigned long data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clear(void);
void send_string(const char*s); /*check this line*/
void uart_send(unsigned char data);
void send_cmd(unsigned char CMD, usigned char P1, unsigned char P2, unsigned char P3);
unsigned char uart_receive(void); /*check?*/
void mode(unsigned char data);
void display_status(unsigned char type, unsigned char data0, unsigned char data);
void receive_reply(void);
void receive_reply_nodisplay(void);
void setting_repeat(void);
void check_admin(void);
void add_new(unsigned char data, unsigned char location);
void store_eeprom(unsigned char data, unsigned char location);
unsigned char get_eeprom(unsigned char loaction);
void view_attendance(void);
void initialize_attendance(void);
void clear_attendance (void);
void upload_hyperterminal(void);   /* to hyperterminal */
void upload_GUI(void);            /* to GUI */
void allign(void);
void reset_admin(void);

/* assign global variables */
bit mode_enter, location_enter, error, usertype_enter, admin, day_enter, GUI_control, export_select;
mode_enter = 0;
usertype_enter = 0;
day_enter = 0;
GUI_control = 0;
export_select = 0;

unsigned char location=1;
unsigned char day_count=1,day_location;
unsigned char array_resp[8];
unsigned char day=1;
unsigned char temp;
unsigned char mode_count=1;

void main(void)
{
   /* set I/O ports */
   /*configuring each port I/O direction */
   TRISA = 0b00011100;            /* port A */
   TRISB = 0b00000000;           /* port B */
   TRISC = 0b10000000;            /* port C */

   /* setting up ADC */
   ADCON1 = 0b10000110;            /* clear display at LCD */

   /* configuring LCD display */
   send_config(0b00000001);      /* clear display at LCD */
   send_config(0b00000010);      /* LCD return to the beginning */
   send_config(0b00000110);      /* entry mode-cursor increase 1 */
   send_config(0b00001100);      /* display on, cursor off and cursor blink off */
   send_config(0b00111000);      /* function set */

   Buzzer=0;
   LEDYELLOW=0;

   /**********************************/
   /* displaying startup message */
   lcd_clear();                  /* LCD clear */
   lcd_goto(0);                  /* the cursor goes to location 0 */
   send_string("Syenah Amal Daus");
   lcd_goto(20);
   send_string("Aisah ND2/11/CME");
   /*********************************/

   /* setting up USART */
   SPBRF = 0X40;                  /* set baud rate to 19200 for 20MHz Crystal */
   BRGH = 1;                     /* baud rate high speed option */
   TXEN = 1;                     /* enable transmission */
   CREN = 1;                     /* enable reception */
   SPEN = 1;                     /* enable serial port */

   /* Push button processors */
   /* resetting admin mode */
   if((!Button_1 && (!Button_2))         /* if Button 1 and Button 2 is pressed simultaneously */
   {
      delay(100000);
      if((!Button_1) && (!Button_2))   /* wait for release */
      {
         reset_admin();                  /* reset admin mode */
      }
   }

   /* configuring reader setting */
   send_cmd(0x2E,0x00,0x10,0x00);      /* configuring time out(0x10 means timeout after approx. 7s) */
   delay(10);
   receive_reply_nodisplay();            /* get reply from UART but do not display */
   send_cmd(0x2d,0x00,1,0x00);         /* send command to configure not allowed repeat */
   delay(10);
   receive_reply_nodisplay();            /* get reply from UART but do not display */

   /* initialize programmed UART */
   uart_init(1);

   /* initialize attendace */
   initialize_attendance();

while(1)
{
   while(usertype_enter==0)            /* usertype_enter flag not set */
   {
      lcd_goto(0);                     /* setting LCD cursor to location 0 */
      send_string("(1) Admin ");       /* display option 1: admin login  */
      lcd_goto(18);                     /* setting LCD cursor to location 0 */
      send_string("(2) User ");         /* display option 2: user login */
      if(!Button_1)
      {
         while(!Button_1)               /* wait for release */
         check_admin();                  /* verify process */
         if(error!=1)                  /* if no error return */
         {
         admin = 1;                     /* mark user as admin */
         usertype_enter = 1;            /* set usertype_enter flag and exit loop */
         }
      }
      else if (!Button_2)               /* user select user */
      {
         while(!Button_2)               /* wait for release */
         admin = 0;                     /* mark user as normal user */
         usertype_enter = 1;            /* set usertype_enter flag and exit loop */
      }
   }
lcd_clear();


while(mode_enter==0 && admin ==1 && usertype_enter==1)   /* loop if admin logging on, chosen user type and mode not selected */
{
   if ((!Button_1))                                      /* check whether SW1 is pressed */
   {
      while((!Button_1));                                 /* wait for release */
      if (mode_count<6);                                 /* if not reaching 5th mode */
      mode_count++;                                       /* mode increases */
      else
      mode_count=1;                                       /* reset back to 1st mode */
   }
   else if ((!Button_2))                                 /* check whether SW2 is pressed */
   {
      while((!Button_2));                                 /* wait for release */
      if (mode_count>1);                                 /* if not reaching 5th mode */
      mode_count--;                                       /* mode decreases */
      else
      mode_count=6;                                       /* reset back to 5th mode */
   }
   else if ((!Button_3))                                 /* check whether SW3 is pressed */
   {
      while(!Button_3))                                    /* wait for release */
      mode_enter=1;                                       /* set mode_enter flag indicates user has choosen a mode */
   }
   lcd_goto(0);                                          /* set the lcd cursor to location 0 */
   send_string("Mode=   ");                              /* display string */
   lcd_goto(5);                                          /* set the lcd cursor to location 5 */
   send_char(0x30+mode_count);                           /* display at location 6 (0x30 is ASCII code for 0) */
   lcd_goto(6);                                          /* set the lcd cursor to loacation 6 */
   send_string("/7");                                    /* display string */
   lcd_goto(20);                                          /* set the lcd cursor to location 20 */

   if(mode_count==1)
      send_string("Set Day");                              /* mode 1 */
   else if(mode_count==2)
      send_string("Add a New Data");                  /* mode 2 */
   else if(mode_count==3)
      send_string("Delete a data");                  /* mode 3 */
   else if(mode_count==4)
      send_string("View Attendance");            /* mode 4 */
   else if(mode_count==5)
      send_string("Clear Attendance");         /* mode 5 */
   else if(mode_count==6)
      send_string("Export");               /* mode 6 */

   while(mode_enter==0 && admin==0 && usertype_enter==1)   /* loop if normal user logging on, choesen user type and mode not selected */
   {
      while(1)                                             /* keep looping */
      {
      lcd_goto(0);                                       /* set the lcd cursor to location 0 */
      send_string("Today is Day");                        /* display string */
      lcd_goto(13);                                        /* set the lcd cursor to location 13 */
      day=get_eeprom(0xff);                              /* assign value(from eeprom location 0xff) to variable */
      send_char(0x30+day);                                 /* display character */
      lcd_goto(20);                                       /* set the lcd cursor to location 20 */
      send_string("Press 3 to mark");                     /* display string */

      if(!Button_3)                                       /* if Switch 3 is pressed */
      {
         while(!Button_3);                               /* wait for release */

         send_cmd(0x0c,0x00,0x00,0x00);                  /* send matching 1:N command */
         lcd_clear();                                    /* clearing screen */
         lcd_goto(0);                                    /* set the lcd cursor to location 0 */
         send_string("Place your thumb");                  /* display string */
         lcd_goto(20);
         send_string("on the module");
         delay(100);
         receive_reply();

         if(!error)
         {
            if(day==1)
            {
               day_location==0x00;                              /* location to store day1 data */
               store_eeprom(0x2f,day_location+3+array_resp[3])   /* get which user and mark at appropriate space */
               delay(100);
            }
            else if(day==2)
                  {
                     day_location=0x10;                              /* location to store day2 data */
                     store_eeprom(0x2f,day_location+3+array_resp[3])   /* get which user and mark at appropriate space */
                     delay(100);
                  }
            else if(day==3)
                  {
                     day_location=0x20;                              /* location to store day3 data */
                     store_eeprom(0x2f,day_location+3+array_resp[3])   /* get which user and mark at appropriate space */
                     delay(100);
                  }
            else if(day==4)
                  {
                     day_location=0x30;                              /* location to store day4 data */
                     store_eeprom(0x2f,day_location+3+array_resp[3])   /* get which user and mark at appropriate space */
                     delay(100);
                   }
            else if(day==5)
                  {
                     day_location=0x40;                              /* location to store day5 data */
                     store_eeprom(0x2f,day_location+3+array_resp[3])   /* get which user and mark at appropriate space */
                     delay(100);
                  }
         }
      }
      }
   }
   lcd_clear();
   mode(mode_count);                  /* function call for mode selected */
   delay(10);

   }

   }

   /* End of main function */

   /* _______________FUNCTIONS_______________________*/

   /* function to configure LCD display */
   void send_config(unsigned char data)      /* send lcd configuration */
   {
      rs=0;                                    /* set lcd to configuration mode */
      lcd_data=data;                           /* lcd data port = data */
      e=1;                                    /* pulse e to confirm the data */
      delay(50);
      e=0;
      delay(50);
   }

   /* delay function */
   void delay(unsigned long data)            /* delay function, the delay time */
   {
      for(;data>;data--);                     /* depends on the given value */
   }

   /* function to send character to lcd display */
   void send_char(unsigned char data)         /* send lcd character */
   {
      rs=1;                                    /* set lcd to display mode */
      lcd_data=data;                           /* lcd data port = data */
      e=1;                                    /* pulse e to confirm the data */
      delay(10);
      e=0;
      delay(10);
   }

   /* function to set lcd cursor to desired location */
   void lcd_goto(unsigned char data)         /* set the location of the lcd cursor */
   {                                         /* if the given value is (0 to 15) the */
      if(data<16)                              /* cursor will be at the upper line */
      {                                        /* if the given value is (20 to 35) the */
         send_config(0x80+data);               /* cursor will be at the lower line */
      }                                      /* location of the lcd cursor(2x16) */
      else
      {
         data=data-20;
         send_config(0xc)+data);
      }
   }

   /* function to clear LCD display */
   void lcd_clear(void)
   {
      send_config(0x01);
      delay(600);
   }

   /* function to send string to LCD display */
   void send_config(const char*s)            /* send a string to display in the lcd */
   {
      unsigned char i=0;
      while (s && *s)send_char(*s++);
   }

   /* function to transmit data by data to target device */
   void uart_send(unsigned char data)         /* transmit data through USART */
   {
      while(TXIF==0);                        /* only send the new data after */
      TXREG=data;                              /* the previous data finish sent */
   }

   /* function to send command */
   void send_cmd(unsigned char CMD, unsigned char P1, unsigned char P2, unsigned char P3)   /* send command to fingerprint module */
   {
      unsigned char CHK;
      CHK = CMD^P1^P2^P3^0X00;               /* calculate CHK(XOR CMD,P1,P2,P3,0) */
      uart_send(0xF5);                        /* send first byte */
      uart_send(CMD);                        /* send CMD */
      uart_send(P1);                           /* send P1 */
      uart_send(P2);                             /* send P2 */
      uart_send(P3);                           /* send P3 */
      uart_send(0x00);                        /* send 0 */
      uart_send(CHK);                        /* send CHK */
      uart_send(0xF5);                        /* send 0xF5 */
   }

   /* function to receive data from uart buffer */
   unsigned char uart_receive(void)            /* receive data through USART */
   {
      unsigned char rec_data;
      while(RDIF==0);                        /* wait for data */
      rec_data=RCREG;
      return rec_data;                         /* return received data */
   }

   /* modes operation */
   {
      if(data==1)                              /* mode 1 = set day mode */
      {
         while(day_enter)                     /* entering loop while day_enter is not set */
         {
            if(!Button_1)                     /* check whether SW1 is pressed */
            {
               while(!Button_1)               /* wait for release */
               if(day_count<5)               /* if day not reaching 5 */
                  day_count++;               /* increase */
               else
                  day_count=1;               /* reset back to 1 */
            }
            else if(!Button_2)                  /* check whether SW2 is pressed */
            {
               while(!Button_2)               /* wait for release */
               if(day_count>1)               /* if mode not reaching 1 */
                  day_count--;               /* decrease */
               else
                  day_count=5;               /* reset back to 5 */
            }
            else if(!Button_3)                  /* check whether SW3 is pressed */
            {
               lcd_clear();                  /* clearing LCD */
               LEDYELLOW=1;                  /* yellow LED ON */
               while(!Button_3)               /* wait for release */
               if(day_count==1)                     /* day 1 */
                  {
                     store_eeprom(day_count,0xff);   /*store at location 0xff in eeprom */
                  {
               else if(day_count==2)                 /* day 2 */
                  {
                     store_eeprom(day_count,0xff);   /* store at location 0xff in eeprom */
                  }
               else if(day_count==3)                    /* day 3 */
                  {
                     store_eeprom(day_count,0xff);   /* store at location 0xff in eeprom */
                  }
               else if(day_count==4)                    /* day 4 */
                  {
                     store_eeprom(day_count,0xff);   /* store at location 0xff in eeprom */
                  }
               else if(day_count==5)                    /* day 5 */
                  {
                     store_eeprom(day_count,0xff);   /* store at location 0xff in eeprom */
                  }
               lcd_goto(0);
               send_string("Day");
               lcd_goto(4);
               send_char(0x30+day_count);
               lcd_goto(20);
               send_string("Selected");
               delay(200000);
               LEDYELLOW=0;
               day_enter=1;
            }
               lcd_goto(0);
               send_string("Today is Day");
               lcd_goto(13);
               send_char(0x30+day_count);
               lcd_goto(14);
               send_string("/5");
               lcd_goto(20);
               send_string("Press 3 to set");
         }
            day_enter=0;
         }
         else if(data==2)                           /* mode 2: adding new data */
         {
            delay(10000);

            while(location_enter==0)
            {
               lcd_goto(0);
               send_string("Choose a user");
               lcd_goto(20);
               send_string("User");
               lcd_goto(25);
               send_char(0x30+location);            /* display character (numerical digit which started from 0x30 or zero) */

               if(!Button_1)
                  {
                     while(!Button_1)
                     if(location<5)
                        location++;
                     else
                        location=1;
                  }
               else if(!Button_2)
                  {
                     while(!Button_2)
                     if(location>1)
                        location--;
                     else
                        location=5;
                  }
               else if(!Button_3)
                  {
                     while(!Button_3)
                     add_new(location);            /* function call for add new fingerprint into database at desired location */
                  }
            }
         }
         else if(data==3)
         {
            delay(10000);

            while(location_enter==0)
            {
               lcd_goto(0);
               send_string("Choose User");
               lcd_goto(20);
               send_string("User");
               lcd_goto(25);
               send_char(0x30+location);
               if(!Button_1)
                  {
                     while(!Button_1)
                     if(location<5)
                        location++;
                     else
                        location=1;
                  }
               else if(!Button_2)
                  {
                     while(!Button_2)
                     if(location>1)
                        location--;
                     else
                        location=1;
                  }
               else if(!Button_3)
                  {
                     while(!Button_3)
                     send_cmd(0x04,0x00,location,0x03);   /* send delete data command */
                     delay(10);
                     receive_reply();
                     location_enter=1;
                  }
            }
         }
         else if(data==4)         /* mode 4 : view attendance */
         {
            view_attendance();
         }
         else if(data==5)
         {
            LEDYELLOW=1;
            clear_attendance();
            lcd_goto(0);
            send_string("Attendance");
            lcd_goto(20);
            send_string("Cleared");
            delay(200000);
            LEDYELLOW=0;
         }
         else if(data==6)
         {
            while(export_select==0)
            {
            lcd_goto(0);
            send_string("1.Export to GUI");
            lcd_goto(20);
            send_string("2.Export to HT");
            if(!Button_1)
            {
               while(!Button_1)
               lcd_clear();
               lcd_goto(0);
               send_string("Uploading...");
               LEDRED=1;
               delay(150000);
               upload_GUI;
               lcd_goto(20);
               send_string("Done!");
               delay(100000);
               LEDRED=0;
               export_select=1;         /* exitting loop */
            }
            if(!Button_2);
            {
               while(!Button_2)
               lcd_clear();
               lcd_goto(0);
               send_string("Uploading...");
               LEDRED=1;
               delay(150000);
               upload_hyperterminal();
               lcd_goto(20);
               send_string("Done");
               delay(100000);
               LEDRED=0;
               export_select=1;
            }
         }
         export_select=0;
      }
   mode_enter=0;
   location_enter=0;
   error=0;
   }

   /* function to display the status of reply */
   void display_status(unsigned char type, unsigned char data0, unsigned char data)      /* show the status of the reply */
   {
      lcd_clear();
      switch(data)
      {
         case success      LEDYELLOW=1;
                           if((type!=1) && (type!=2))
                           {
                              lcd_goto(20);
                              send_string("Successful")
                           }
                           else if(type==1)
                           {
                              lcd_goto(0);
                              send_string("Scanning...");
                              lcd_goto(20);
                              send_string("Verification 2/2");
                           }
                           delay(200000);
                           LEDYELLOW=0;
                           error=0;
                           lcd_clear();
                           break;

         case fail         LEDRED=1;
                           Buzzer=1;
                           lcd_goto(20);
                           send_string("Failed");
                           delay(200000);
                           Buzzer=0;
                           LEDRED=0;
                           error=1;
                           lcd_clear();
                           break;

         case timeout      LEDRED=1;
                           Buzzer=1;
                           lcd_goto(20);
                           send_string("Timeout");
                           delay(200000);
                           Buzzer=0;
                           LEDRED=0;
                           error=1;
                           lcd_clear();
                           break;

         case user_exist   LEDRED=1;
                           Buzzer=1;
                           lcd_goto(20);
                           send_string("User Exist");
                           delay(200000);
                           Buzzer=0;
                           LEDRED=0;
                           error=1;
                           lcd_clear();
                           break;

         case no_user      LEDRED=1;
                           Buzzer=1;
                           lcd_goto(20);
                           send_string("Access Denied");
                           delay(200000);
                           Buzzer=0;
                           LEDRED=0;
                           error=1;
                           lcd_clear();
                           break;

         case access         LEDYELLOW=1;
                           if(data0!=0xff)
                           {
                              lcd_goto(0);
                              send_string("Hello User");
                              lcd_goto(11);
                              send_char(0x30 + data0);

                              lcd_goto(20);
                              send_string("Welcome");
                              error=0;
                           {
                           else
                           {
                              lcd_goto(0);
                              send_string("Hello Admin");
                           }

                           delay(200000);
                           LEDYELLOW=0;
                           lcd_clear();
                           break;

         default            LEDRED=1;
                           LEDYELLOW=1;
                           Buzzer=1;
                           lcd_goto(20);
                           send_string("Error");
                           delay(200000);
                           Buzzer=0;
                           LEDRED=0;
                           LEDYELLOW=0;
                           error=1;
                           lcd_clear();
                           break;

   /* function to get reply from UART */
   void receive_reply(void)
   {
      unsigned char i;
      for(i=0;i<8;i++)
      array_resp[i]=uart_receive();
      display_status(array_resp[1],array_resp[3],array_resp[4]);
      delay(1000);
   }

   /* function to get reply from UART but not display the status */
   void receive_reply_nodisplay(void)
   {
      unsigned char i;
      for(i=0;i<8;i++)
      array_resp[i]=uart_receive();
   }

   /* function to verify admin */
   void check_admin
   {
      send_cmd(0x0b,0x00,0xff,0x00);
      lcd_goto(0);
      send_string("Place your thumb");
      lcd_goto(20);
      send_string("on the module");
      delay(100);
      receive_reply();
   }

   /* adding new fingerprint into database */
   void add_new(unsigned char data)
   {
      send_cmd(0x01,0x00,data,0x03);
      lcd_goto(0);
      send_string("Place your thumb");
      lcd_goto(20);
      send_string("on the module");
      delay(5000);
      receive_reply();
      location_enter=1;
      if(!error)
      {
         lcd_clear();
         lcd_goto(0);
         send_string("Scanning...");
         lcd_goto(20);
         send_string("Verification 1/2");
         send_cmd(0x02,0x00,data,0x03);
         receive_reply();
            if(!error)
            {
               lcd_clear();
               lcd_goto(0);
               send_string("Scanning...");
               lcd_goto(20);
               send_string("Verification 2/2");
               send_cmd(0x03,0x00,data,0x03);
               receive_reply();
            }
      }
   }

   /* store data into specified location in EEPROM */
   void store_eeprom(unsigned char data, unsigned char location)
   {
      EEPROM_WRITE(location,data);
      while(WR)
      continue;
   }

   /* access EEPROM to retrieve data */
   {
      unsigned char value;
      value=EEPROM_READ(location);
      return value;
   }

   /* function to display attendance */
   void view_attendance(void)
   {
      lcd_clear();
      lcd_goto(0);
      send_string("User 1 2 3 4 5");
      lcd_goto(20);
      unsigned char x;
      for(x=0;x<4;x++)
      {
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      for(x=4;x<9;x++)
      {
         send_char(0x20);
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      delay(300000);
      lcd_goto(20);
      for(x=16;x<20;x++)
      {
         TEMP=get_eepromm(x);
         send_char(TEMP);
      }
      for(x=20;x<25;x++)
      {
         send_char(0x20);
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      delay(300000);
      lcd_goto(20);
      for =(x=32;x<36;x++)
      {
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      for(x=36;x<41;x++)
      {
         send_char(0x20);
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      delay(300000);
      lcd_goto(20);
      for(x=48;x<52;x++)
      {
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      for(x=52;x<57;x++)
      {
         send_char(0x20);
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      delay(300000);
      lcd_goto(20);
      for(x=64;x<73;x++)
      {
            TEMP=get_eeprom(x);
            send_char(TEMP);
      }
      for(x=68;x<73;x++)
      {
         send_char(0x20);
         TEMP=get_eeprom(x);
         send_char(TEMP);
      }
      delay(300000);
   }

   /* initialize attendance list */
   void initialize_attendance(void)
   {
      day_location=0x00l
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
      store_eeprom('Y',day_location+2);
      store_eeprom('1',day_location+3);

      day_location=0x10;
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
      store_eeprom('Y',day_location+2);
      store_eeprom('2',day_location+3);

      day_location=0x20;
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
      store_eeprom('Y',day_location+2);
      store_eeprom('3',day_location+3);

      day_location=0x30;
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
      store_eeprom('Y',day_location+2);
      store_eeprom('4',day_location+3);

      day_location=0x40;
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
      store_eeprom('Y',day_location+2);
      store_eeprom('5',day_location+3);
   }

   /* clear attendance marking and reset to default */
   void clear_attendance(void)
   {
      day_location=0x00;
      store_eeprom('D',day_location);
      store_eeprom('A',day_location+1);
               store_eeprom('Y',day_location+2);
               store_eeprom('1',day_location+3);
               store_eeprom(0xff,day_location+4);
               store_eeprom(0xff,day_location+5);
               store_eeprom(0xff,day_location+6);
               store_eeprom(0xff,day_location+7);
               store_eeprom(0xff,day_location+8);

               day_location=0x10;
               store_eeprom('D',day_location);
               store_eeprom('A',day_location+1);
               store_eeprom('Y',day_location+2);
               store_eeprom('2',day_location+3);
               store_eeprom(0xff,day_location+4);
               store_eeprom(0xff,day_location+5);
               store_eeprom(0xff,day_location+6);
               store_eeprom(0xff,day_location+7);
               store_eeprom(0xff,day_location+8);

               day_location=0x20;
               store_eeprom('D',day_location);
               store_eeprom('A',day_location+1);
               store_eeprom('Y',day_location+2);
               store_eeprom('3',day_location+3);
               store_eeprom(0xff,day_location+4);
               store_eeprom(0xff,day_location+5);
               store_eeprom(0xff,day_location+6);
               store_eeprom(0xff,day_location+7);
               store_eeprom(0xff,day_location+8);

               day_location=0x30;
               store_eeprom('D',day_location);
               store_eeprom('A',day_location+1);
               store_eeprom('Y',day_location+2);
               store_eeprom('4',day_location+3);
               store_eeprom(0xff,day_location+4);
               store_eeprom(0xff,day_location+5);
               store_eeprom(0xff,day_location+6);
               store_eeprom(0xff,day_location+7);
               store_eeprom(0xff,day_location+8);

               day_location=0x40;
               store_eeprom('D',day_location);
               store_eeprom('A',day_location+1);
               store_eeprom('Y',day_location+2);
               store_eeprom('5',day_location+3);
               store_eeprom(0xff,day_location+4);
               store_eeprom(0xff,day_location+5);
               store_eeprom(0xff,day_location+6);
               store_eeprom(0xff,day_location+7);
               store_eeprom(0xff,day_location+8);
   }

   /* function to upload attendance to Hyper Terminal */
   void upload_HT(void)
   {
      unsigned char address;
      unsigned char count;
      unsigned char array_title[40]= {"+-+-+- Attendance List -+-+- MKJB"};   /* display string */

      for(count=0;count<40;count++)         /* loop for 40 times */
      uart_write(2,array_title[count]);   /* write to programmed uart */
      for(count=0;count<20;count++)         /* loop for 20 times */
      {
         uart_write(2,'+');               /* write '+' */
         uart_write(2,'-');               /* write '-' */
      }

      for(count=0;count<80;count++)         /* loop for 80 times */
      uart_write(2,' ');                  /* write to programmed uart */
      uart_write(2,'U');                  /* write to programmed uart */
      uart_write(2,'s');                  /* write to programmed uart */
      uart_write(2,'e');                  /* write to programmed uart */
      uart_write(2,'r');                  /* write to programmed uart */

      for(count=1;count<6;count++)         /* loop for 5 times */
      {
         uart_write(2,' ');               /* write ' ' */
         uart_write(2,0x30+count);         /* write user id 1 to 5 */
      }
      allign();                           /* function making allignment */

      address=0x00;                           /* set address for day1 */
      count=address;                           /* assign value in address to count */
      for(address;count<=address+3;count++)   /* DAY1 0x00->0x03 */
      {
         TEMP=get_eeprom(count);               /* get "D","A","Y","1" */
         uart_write(2,TEMP);                  /* write to programmmed uart */
      }
      address=count;                           /* assign value in count to address */
      for(count;count<=address+4;count++)      /* loop 5 times to get marking */
      {
         TEMP=get_eeprom(count);               /* get marking */
      uart_write(2,' ');                     /* write to programmed uart */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
      }
      allign();                              /* function making allignment */

      address=0x10;                           /* set address for day2 */
      count=address;                           /* assign value in address to count */
      for(count;count<=address+3;count++)      /* DAY2 0x10->0x13 */
      {
         TEMP=get_eeprom(count);               /* get "D","A","Y","2" */
         uart_write(2,TEMP);                  /* write to programmmed uart */
      }
      address=count;                           /* assign value in count to address */
      for(count;count<=address+4;count++)      /* loop 5 times to get marking */
      {
         TEMP=get_eeprom(count);               /* get marking */
         uart_write(2,' ');                  /* write to programmed uart */
         if(TEMP==0xff)   TEMP=0x30;            /* if 0xff (no marking) replace with 0x30( zero ) */
         uart_write(2,TEMP);                  /* write to programmed uart */
      }
      allign();                              /* function making allignment */

      address=0x20;                           /* set address for day3 */
      count=address;                           /* assign value in address to count */
      for(count;count<=address+3;count++)      /* DAY3 0x20->0x23 */
      {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","3" */
      uart_write(2,TEMP);                     /* write to programmmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      uart_write(2,' ');                     /* write to programmed uart */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   allign();                                 /* function making allignment */

   address=0x30;                              /* set address for day4 */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY4 0x30->0x33 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","4" */
      uart_write(2,TEMP);                     /* write to programmmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      uart_write(2,' ');                     /* write to programmed uart */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   allign();                                 /* function making allignment */

   address=0x40;                              /* set address for day5 */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY5 0x40->0x43 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","5" */
      uart_write(2,TEMP);                     /* write to programmmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      uart_write(2,0xff);                     /* write to programmed uart */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   allign();                                 /* function making allignment */
   for(count=0;count<80;count++)               /* loop 80 times */
   uart_write(2,' ');                        /* to blank a line */
   for(count=0;count<40;count++)               /* loop 40 times */
   {
      uart_write(2,'+');                     /* write to programmed uart */
      uart_write(2,'-');                     /* write to programmed uart */

   }
}

//function to upload attendance to GUI
void upload_GUI(void)
{
   unsigned char address;
   unsigned char count;

   address=0x00;                              /* day1 location */
   count=address;                              /* assign value in address to count */
   for(address;count<=address+3;count++)      /* DAY1 0x00->0x03 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","1" */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }

   address=0x10;                              /* day2 location */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY2 0x10->0x13 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","2" */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }

   address=0x20;                              /* day3 location */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY3 0x20->0x23 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","3" */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }

   address=0x30;                              /* day4 location */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY4 0x30->0x33 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","4" */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }

   address=0x40;                              /* day5 location */
   count=address;                              /* assign value in address to count */
   for(count;count<=address+3;count++)         /* DAY5 0x40->0x43 */
   {
      TEMP=get_eeprom(count);                  /* get "D","A","Y","5" */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }
   address=count;                              /* assign value in count to address */
   for(count;count<=address+4;count++)         /* loop 5 times to get marking */
   {
      TEMP=get_eeprom(count);                  /* get marking */
      if(TEMP==0xff)   TEMP=0x30;               /* if 0xff (no marking) replace with 0x30( zero ) */
      uart_write(2,TEMP);                     /* write to programmed uart */
   }

}

//function to allign the text in Hyper Terminal
void allign(void)
{
   unsigned char Allign;
   for(Allign=0;Allign<66;Allign++)            /* loop */
   uart_write(2,' ');                        /* write ' ' to programmed uart */
}

//function to reset and re-assign admin
void ResetAdmin(void)
{
   lcd_goto(0);                              /* set the lcd cursor to location 0 */
   send_string("Resetting Admin...");         /* display string */
   delay(200000);
   send_cmd(0x04,0x00,0xFF,0x00);            /* command to delete formal admin */
   receive_reply();                           /* get reply from uart */
   lcd_goto(0);                              /* set the lcd cursor to location 0 */
   send_string("New Admin Needed");            /* display string */
   delay(200000);
   do{
      lcd_goto(0);                           /* set the lcd cursor to location 0 */
      send_string("New Admin       ");         /* display string */
      lcd_goto(20);                           /* set the lcd cursor to location 20 */
      send_string("Standby");                  /* display string */
      delay(200000);
      add_new(0xff);                           /* add new admin */
     }   while(error==1)   ;                  /* repeat if new admin not added successfully */
}


this is my new code.. do u think it's over-coded?
Suria
Novice
 
Posts: 24
Joined: Sat Dec 31, 2011 11:21 am

Re: PR29 programming

Postby ABSF » Fri Jan 06, 2012 10:18 pm

I dont know, why dont you try it out yourself?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Next

Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 10 guests

cron