?? driver.h
字號:
#include <iom16v.h>
#include <macros.h>
#include <bit.h>
#include "define.h"
#include "LCD_Driver.h"
#include "Sounds_and_Display.h"
#include "key.h"
#include "PWM.h"
#include "24L01_Driver.h"
#define out_o_not if(flag_start==0)break
#define PWM_off TCCR1A=0x00;TCCR1B = 0x00;DDR_PD4=0 //stop
#define PWM_on TCCR1A=0x23;TCCR1B = 0x1A;DDR_PD4=1 //start
uchar data_buff[2];
void Port_close(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
void timer0_init(void)
{
TCNT0 = 0x06; //set count
TIMSK|=BIT(0);
SREG|=BIT(7);
}
void set_watlev()//水位高3中2低1
{
cls;
Delay(2);
Char_Set_XY(0,1,"水位設置:");
switch(wat_lv)
{
case 3:Char_Set_XY(5,1,"高");break;
case 2:Char_Set_XY(5,1,"中");break;
case 1:Char_Set_XY(5,1,"低");break;
default:break;
}
set_buff=0;
while(nn==1&&flag_start==0)//水位設置標志位為1
{
set_buff=key2_scan();
wat_lv+=set_buff;
if(BBBuffer==1)
{
if(wat_lv>=4)//判斷溢出
wat_lv=1;
if(wat_lv<=0)
wat_lv=3;
switch(wat_lv)
{
case 3:Char_Set_XY(5,1,"高");break;
case 2:Char_Set_XY(5,1,"中");break;
case 1:Char_Set_XY(5,1,"低");break;
default:break;
}
BBBuffer=0;
data_buff[0]='w';
data_buff[1]=wat_lv;
Putstr(data_buff);
}
key_scan();//掃描設置鍵盤
}
}
void set_health()//洗衣強度
{
cls;//清屏
Delay(2);
Char_Set_XY(0,1,"洗衣強度:");
Delay(1);
switch (health)
{
case 2:Char_Set_XY(5,1,"強");break;
case 1:Char_Set_XY(5,1,"弱");break;
default:break;
}
set_buff=0;
while(nn==2&&flag_start==0)//洗衣強度標志位為2
{
speed=health;
set_buff=key2_scan();
health+=set_buff;
if(BBBuffer==1)
{
if(health>=3)//判斷溢出
health=1;
if(health<=0)
health=2;
switch (health)
{
case 2:Char_Set_XY(5,1,"強");break;
case 1:Char_Set_XY(5,1,"弱");break;
default:break;
}
BBBuffer=0;
data_buff[0]='h';
data_buff[1]=health;
Putstr(data_buff);
}
key_scan();//掃描設置鍵盤
}
}
void set_cycle()//電動機循環次數
{
cls;//清屏
Delay(2);
Char_Set_XY(0,1,"循環次數 次");
Delay(1);
Char_Set_XY(4,1,":");
W_1byte(0,1,0x30+cycle);
set_buff=0;
while(nn==3&&flag_start==0)//電動機循環設置標志位為3
{
// display(cycle);
set_buff=key2_scan();
cycle+=set_buff;
if(BBBuffer==1)
{
if(cycle>=10)//判斷溢出
cycle=1;
if(cycle<=0)
cycle=9;
Char_Set_XY(4,1,":");
W_1byte(0,1,0x30+cycle);//顯示數字
BBBuffer=0;
data_buff[0]='c';//發數據
data_buff[1]=cycle;
Putstr(data_buff);
}
key_scan();//掃描設置鍵盤
}
}
void set_replay()//洗衣加排水重復次數
{
cls;//清屏
Delay(2);
Char_Set_XY(0,1,"洗衣重復次數 次");
Char_Set_XY(6,1,":");
Delay(1);
W_1byte(0,1,0x30+replay);
set_buff=0;
while(nn==4&&flag_start==0)//洗衣強度標志位為4
{
set_buff=key2_scan();
replay+=set_buff;
if(BBBuffer==1)
{
if(replay>=6)//判斷溢出
replay=1;
if(replay<=0)
replay=5;
Char_Set_XY(6,1,":");
W_1byte(0,1,0x30+replay);//顯示數字
BBBuffer=0;
data_buff[0]='r';
data_buff[1]=replay;
Putstr(data_buff);
}
key_scan();//掃描設置鍵盤
}
}
void wait_time(uchar w_t)
{
TCNT0=0;
count=0;
endcount=w_t;
}
void PWM_motor_going(uchar dir)
{
switch (dir)
{
case 0:DDR_PB0=1,_PB0=1;DDR_PB1=1,_PB1=0;break;
case 1:DDR_PB0=1,_PB0=0;DDR_PB1=1,_PB1=1;break;
default:break;
}
}
void Water_in(uchar ff)
{
switch(ff)
{
case 0:DDR_PC4=1;_PC4=0;break;
case 1:DDR_PC4=1;_PC4=1;break;
default:break;
}
}
void Water_out(uchar ff)
{
switch(ff)
{
case 0:DDR_PC5=1;_PC5=0;break;//寫語句
case 1:DDR_PC5=1;_PC5=1;break;//寫語句
default:break;
}
}
void get_clean(void)//洗衣
{
SET_PWMA(speed);//設置洗衣強弱模式
PWM_on;
wait_time(8);//定時8s正轉
PWM_motor_going(0);
while(1)
{
out_o_not;//判斷是否應該退出大循環
if(count==endcount)
break;
}
PWM_off;
wait_time(2);//定時2s停轉
while(1)
{
out_o_not;//判斷是否應該退出大循環
if(count==endcount)
break;
}
PWM_on;
wait_time(8);//定時8s反轉
PWM_motor_going(1);
while(1)
{out_o_not;//判斷是否應該退出大循環
if(count==endcount)
break;
}
PWM_off;
wait_time(3);//定時3s停轉
while(1)
{out_o_not;//判斷是否應該退出大循環
if(count==endcount)
break;
}
}
void get_dry()//脫水
{
PWM_on;
wait_time(10);//定時10s狠轉
while(1)
{out_o_not;//判斷是否應該退出大循環
if(count<endcount)
PWM_motor_going(0);
else break;
}
PWM_off;
wait_time(2);//定時2s停轉
while(count<endcount)
{
out_o_not;//判斷是否應該退出大循環
}
PWM_on;
wait_time(10);//定時10s狠轉
while(1)
{
out_o_not;//判斷是否應該退出大循環
if(count<endcount)
PWM_motor_going(1);
else break;
}
PWM_off;
wait_time(2);//定時2s停轉
while(count<endcount)
{
out_o_not;//判斷是否應該退出大循環
}
}
void handle_receive(uchar ceive[2])//串口接收處理程序
{
switch (ceive[0])
{
case start:flag_start=ceive[1];BBBuffer=1;break;
case wat:wat_lv=ceive[1];BBBuffer=1;break;
case heal:health=ceive[1];BBBuffer=1;break;
case cyc:cycle=ceive[1];BBBuffer=1;break;
case rep:replay=ceive[1];BBBuffer=1;break;
defult:break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -