上周做的洗衣机,整个框架已经搭好,包括源码和仿真图,子程序可以使用,各位吧友,可以根据需要自己进行更改
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #include <string.h>
- #define uchar unsigned char
- #define uint unsigned int
- ///1602 液晶 p0 为液晶数据口
- sbit RS=P3^0;
- sbit RW=P3^1;
- sbit E=P3^4;
- uchar code line1[]="mode:01 time:00";
- uchar code line2[]="state: menu ";
- uchar code line3[]="state: work ";
- uchar code line4[]="state: stop ";
- uchar code line5[]="state: pause ";
- // motor
- sbit Motor_In0=P1^5;
- sbit Motor_In1=P1^4;
- //water
- sbit Water_In0=P3^6;
- sbit Water_In1=P3^7;
- ///key
- sbit Key_water_mode=P1^0;
- sbit Key_water_time=P1^1;
- sbit Key_water_start=P1^6;
- sbit Key_water_stop=P3^2;
- sbit Key_water_pause=P3^3;
- ///
- void delay(uint time)
- {
- uint i,j;
- for(i=0;i<time;i++)
- for(j=0;j<250;j++);
- }
- void Lcd1602_Write(uchar Cmd,uchar Cmd_Data)
- {
- E=0;
- RS=Cmd; // 0 指令 1 数据
- RW=0;
- P0=Cmd_Data;
- delay(1);
- E=1;
- E=0;
- }
- void Lcd1602_Init()
- {
- E=0;
- RW=1;
- RS=1;
- P0=0xff;
- delay(15);
- Lcd1602_Write(0,0x38);
- delay(5);
- Lcd1602_Write(0,0x38);
- Lcd1602_Write(0,0x08);
- Lcd1602_Write(0,0x0e);
- Lcd1602_Write(0,0x06);
- Lcd1602_Write(0,0x01);
- }
- void Lcd1602__byte(uchar y,uchar x,uchar z) //Y=0,1(起始行)X=0~15(起始列) Z asii 码
- {
- if(y) x+=0x40;
- x+=0x80; //
- Lcd1602_Write(0,x);
- Lcd1602_Write(1,z); //
- }
- void Lcd1602__text(uchar y,uchar x,uchar table[]) //Y,X??????,table[]?????
- {
- uchar z=0;
- uchar t;
- t=strlen(table)+x; //
- while(x<t) //
- { //
- Lcd1602__byte(y,x,table[z]); //
- x++;
- z++;
- }
- }
- void Timer0_Init(void)
- {
- TMOD = 0x01; //T0 工作方式 1;16位 计数器;
-
- TH0=(65536-50000)/256; // 初值高 8 位 走 1000 次,每次 1us :晶振 12MHz;
- TL0=(65536-50000)%256; // 初值低 8 位 走 1000 次,每次 1us :晶振 12MHz;
-
- TR0 = 0; // 开启 T0 定时器;
- ET0 = 1; // 允许 T0 定时器中断;
- EA = 1; // 开启 总中断 允许;
- }
- ///
- void INT0_Init(void) //外部中断0初始化
- {
- EA=1; //全局中断开
- EX0=1; //外部中断0开
- IT0=1; //边沿触发
- }
- //
- void Timer0(void) interrupt 1 using 1
- {
-
- static uchar count=0;
-
- uchar time_s,time_g;
- ET0=0;TR0=0;
- TH0 = (65536-50000)/256; // 中断后,赋初值;
- TL0 = (65536-50000)%256;
- count++; // 每次中断,计数 累加 1;
- if(count >=20)
- {
- count = 0; // 计数值 清0 ;
- }
- ET0=1;TR0=1;
- }
- //
- void INT0_EX0(void) interrupt 0 using 1
- {
-
- }
- /////////////////////
- void main(void)
- {
- uint i=0;
- INT0_init();
- Timer0_Init();
- Lcd1602_Init();
- Lcd1602__text(0,0,line1);
- Lcd1602__text(1,0,line2);
- Motor_In0=0;
- Motor_In1=1;
- while(1)
- {
-
- }
- }
复制代码
按键部分还未完成,希望大家补全:
3-water.rar
(47.2 KB, 下载次数: 83)
|