最近闲的无聊,就接了5个系里面同学的毕业设计,这几天加班累得我,当然是收费的,都是同学,差不多就500一个,然而班级一个同学让我帮他调设备,也是网上买的,居然花了2800,社会,社会........老子做了5个,还没人家一个赚的多,小猪佩奇送给自己安慰一下自己。。。。。。。。废话不想说,直接看代码吧.....都是很简单的,很多东西都是现成的,我就是为了骗黑币。。。。。。暴露自己了
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- typedef bit BOOL;
-
- unsigned int sec = 0,min = 0,aa,tmp;
- unsigned char ss,sg,ms,mg,count,count1;
- sbit key1 = P0^0; //系统启动按键
- sbit key2 = P0^1; //投币三元按键
- sbit beep = P3^7; //蜂鸣器,洗衣完成
- sbit led1 = P0^2; //等待运行灯
- sbit led2 = P0^3; //系统运行灯
- sbit led3 = P0^4; //网上预约灯
- sbit rs=P0^7;
- sbit rw=P0^6;
- sbit lcden=P0^5;
- char code dis1 []={"Waiting To Run!"};
- char code dis2 []={"system running!"};
- char code dis3 []={"time remaining:"};
- void delay_ms(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void send(unsigned char a) //单字节发送函数
- { //注意:若单片机TXD(P3.1)无上拉能力,必须在P3.1端接上拉电阻
- ES =0;
- TI=0;
- SBUF=a;
- while(TI==0);
- TI=0;
- ES = 1;
- }
- void send_str(unsigned char *str) //发送字符串函数
- {
- while(*str != '\0')
- send(*str++);
- }
- void ctrl() //接收处理函数
- {
- switch(tmp)
- {
- case '1': //查询洗衣机是否被预约
- if(count1 == 0)
- {
- send_str(" the system is not running\n! ");
- }
- else
- {
- send_str(" the system is running\n! ");
- }
-
- break;
-
- case '2': //查询洗衣机剩余洗衣时间
- if(count1 == 0)
- {
- send_str(" time remaining: 00:00\n");
- }
- else
- {
- send_str(" time remaining: \n");
- send((unsigned char) 2-ms+'0');
- send((unsigned char) 9-mg+'0');
- send(':');
- send((unsigned char) 5-ss+'0');
- send((unsigned char) 9-sg+'0');
- send('\n');
- }
- break;
- case '3': //预定洗衣机
- led3 = 1;
- count1 = 1;
- send_str(" the machines is reserved by you!\n");
- break;
- case '4': //启动洗衣机
- led2 = 1;
- led3 = 0;
- count = 3;
- break;
-
- default:
- break;
- }
- }
- void init(void)
- {
- ES=0; //关中断
- SCON = 0x50; // REN=1允许串行接受状态,串口工作模式1,
- //10位UART(1位起始位,8位数据位,1位停止位,无奇偶校验),波特率可变
- TMOD = 0x21;
- TH0 = (65535-50000)/256;
- TL0 = (65535-50000)%256;
-
- TH1=TL1=0xFD; // 波特率9600 (本次测试采用晶振为11.0592)
- PCON &= 0x7f; // 波特率不倍增
- TR1 = 1; //定时器1开始工作,产生波特率
- //发送标志位置0
- TI=0; //接收标志位置0
- RI=0;
- ES=1;
-
-
- EA = 1; //开总中断
- ET0 = 1; //开定时器中断
- }
- void write_com(uchar com)
- {
- rs=0;
- lcden=0;
- P2=com;
- delay_ms(5);
- lcden=1;
- delay_ms(5);
- lcden=0;
- }
- void write_date(uchar date)
- {
- rs=1;
- lcden=0;
- P2=date;
- delay_ms(5);
- lcden=1;
- delay_ms(5);
- lcden=0;
- }
- void lcd_init()
- {
- rw=0;
- lcden=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void write_fm(uchar add,uchar data1,uchar data2)
- {
- write_com(0x80+0x40+add);
- write_date(0x30+data1);
- write_date(0x30+data2);
- }
- void main()
- {
- char i = 0;
-
- init();
- lcd_init();
- led1 =1;
- led2 =0;
- led3 =0;
- beep = 0;
- key1 = 1;
- key2 = 1;
- count1 = 0; //0为系统没有运行;1为系统已经被预定
-
- write_com(0x80);
- i=0;
- while (dis1 [i]!='\0')
- {
- write_date(dis1 [i]);
- i++;
- }
-
- while(key1 == 1)
- {
- if(count == 3)
- {
- count = 0;
- led2 = 1;
- write_com (0x01);
- while(1)
- {
- TR0 = 1; //开启定时器
- ss = sec/10;
- sg = sec%10;
- ms = min/10;
- mg = min%10;
- write_com(0x80);
- i=0;
- while (dis1 [i]!='\0')
- {
- write_date(dis3 [i]);
- i++;
- }
-
- write_fm(4,2-ms,9-mg);
- write_date(':');
- write_fm(7,5-ss,9-sg);
-
- if(ms == 2&&mg == 9&&ss == 5&&sg == 9)
- {
- ET0 = 0;
- TR0 = 0; //关定时器
- }
- }
- }
- }
-
-
- if(key1 == 0)
- {
- delay_ms(20);
- write_com (0x01);
- while(key1 != 1)
- {
- led1 = 0;
- write_com(0x80);
- i=0;
- while (dis2 [i]!='\0')
- {
- write_date(dis2 [i]);
- i++;
- }
- count1 = 1; //人工投币
- if(key2 == 0)
- {
- delay_ms(20);
- if(key2 == 0)
- {
- count++;
- while(!key2);
- }
- }
- if(count == 3)
- {
- count = 0;
- led2 = 1;
- write_com (0x01);
- while(1)
- {
- TR0 = 1; //开启定时器
- ss = sec/10;
- sg = sec%10;
- ms = min/10;
- mg = min%10;
- write_com(0x80);
- i=0;
- while (dis1 [i]!='\0')
- {
- write_date(dis3 [i]);
- i++;
- }
-
- write_fm(4,2-ms,9-mg);
- write_date(':');
- write_fm(7,5-ss,9-sg);
-
- if(ms == 2&&mg == 9&&ss == 5&&sg == 9)
- {
- ET0 = 0;
- TR0 = 0; //关定时器
- }
- }
-
- }
- }
- }
-
- }
- void timer0() interrupt 1
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
赵桂黎.rar
(44.86 KB, 下载次数: 40)
|