標(biāo)題: 基于單片機(jī)的自動(dòng)售貨機(jī)程序 [打印本頁(yè)]

作者: 忖腹食水    時(shí)間: 2018-11-30 12:30
標(biāo)題: 基于單片機(jī)的自動(dòng)售貨機(jī)程序
分享交流
#include<reg52.h>
voiddelay_s(unsigned int t);
voiddelay_ms(unsigned int t);
voidUART_Init(void);
voidSpeech(unsigned char*text,unsigned char length);
voidinit_lcd(void);
voidch_disp_any(unsigned char line,unsigned char row,unsigned char num,unsignedchar chn);
#define ch P0
#define led P1
sbit take=P2^0;
sbit back=P2^1;
void main()
{
unsigned char money,i,key,x[3];
init_lcd();
UART_Init();
while(1)
{
  ks:led=0xff;
     ch_disp_any (1,1,16,"所選商品:    ");
        ch_disp_any(2,1,16,"應(yīng)投金額:    ");
        ch_disp_any (3,1,16,"實(shí)投金額:    ");
        ch_disp_any (4,1,16,"所選商品:    ");
        while(ch==0xff);
        delay_ms(50);
        switch(ch)                                                                                                                                    
        {
        case 0xfe:money=35;led=0xfe;ch_disp_any (1,6,4,"七喜");ch_disp_any (2,6,6,"3.5元");Speech("七喜3.5 元請(qǐng)投幣",16);break;
        case 0xfd:money=40;led=0xfd;ch_disp_any (1,6,4,"可樂(lè)");ch_disp_any(2,6,6,"4.0 元");Speech("可樂(lè)4.0 元請(qǐng)投幣",16);break;
        case 0xfb:money=45;led=0xfb;ch_disp_any (1,6,4,"牛奶");ch_disp_any(2,6,6,"4.5 元");Speech("牛奶4.5 元請(qǐng)投幣",16);break;
        case 0xf7:money=60;led=0xf7;ch_disp_any (1,6,4,"銳澳");ch_disp_any(2,6,6,"6.0 元");Speech("銳澳6.0 元請(qǐng)投幣",16);break;
        case 0xef:money=30;led=0xef;ch_disp_any (1,6,4,"芬達(dá)");ch_disp_any(2,6,6,"3.0 元");Speech("芬達(dá)3.0 元請(qǐng)投幣",16);break;
        case 0xdf:money=50;led=0xdf;ch_disp_any (1,6,4,"雪碧");ch_disp_any(2,6,6,"5.0 元");Speech("雪碧5.0 元請(qǐng)投幣",16);break;
        case 0xbf:money=75;led=0xbf;ch_disp_any (1,6,4,"酸奶");ch_disp_any(2,6,6,"7.5 元");Speech("酸奶7.5 元請(qǐng)投幣",16);break;
        case 0x7f:money=20;led=0x7f;ch_disp_any (1,6,4,"白水");ch_disp_any(2,6,6,"2.0 元");Speech("白水2.0 元請(qǐng)投幣",16);break;
        default:break;
        }
  toubi:
     do{i=Keyboard();} while(i>100);
        if(i==100)    goto ks;
        if(i<90)
       {key=i;
          x[0]=key/10+'0';
              x[1]='.';
              x[2]=key%10+'.';
              ch_disp_any (3,6,3,x);ch_disp_any(3,8,4,"元");
              Speech("實(shí)投",4);Speech(x,4);Speech("元",4);
              }
        do{i=Keyboard();}while((i!=100)&&(i!=90));
        if(i==100)
         {
              if(key==money)
              {
               ch_disp_any (4,6,6,"請(qǐng)取物");
               Speech("請(qǐng)取物",6);
               take=0;delay_s(2);take=1;
               goto ks;
              }
              else
              {
               ch_disp_any (4,1,16,"退幣:   元");
               ch_disp_any (4,3,3,x);
               Speech("退幣",4);Speech(x,4);Speech("元",2);
               back=0;delay_s(2);back=1;
               ch_disp_any (3,1,16,"實(shí)投金額:      ");
               ch_disp_any (4,1,16,"購(gòu)物狀態(tài):請(qǐng)取物");
               goto toubi;
         }
      }
        if(i==90)
         {
               ch_disp_any (4,1,16,"退幣:  元");
               ch_disp_any (4,3,3,x);
               Speech("退幣",4);Speech(x,4);Speech("元",4);
               back=0;delay_s(2);back=1;
               ch_disp_any (3,1,16,"實(shí)投金額:      ");
               ch_disp_any (4,1,16,"購(gòu)物狀態(tài):請(qǐng)取物");
               goto toubi;
         }
      }
}



自助售貨機(jī).docx

16.07 KB, 下載次數(shù): 15, 下載積分: 黑幣 -5

1






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1