捕獲.PNG (83.88 KB, 下載次數: 25)
下載附件
2020-4-3 12:37 上傳
總共6個按鍵,左邊第一個是開窗,顯示屏顯示hand1,下面接著的是關窗,顯示hand2,后面是停止鍵,顯示hand0,此時電機應該要停下來,右邊3個第一個和第二個都是限位開關,比如此時是hand1狀態,按一下這兩個中的任何一個都會變為hand0,就代表電機停下來的意思,右邊最后一個鍵是模式選擇鍵,可以調到語音模式,此時要是閉合最上面的第一個刀開關,顯示sound1,開窗,閉合第二個就顯示sound2,關窗,兩個都打開就是sound0,代表停止
單片機源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include<stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit E=P2^7;
- sbit RW=P2^6;
- sbit RS=P2^5;
- sbit K2=P3^4;
- sbit K1=P2^4;
- sbit xianwei1=P2^0;
- sbit xianwei2=P2^1;
- sbit S1=P2^2;
- sbit S2=P2^3;
- unsigned char code F_Rotation[8]={0x08,0x18,0x10,0x30,0x20,0x60,0x40,0x48};
- unsigned char code B_Rotation[8]={0x48,0x40,0x60,0x20,0x30,0x10,0x18,0x08};
- uchar xwflag=0;
- uchar FB_flag=0;
- uchar a1=0,a2=0;
- uchar b1=0,b2=0;
- uchar c1=0,c2=0;
- uchar d1=0,d2=0;
- uchar moshi=0;
- void Delay(uint i)
- {
- uchar x,j;
- for(j=0;j<i;j++)
- for(x=0;x<=148;x++);
- }
- void delays()
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- bit Busy(void)
- {
- bit busy_flag=0;
- RS=0;
- RW=1;
- E=1;
- delays();
- busy_flag=(bit)(P0 & 0x80);
- E=0;
- return busy_flag;
- }
- void wcmd(uchar del)
- {
- while(Busy());
- RS=0;
- RW=0;
- E=0;
- delays();
- P0=del;
- delays();
- E=1;
- delays();
- E=0;
- }
- void wdata (uchar del)
- {
- while(Busy());
- RS=1;
- RW=0;
- E=0;
- delays();
- P0=del;
- delays();
- E=1;
- delays();
- E=0;
- }
- void L1602_init(void)
- {
- wcmd(0x38);
- wcmd(0x0c);
- wcmd(0x06);
- wcmd(0x01);
- }
- void L1602_char(uchar hang, uchar lie, char sign)
- {
- uchar a;
- if(hang==1) a=0x80;
- if(hang==2) a=0xc0;
- a=a+lie -1;
- wcmd(a);
- wdata(sign);
- }
- void L1602_string(uchar hang, uchar lie, uchar *p )
- {
- uchar a,b=0;
- if(hang==1) a=0x80;
- if(hang==2) a=0xc0;
- a=a+lie -1;
- while(1)
- {
- wcmd(a++);
- if((*p=='\0') || (b==16)) break;
- b++;
- wdata(*p);
- p++;
- }
- }
- void main(void)
- {
- unsigned char i;
- IT0=1;
- EX0=1;
- PX0=1;
- IT1=1;
- EX1=1;
- PX1=1;
- EA=1;
- L1602_init();
- Delay(100);
- L1602_char(1,1,'M');
- L1602_char(1,2,'o');
- L1602_char(1,3,'d');
- L1602_char(1,4,'e');
- L1602_char(1,5,':');
- while(1)
- {
- L1602_char(2,6,FB_flag%10+48);
- if(i>7) i=0;
- if(FB_flag==1) { P1=F_Rotation[i]; }
- else if(FB_flag==2) { P1= B_Rotation[i]; }
- else{ P1=0xff; }
- i++;
- Delay(100);
- if(K1==0){ a1=1; a2=0; }
- if( a1==1&&a2==0)
- {
- FB_flag=0;
- a2=1;
- }
- if(K1==1){ a1=0;a2=0; }
- if( K2==0) { d1=1;d2=0; }
- if(d1==1&&d2==0)
- {
- FB_flag=1;
- xwflag=0;
- d2=1;
- }
- if(K2==1) { d1=0;d2=0; }
- if(moshi==0)
- {
- L1602_char(1,6,'H');
- L1602_char(1,7,'a');
- L1602_char(1,8,'n');
- L1602_char(1,9,'d');
- L1602_char(1,10,' ');
- L1602_char(1,16, FB_flag%10+48);
- L1602_char(2,16,' ');
- }
- if(moshi==1)
- {
- L1602_char(1,6,'S');
- L1602_char(1,7,'o');
- L1602_char(1,8,'u');
- L1602_char(1,9,'n');
- L1602_char(1,10,'d');
- if(S1==0) L1602_char(2,1,0+48); else L1602_char(2,1,1+48);
- if(S2==0) L1602_char(2,2,0+48); else L1602_char(2,2,1+48);
- if(S1==1&&S2==0) { xwflag=0;FB_flag=1; L1602_char(1,16,FB_flag%10+48) ;}
- if(S1==0&&S2==1) { xwflag=0;FB_flag=2; L1602_char(1,16,FB_flag%10+48) ;}
- if(S1==1&&S2==1) { FB_flag=0; L1602_char(1,16,FB_flag%10+48) ;}
- L1602_char(2,16,' ');
- }
-
- if(xianwei1==0) { b1=1;b2=0;}
- if(b1==1&&b2==0)
- {
- FB_flag=0;
- xwflag=1;
- b2=1;
- }
- if(xianwei1==1) { b1=0;b2=0;}
- if(xianwei2==0) { c1=1;c2=0; }
- if(c1==1&&c2==0)
- {
- FB_flag=0;
- xwflag=2;
- c2=1;
- }
- if(xianwei2==1) { c1=0;c2=0; }
- if(xwflag!=0) FB_flag=0;
- }
- }
-
- void it0() interrupt 0
- {
- moshi++;
- if(moshi==3) moshi=0;
- FB_flag=0;
- }
- void it1() interrupt 2
- {
- FB_flag=2;
- xwflag=0;
- }
復制代碼
全部資料51hei下載地址:
仿真.zip
(21.64 KB, 下載次數: 3)
2020-4-3 12:39 上傳
點擊文件名下載附件
|