51 single chip microcomputer automatic water vending machine

Publisher:凌晨2点369Latest update time:2020-02-11 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

51hei.png 

The microcontroller source program is as follows:

#include "stc.h"

#include "button.h"

#include "smg.h"

#include "AT24C02.h"

sbit led1=P0^0;

sbit bell=P0^6;

sbit relay=P0^4;  

unsigned char flag_s7,flag_s6;

int money=0,amount=0;//price capacity

unsigned char count,flag_count;

unsigned char state; //Control the two display interface buttons of the digital tube

#define EXE_EN P2 = (P2&0X1F)|0XA0;  P2 &= 0X1F

void init_time0() //1 microsecond plus 1

{

        TMOD=0x01;

        TH0=(65536-50000)/256; //timing 50ms

        TL0=(65536-50000)%256;

        ET0=1;

        //TR0=1;

        EA=1;

}

void time0() interrupt 1

{

   TH0=(65536-50000)/256;

   TL0=(65536-50000)%256;

   count++;

   if(count==20)

   {

   count=0;

   flag_count=1;

   }

}

void key()

{

        unsigned char kk=keyboard();

        unsigned char guan=get_lux(0x41);


        if(guan<64)

        {

            P0=0xff;

            P2&=0x1f;

            P2|=0x80;

            led1=0; //light l2 is on    

                P2&=0x1f;        

        }

        if(guan>=64)

        {

                P0=0xff;

            P2&=0x1f;

            P2|=0x80;

            led1=1; //light l1 off    

                P2&=0x1f;

        }

        if(kk==7) 

        {

        flag_s7=1;

        state=1;

        TR0=1; //Start the timer

        }

        if(kk==6)

        {

                flag_s6=1;

                state=2;

        }

        if(flag_s7)

        {

          flag_s7=0;bell=0;relay=1;EXE_EN;             

        }

        if(flag_s6)

        {

         TR0=0; //Turn off the timer

         flag_s6=0;bell=0;relay=0;EXE_EN;

        }

        if(state==1)

        {

            display_s(1,0); display(2,5); display(3,0);

                display(4,amount/100); display_s(5,amount%100/10); display(6,amount%10); display(7,0);

        }

        if(state==2)

        {

                display_s(1,0); display(2,5); display(3,0);

                display(4,money/1000); display_s(5,money%1000/100); display(6,money%100/10); display(7,money%10);

        }


        if(flag_count==1)

        {

                flag_count=0;

                money=money+5;

                amount=amount+1;

        }

        if(amount==9990){flag_s6=1;state=2;}

}

void main()

{

    init_time0();

        while(1)

        {

          key();

        }

}



Reference address:51 single chip microcomputer automatic water vending machine

Previous article:MCU smoke alarm program + PCB + schematic diagram
Next article:51 MCU assembly control nRF24L01 source program

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号