- #include<reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- void delay(uint i){while(i--);}
- sbit cs1=P2^0; sbit cs2=P2^1;sbit en=P2^2;sbit rw=P2^3;
- sbit rs=P2^4; sbit wr=P2^5; sbit LED=P2^6; sbit f=P2^7;
- sbit wl1=P1^0;sbit wl2=P1^1;sbit wl3=P1^2;sbit wl4=P1^3;
- sbit wl5=P1^4;sbit wl6=P1^5;sbit wl7=P1^6;sbit col0=P1^7;
- sbit col1=P3^0;sbit col2=P3^1;sbit col3=P3^2;
- sbit w1=P3^3; sbit w2=P3^4;sbit w3=P3^5;
- sbit w4=P3^6;sbit w5=P3^7;
- sbit row0=P0^0;sbit row1=P0^1;sbit row2=P0^2;sbit row3=P0^3;
- #define zuo {w1=0;w2=1;}
- #define you {w1=1;w2=0;}
- #define stop {w1=1;w2=1;}
- #define jia {w3=0;w4=1;}
- #define song {w3=1;w4=0;}
- #define shang {w5=1;}
- #define xia {w5=0;}
- uchar code ledcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
- 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x19,0x10,
- 0xbf,0xff};
- uchar buf[8];
- uchar code zm16x16l[]="產(chǎn)品手動包裝控制白黃色工作狀態(tài)左右移上升下降故障";
- uchar code zm16x16[][32]=
- {
- /*-- 文字: 產(chǎn) --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x04,0xE4,0x44,0x4C,0x74,0x54,0x45,0x46,0x64,0x54,0x4C,0x44,0x64,0x44,0x00,
- 0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- /*-- 文字: 品 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x00,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00,0x00,
- 0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,
- /*-- 文字: 手 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x24,0x24,0x24,0x24,0x24,0x24,0xFE,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x00,
- 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,
- /*-- 文字: 動 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x20,0x24,0x24,0xE4,0x24,0x24,0x24,0x20,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,
- 0x08,0x1C,0x0B,0x08,0x0C,0x05,0x4E,0x24,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,
- /*-- 文字: 包 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x80,0x40,0x20,0xD8,0x4F,0x4A,0x48,0x48,0x48,0xC8,0x08,0x08,0xFC,0x08,0x00,0x00,
- 0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x42,0x43,0x48,0x50,0x4F,0x40,0x70,0x00,
- /*-- 文字: 裝 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x42,0x2C,0x24,0x10,0xFF,0x04,0x64,0xA4,0x24,0x3F,0x24,0x24,0x24,0x04,0x00,
- 0x20,0x21,0x11,0x11,0xF9,0x45,0x23,0x03,0x05,0x09,0x11,0x29,0x45,0xC1,0x41,0x00,
- /*-- 文字: 控 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00,
- 0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,
- /*-- 文字: 制 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00,
- 0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,
- /*-- 文字: 白 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x00,0xF8,0x08,0x08,0x0C,0x0B,0x08,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,
- 0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,
- /*-- 文字: 黃 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x20,0x24,0x24,0xA4,0xA4,0xBF,0xA4,0xE4,0xA4,0xBF,0xA4,0xA4,0x24,0x24,0x20,0x00,
- 0x00,0x80,0x80,0x5F,0x32,0x12,0x12,0x1F,0x12,0x12,0x32,0x5F,0xC0,0x00,0x00,0x00,
- /*-- 文字: 色 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x40,0x20,0xF0,0x28,0x27,0x24,0xE4,0x24,0x34,0x2C,0xE4,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x43,0x42,0x42,0x42,0x43,0x40,0x78,0x00,0x00,
- /*-- 文字: 工 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
- 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
- /*-- 文字: 作 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x80,0x40,0x20,0xF8,0x07,0x22,0x18,0x0C,0xFB,0x48,0x48,0x48,0x68,0x48,0x08,0x00,
- 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00,
- /*-- 文字: 狀 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x08,0x30,0x00,0xFF,0x20,0x20,0x20,0x20,0xFF,0x20,0xE1,0x26,0x2C,0x20,0x20,0x00,
- 0x04,0x02,0x01,0xFF,0x40,0x20,0x18,0x07,0x00,0x00,0x03,0x0C,0x30,0x60,0x20,0x00,
- /*-- 文字: 態(tài) --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x04,0x04,0x04,0x84,0x44,0x34,0x4F,0x94,0x24,0x44,0x84,0x84,0x04,0x00,0x00,
- 0x00,0x60,0x39,0x01,0x00,0x3C,0x40,0x42,0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00,
- /*-- 文字: 左 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x08,0x08,0x08,0x08,0x08,0xC8,0x3F,0x0A,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
- 0x40,0x20,0x50,0x4C,0x43,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,
- /*-- 文字: 右 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x08,0x08,0x08,0x88,0xC8,0x38,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
- 0x04,0x02,0x01,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,
- /*-- 文字: 移 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x10,0x92,0x72,0xFE,0x91,0x19,0x90,0x88,0x44,0x53,0xA2,0x52,0x0A,0x06,0x00,0x00,
- 0x02,0x01,0x00,0xFF,0x00,0x81,0x88,0x44,0x46,0x29,0x11,0x09,0x05,0x03,0x01,0x00,
- /*-- 文字: 上 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
- 0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00,
- /*-- 文字: 升 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x40,0x44,0x44,0x44,0xFE,0x42,0x42,0x40,0x40,0xFE,0x40,0x40,0x60,0x40,0x00,
- 0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,
- /*-- 文字: 下 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x22,0x62,0xC2,0x82,0x02,0x03,0x02,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
- /*-- 文字: 降 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0xFE,0x22,0x5A,0x86,0x00,0x48,0x44,0x2B,0xD2,0x2A,0x26,0x42,0x40,0x40,0x00,
- 0x00,0xFF,0x02,0x04,0x03,0x00,0x0D,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x00,0x00,
- /*-- 文字: 故 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x10,0x90,0x90,0xFF,0x90,0x90,0x10,0x80,0xF0,0x1F,0x12,0x10,0xF0,0x10,0x10,0x00,
- 0x00,0x3F,0x10,0x10,0x10,0x5F,0x41,0x20,0x20,0x13,0x0C,0x13,0x20,0x60,0x20,0x00,
- /*-- 文字: 障 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
- 0x00,0xFE,0x22,0x5A,0x86,0x10,0xD2,0x56,0x5A,0x53,0x52,0x5A,0xD6,0x12,0x10,0x00,
- 0x00,0xFF,0x02,0x04,0x13,0x10,0x17,0x15,0x15,0xFD,0x15,0x15,0x17,0x10,0x10,0x00,
- };
- uchar code zm8x16l[]="0123456789";
- uchar code zm8x16[][16]=
- {
- /*-- 文字: 0 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
- /*-- 文字: 1 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
- /*-- 文字: 2 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
- /*-- 文字: 3 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
- /*-- 文字: 4 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
- /*-- 文字: 5 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
- /*-- 文字: 6 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
- /*-- 文字: 7 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
- /*-- 文字: 8 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
- /*-- 文字: 9 --*/
- /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
- };
- /* 鍵盤掃描 */
- uchar key()
- {
- uchar k=25;
- row0=0; k=col0==0?0:col1==0?1:col2==0?2:col3==0?3:k; row0=1;
- row1=0; k=col0==0?4:col1==0?5:col2==0?6:col3==0?7:k; row1=1;
- row2=0; k=col0==0?8:col1==0?9:col2==0?10:col3==0?11:k; row2=1;
- row3=0; k=col0==0?12:col1==0?13:col2==0?14:col3==0?15:k; row3=1;
- return k;
- }
- /* 寫命令 */
- void wc(uchar com)
- {
- rs=0;rw=0;
- P0=com;
- en=1;en=0;
- }
- /* 寫數(shù)據(jù) */
- void wd(uchar dat)
- {
- rs=1;rw=0;
- P0=dat;
- en=1;en=0;
- }
- /* 清屏 */
- void clr()
- {
- uchar i,j;
- cs1=cs2=1;
- for(i=0;i<8;i++)
- {
- wc(0xb8+i);
- wc(0x40);
- for(j=0;j<64;j++)wd(0);
- }
- }
- /* 12864初始化 */
- void init()
- {
- wc(0x3f);
- wc(0xc0);
- clr();
- }
- /* 顯示任意字模 */
- void showxy(uchar row,uchar col,uchar x,uchar y,uchar *tab)
- {
- bit right;
- uchar i,j;
- if(col<64){right=0;}
- else {col-=64;right=1;}
- for(i=0;i<y;i++)
- {
- if(right)cs1=0,cs2=1;
- else cs1=1,cs2=0;
- wc(0xb8+row+i);
- wc(0x40+col);
- for(j=0;j<x;j++)
- {
- if(col+j<64)wd(tab[i*x+j]);
- else if(right==0)
- {
- cs1=0,cs2=1;
- wc(0xb8+row+i);
- wc(0x40+(col+j-64));
- wd(tab[i*x+j]);
- }
- }
- }
- }
- /* 8x16的索引 */
- uchar enn(uchar *s)
- {
- uchar i;
- for(i=0;zm8x16l[i]!=0;i++)if(zm8x16l[i]==s[0])break;
- return i;
- }
- /* 16x16的索引 */
- uchar cnn(uchar *s)
- {
- uchar i;
- for(i=0;zm16x16l[i]!=0;i+=2)
- if(zm16x16l[i]==*s&&zm16x16l[i+1]==*(s+1))break;
- return i/2;
- }
- /* 顯示8x16及16x16的索引 */
- void showstr(uchar row,uchar col,uchar *s)
- {
- uchar i;
- for(i=0;s[i]!=0;i++)
- {
- if(s[i]<0x80)
- {
- showxy(row,col,8,2,zm8x16[enn(&s[i])]);
- col+=8;
- }
- else
- {
- showxy(row,col,16,2,zm16x16[cnn(&s[i])]);
- col+=16;i+=1;
- }
- if(col>120)
- {
- col=0;row+=2;
- }
- }
- }
- /* 數(shù)碼管的驅(qū)動 */
- void dis()
- {
- uchar i,j=0x7f;
- for(i=0;i<8;i++)
- {
- cs1=0;cs2=1;
- P0=ledcode[buf[i]];wr=1;wr=0;
- cs1=1;cs2=0;
- P0=j;wr=1;wr=0;
- delay(40);
- j=(j>>1)|0x80;
- cs1=cs2=0;
- P0=0xff;wr=1;wr=0;
- }
- }
- bit runflag=1,timeflag=1,timesz,keyflag,dian,stopflag=1; //運(yùn)行,時間,時間設(shè)置,按鍵,小數(shù)點(diǎn),停止的標(biāo)志
- uchar bs=0,hs=0,sec,min; //白色球,黃色球,秒,分的定義
- uchar n=0,moveflag,flag; //n是機(jī)械手工步,moveflag是工作狀態(tài)標(biāo)志,flag夾球顏色判斷,
- void ka() //鍵值和控制設(shè)置
- {
- uchar i,k;
- if(key()!=25&&keyflag==0)
- {
- keyflag=1;
- if(key()==13&&runflag==1&&timeflag==1)
- {
- while(key()==13);
- bs++; //白色球設(shè)置
- if(bs>10)bs=0; //到10就歸0
- }
- if(key()==14&&runflag==1&&timeflag==1)
- {
- while(key()==14);
- hs++; //黃色球設(shè)置
- if(hs>10)hs=0; //到時就歸零
- }
- if(key()==12)timesz=1; //時間設(shè)置按鈕被按下
- if(key()<10&×z==1) //鍵盤值小于十
- {
- k=key();
- for(i=0;i<7;i++)buf[i]=buf[i+1]; //buf[7]顯示當(dāng)前數(shù)值,將之前的數(shù)值往前推
- buf[7]=k;
- }
- else if(key()==10&&dian==1) //按鍵按下小數(shù)點(diǎn),并且沒有重復(fù)按下
- {
- dian=0;
- buf[7]=buf[7]+10; //將原來的數(shù)值加上十,就成為了有小數(shù)點(diǎn)的數(shù)
- }
- if(buf[7]<10)dian=1;
- min=buf[5]-10; //分的取值
- sec=buf[6]*10+buf[7]; //秒的取值
- if(key()==11&×z==1&&(bs!=0||hs!=0)&&(sec!=0||min!=0)) //按下運(yùn)行鍵,時間被設(shè)置完成,球的數(shù)量也被設(shè)置完成
- {
- runflag=0; //運(yùn)行標(biāo)志變?yōu)?0 表示在運(yùn)行
- stopflag=1; //停止標(biāo)志置 1
- }
- if(runflag==0&&key()==15)stopflag=0; //按下暫停鍵,停止標(biāo)志置 0
- if(stopflag==0){stop;runflag=1;} //停止,并且運(yùn)行鍵置 1
- }
- //按鍵松開或沒有按下的標(biāo)志
- if(key()==25)keyflag=0;
- }
- void jxs() //機(jī)械手運(yùn)行函數(shù)
- {
- switch(n)
- {
- case 0:
- if(wl5){xia;moveflag=4;break;} //左移并顯示
- n=1;
- case 1:
- delay(20000); //延時0.2秒等待機(jī)械手判斷
- n=2;
- case 2:
- if(wl7==0)flag=0; //flag=0是黃色,白色相反
- else flag=1;
- n=3;
- case 3:
- if(wl6){jia;break;} //夾球
- n=4;
- case 4:
- if(wl6==0){n=5;break;} //夾緊就下一步
- else {moveflag=5;break;} //故障顯示
- case 5:
- if(wl4){shang;moveflag=3;break;} //上升并顯示
- n=6;
- case 6:
- if(wl3){zuo;moveflag=1;break;} //左移并顯示
- stop;
- n=7;
- case 7:
- if(wl6==0){song;break;} //松球
- if(flag==0)hs--; //減少黃球數(shù)
- else bs--; //減少白球數(shù)
- n=8;
- case 8:
- if(wl1){you;moveflag=2;break;} //右移并顯示
- stop;
- if(bs==0&&hs==0){runflag=1;moveflag=6;} //運(yùn)球完成 開始包裝
- n=0;
- }
- }
- void init1() //初始化函數(shù)a
- {
- TMOD=0x01;
- EA=ET0=1;
- init();
- showstr(0,0,"產(chǎn)品手動包裝控制"); //12864顯示
- buf[0]=buf[1]=buf[2]=buf[3]=20; //顯示 ---------
- buf[4]=buf[5]=buf[6]=buf[7]=20;
- while(wl1)you; //機(jī)械手歸位
- stop; //移到一工位停止
- song; //松開爪子
- delay(50000);
- showstr(3,0,"白色"); //12864顯示
- showstr(3,64,"黃色");
- }
- void main() //主函數(shù)
- {
- uchar z,x; //蜂鳴器及燈的閃爍
- end:
- init1();
- while(1)
- {
- showxy(3,40,8,2,zm8x16[bs%10]); //白球數(shù)量顯示
- showxy(3,104,8,2,zm8x16[hs%10]); //黃球數(shù)量顯示
- ka();
- if(runflag==0) //系統(tǒng)運(yùn)行
- { //定時器開
- TR0=1; //時間設(shè)置置 1
- timesz=1; //機(jī)械手開啟
- jxs();
- buf[5]=min%10+10; //時間倒計時顯示
- buf[6]=sec/10%10;
- buf[7]=sec%10;
- /* 工作狀態(tài)顯示 */
- showstr(6,0,"工作狀態(tài)");
- if(moveflag==1)showstr(6,80,"左移");
- else if(moveflag==2)showstr(6,80,"右移");
- else if(moveflag==3)showstr(6,80,"上升");
- else if(moveflag==4)showstr(6,80,"下降");
- else if(moveflag==5) //故障報警
- {
- showstr(6,80,"故障"); //蜂鳴器以1秒五個周期報警
- delay(10000);
- f=!f;
- }
- if(sec==0&&min==0){runflag=1;stop;} //時間到就停止
- }
- /* 抓球結(jié)束 */
- if(moveflag==6) //包裝
- {
- showstr(6,80,"包裝");
- for(z=0;z<40;z++) //循環(huán)二十秒
- {
- delay(25550);
- f=!f; //蜂鳴器一秒一周期
- for(x=0;x<2;x++)
- {
- delay(25550);
- LED=!LED; //LED0一秒兩周期
- }
- }
- moveflag=0; //完成所有操作回到初始化
- goto end;
- }
- dis();
- }
- }
- void time() interrupt 1 //定時1
- {
- TH0=0xfc;
- TL0=0x17;
- if(++c==1000) //運(yùn)行時分秒的運(yùn)行
- {
- c=0;
- sec--;
- if(sec==0&&min>0)
- {
- sec=60;
- min--;
- }
- }
- }
復(fù)制代碼
|