Electronic Queuing System

Electronic Queuing System

The idea of this electronic queuing system is to display both sequence number and counter number in three seven segment displays. For example, when counter 1 presses his button, the number 1 shows up on the counter number segment. At the same time, the sequence number is incremented. This system can cater up to 99 customers and up to four counters.

Introduction



This electronic queuing system uses the PIC16F877A as the microcontroller with four buttons, one 2-digit common cathode 7-segment display and one 1-digit common cathode 7-segment display. The project itself is not that hard and I would recommend it if you're new to PIC microcontrollers. However, I suggest you learn more about interrupt programming to understand how the code works.

Materials Needed

  • PIC16F877A
  • Dual Seven-segment Display - Common Cathode
  • Single Seven-segment Display - Common Cathode
  • 74LS48 IC
  • 5 x SPST Pushbutton
  • 5 x 10k ohm, 1/4 W Resistors
  • 4 MHz Crystal
  • 2 x 22p Ceramic Capacitor

Schematic Diagram

Electronic Queuing System schematic diagram

[the_ad id="3059"]

One 2-digit common cathode 7-segment display is used to count the customer number while 1 7-segment display is used to indicate the current counter. To prevent debounce on the button, I added some delays after each button press. You may need to push the button for about half a second to update the displays

Code

/*
 * File:   e_queue.c
 * Author: Roland
 * XC8 Code for Electronic Queuing System
 * Published on Teach Me Microcontrollers!
 * Created on April 13, 2018, 3:36 PM
 */

#define _XTAL_FREQ 4000000
#include <xc.h>

int count_ones;
int count_tens;
int count_val;
int counter_no;
int shifter = 0;
int dummy;

void main(void) {
    TRISB = 0b11111000;
    TRISC = 0;
    TRISD = 0;
    OPTION_REG = 0b00000100;
    INTCON = 0b10101000;
    PORTB = 0;
    PORTD = 0;
    
    while(1){;}
    
    return;
}

void updateValue(void){
     count_val++;
     count_tens = count_val/10;
     count_ones = count_val - 10*count_tens;
}
void interrupt isr(void){
    if(RBIF){
        __delay_ms(200);
       
   
        dummy = PORTB;   
        if(RB4==0){
            __delay_ms(200);
           // if(RB4==0){
                counter_no = 1;
                updateValue();
           // }
        }
        if(RB5==0){
            __delay_ms(200);
           // if(RB5==0){
             counter_no = 2;
             updateValue();
           // }
        }
        if(RB6==0){
            __delay_ms(200);
           // if(RB6==0){
             counter_no = 3;
             updateValue();
           // }
        }
        if(RB7==0){
            __delay_ms(200);
           // if(RB7==0){
             counter_no = 4;
             updateValue();
           // }
        }
        RBIF = 0;   //manual clearing of interrupt flag
    }
    
     if(TMR0IF){
            //switch digits for every interrupt. Read about POV for better understanding
            shifter++;        
            switch(shifter){
                case 1:
                    PORTC = 0b11111011;
                    PORTD = counter_no;
                    break;
                case 2:
                    PORTC = 0b11111101;
                    PORTD = count_ones;
                    break;
                case 3:
                    PORTC = 0b11111110;
                    PORTD = count_tens;
                    break;
                case 4:
                    shifter = 0;
                    break;
            }
            TMR0IF = 0;     //manual clearing of interrupt flag
    }
}

The buttons are attached to RB4 to RB7 so that I can use RB change interrupt. The POV shifting on the displays is done through timer overflow interrupt. You might need to change the prescale value via the OPTION register if you can still see the shifting between digits.

[the_ad id="3059"]

In XC8, multiple interrupts can be implemented by simply checking the corresponding interrupt flag bit. Here I checked the RBIF flag to check if the buttons RB4 to RB7 were pressed and the TMR0IF flag for shifting the digits in POV.

Design Files

Feel free to download the design files for this electronic queuing system project:

[wpdm_package id='2042']

If this was useful to you, a simple thanks through the comments would suffice!

Leave a Reply

Your email address will not be published. Required fields are marked *