Vending machine system design based on AT89C51 microcontroller (with simulation + C program + schematic diagram + paper, etc.)

Note: For the full set of designs, see the note at the end of the article…

Overview
This paper designs a vending machine system with AT89C51 microcontroller as the core, and introduces the overall system design scheme, hardware selection basis, software usage methods and skills of the vending machine in detail. Use AT89C51 as the CPU processing unit to connect each function module; use the 4×4 matrix keyboard as the input control module to select the type and quantity of goods and simulate the input function of currency; use LCD1602 liquid crystal as the display module to display the current shopping status and currency Status: The status of the currently selected goods and shipments is represented by the LED display.
insert image description here
The principle of vending machine
In the initial interface, wait for the customer to press the button to select the type and quantity of the goods. The customer puts in the currency, presses the confirm purchase button and waits for the vending machine to automatically calculate the total price of the purchased goods, and then prompts the customer to put in the currency. The invested currency is accumulated and counted after being detected by an external hardware detection sensor. If the customer confirms the purchase system, it will jump to the next step; otherwise, if the purchase is canceled, the currency will be withdrawn and returned to the main interface, waiting for the customer to operate the next step. The vending machine uses the difference between the total price of the currency and the total price of the purchased goods to make changes for shipment.
insert image description here
The control subsystem of the vending machine consists of the following parts, namely the preset vending system, the amount accumulation and change system, the sold out detection system, the sold accumulation and the feedback function system. (For a detailed introduction of each subsystem, please refer to the paper)

Overview of vending machine functions The
system selects the type and quantity of goods through the matrix keyboard, and the vending machine prompts for coins. The currency identifier of the vending machine recognizes the invested currency, and then displays the commodity selection right to the customer through the LCD liquid crystal according to the amount of money. After the customer presses the button to select, the CPU control chip sends an instruction to deliver the selected commodity from the reserve material channel. Material mouth.

There are 8 kinds of goods in total. These 8 kinds of commodities are selected and confirmed by the selection button, and the purchase quantity is determined by the quantity selection button. The price is specified as 1-8 yuan; 5 yuan banknotes, 10 yuan banknotes, 20 yuan banknotes, 50 yuan banknotes and 100 yuan banknotes. In the specified time, after the currency is invested several times, the currency can realize the automatic accumulation function, so that the design will transmit the data of the total amount of the invested currency to the central control component for processing; after the specified time, the coin slot will be automatically closed, The data processing unit performs addition and subtraction operations according to the product of the total number of coins and the purchased quantity and price, so as to realize the functions of purchasing and finding coins. When the total amount of money invested is less than the total amount of goods, the purchase cannot be made, and all the money invested will be refunded.

There are a total of 16 key selections in this design, two of which are cargo selection keys, two are quantity selection keys, and there are 6 currency input keys, 1 confirmation key and 1 cancel key.

System Simulation Circuit Diagram
insert image description here
insert image description here
Schematic

Simulation results analysis
(1) Load the Sale.hex file into the AT89C51 single-chip microcomputer, click to run, the vending machine system enters the initialization waiting state, the LCD displays "Welcome Sale", and waits for key input.
insert image description here
(2) Select the type of goods by pressing the buttons "Price+" and "Price-", and then select the quantity of the purchased goods by pressing "Quantity+" and "Quantity-", and the LED indicator representing the selected goods is on at the same time.
insert image description here
insert image description here
(3) After selecting the goods, press the "OK" button to enter the coin-operated system, and the machine will automatically calculate the total amount of the purchased goods.
insert image description here
(4) When the machine calculates the total price and waits for the customer to input the currency and press the "OK" button, when the currency value of the input currency is greater than or equal to the total price, it will be shipped and changed, and if the currency value of the input currency is less than the total price, then If you can't ship, you can only press "Cancel NO" to withdraw the invested coins or continue to add coins.
insert image description here
insert image description here
(5) When the above steps are completed, an automatic shopping process is completed, and the machine automatically resets back to the initialization interface. At the same time, at any stage of the operation process, you can press the "Cancel NO" button to reset the vending machine system to initial state.

Part of the C code


```c
#include<reg51.h>
#define WAIT_SALE        0            
#define NO_WATER         1                 
#define INPUT_MONEY        2 
#define SALING                3
#define CHANGE                4
#define CANCLE                5
#define NO_DATA                0
#define water_change(x, y) ((x) & (~(0x01 << y)))
#define uint unsigned int
#define uchar unsigned char

unsigned char water_total[] = {10, 10, 10, 10, 10, 10, 10, 10};   
unsigned char water_price[] = {1, 2, 3, 4, 5, 6, 7, 8};
uchar code wait_sale[]=" Welcome Sale ";    //定义所显示的内容
uchar code no_water[] = "No Water!";
uchar code price[] = "Price:";
uchar code number[] = "Num:";
uchar code sum[] = "SUM:";
uchar code input[] = "INPUT:";
uchar code change[] = "Change:";
uchar code put_water[] = "Get Water...";
uchar code cancle[] = "Cancle...";

unsigned char e=0x00;                    
sbit P2_0=P2^0;                       //定义接端口
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
sbit lcd_en=P3^4;             
sbit rs=P3^2;
sbit rw = P3^3;

void lcd_1602_delay(uint z)          //延时
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void lcd_1602_write_com(uchar com)   //写命令
{
rs=0;
rw=0;
P2=com;
lcd_1602_delay(5);
lcd_en=1;
lcd_1602_delay(5);
lcd_en=0;
}

void lcd_1602_write_data(uchar date) //写数据
{
rs=1;
rw=0;
P2=date;
lcd_1602_delay(5);
lcd_en=1;
lcd_1602_delay(5);
lcd_en=0;
}

void lcd_1602_init()               //LCD1602初始化函数
{
lcd_en=0;
lcd_1602_write_com(0x38);
lcd_1602_write_com(0x06);
lcd_1602_write_com(0x01);
}

void lcd_1602_wait_sure()         //显示'OK'&'NO'界面
{
lcd_1602_write_com(0x80+0x40);
lcd_1602_write_data('O');
lcd_1602_write_data('K');
                
lcd_1602_write_com(0x80+0x4e);
lcd_1602_write_data('N');
lcd_1602_write_data('O');
}

void lcd_1602_show_num(uint num)       // 1602显示数字的函数
{
IF(num <= 9) 
 {
   lcd_1602_write_data('0'+num);
   lcd_1602_write_data(' ');
  }else if(num >= 10 ) 
 {
   lcd_1602_write_data('0'+num/10);
   lcd_1602_write_data('0'+num%10);
  }
}

void lcd1602_info_display(uint choose, uint num_type, uint num_count)  
{
int num;
lcd_1602_write_com(0x01);
switch(choose) 
  {
case WAIT_SALE:
lcd_1602_write_com(0x80+0x01);       //
for(num = 0; num < 13; num++) 
{
lcd_1602_write_data(wait_sale[num]);
}
break;
case NO_WATER:
lcd_1602_write_com(0x80+0x03);
for(num = 0; num < 9; num++)
  {
   lcd_1602_write_data(no_water[num]);        
   }
break;
case SALING:
lcd_1602_write_com(0x80+0x00);
for(num = 0; num < 6; num++) 
  {
    lcd_1602_write_data(price[num]);
   }
lcd_1602_write_data('0'+(num_type+1));
lcd_1602_write_data(' ');
lcd_1602_write_data(' ');
for(num = 0; num < 4; num++) 
          {
           lcd_1602_write_data(number[num]);
           }
lcd_1602_show_num(num_count);
break;
case INPUT_MONEY:
lcd_1602_write_com(0x80+0x00);
for(num = 0; num < 4; num++) 
    {
      lcd_1602_write_data(sum[num]);
    }
lcd_1602_show_num(num_type);
lcd_1602_write_data(' ');
lcd_1602_write_data(' ');
for(num = 0; num < 6; num++) 
        {
       lcd_1602_write_data(input[num]);
        }
lcd_1602_show_num(num_count);
break;
case CHANGE:
if(!num_count) 
                {
                //put water
       lcd_1602_write_com(0x80+0x02);
                for(num = 0; num < 13; num++)
            {
lcd_1602_write_data(put_water[num]);
            }
       }
else 
{
lcd_1602_write_com(0x80+0x02);              //取消选择时写命令退币
for(num = 0; num < 9; num++) 
        {
             lcd_1602_write_data(cancle[num]);
        }
}
for(num = 0; num < 7; num++)
        {
            lcd_1602_write_data(change[num]);
        }
lcd_1602_show_num(num_type);
break;
default:
break;
}
lcd_1602_write_com(0x0c);
}
void lcd_1602_saling(uint type, uint num)
{
        lcd1602_info_display(SALING, type, num);
        lcd_1602_wait_sure();
}

void lcd_1602_inputing(uint need, uint input)
{
  lcd1602_info_display(INPUT_MONEY, need, input);
  lcd_1602_wait_sure();
}

The content of resource sharing includes:
(1) [Complete final version of graduation thesis] Vending machine system design based on AT89C51 microcontroller.doc
(2) Proteus simulation;
(3) Keil C program;
(4) Reference materials;
(5) Visio process Diagram file;
(6) Schematic diagram file;

Screenshot of the resource:
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Resource acquisition method
Resource acquisition method
Resource acquisition method
Important things said three times! ! ! ! ! ! ! ! ! ! !
Since this design is the original design of the author,
to obtain all the above resources, please search on WeChat and pay attention to the public number: Jiaoyuan Xiaozhi

Related Posts