📄 app.c
字号:
/******************************************************************************************
App.c (v1.0)
-------------------------------------------------------------------------------------
This code is from the book:
"Embedded Internet: TCP/IP Basics, Implementation and Applications" by Sergio Scaglia
[Pearson Education, 2006 - ISBN: 0-32-130638-4]
This code is copyright (c) 2006 by Sergio Scaglia, and it may only be used for educational
purposes. For commercial use, please contact me at sscaglia@intramarket.com.ar
For more information and updates, please visit www.embeddedinternet.org
******************************************************************************************/
#include "app.h"
#include "timer.h"
#include "hardware.h"
#include <iolpc2129.h>
#include <stdio.h>
char valve1, valve2, heater, cycle, state, ledapp;
unsigned int liquid, temp;
void ledappOn(void) {
IO0CLR = LEDAPP;
}
void ledappOff(void) {
IO0SET = LEDAPP;
}
void app_init(void) {
valve1=OFF;
valve2=OFF;
heater=OFF;
cycle=NO;
state=STOP;
liquid=0;
temp=15;
ledapp=0;
IO0DIR |= LEDAPP;
IO0SET = LEDAPP;
timer_start(ledapptimer, 500);
timer_start(buttontimer, 200);
}
void app_process(void) {
if (BUTTON1 && state == STOP)
state = STARTED;
if (BUTTON2 && timer_expired(buttontimer)) {
timer_start(buttontimer, 200);
if (cycle)
cycle = 0;
else
cycle = 1;
}
switch(state) {
case STARTED:
valve1 = ON;
state = FILL;
timer_start(apptimer, 1000);
break;
case FILL:
if (valve1 == ON && timer_expired(apptimer)) {
liquid++;
timer_start(apptimer, 1000);
}
if (liquid == 30) {
valve1 = OFF;
heater = ON;
state = HEAT;
timer_start(apptimer, 1000);
}
if (timer_expired(ledapptimer)) {
if (ledapp) {
ledapp=0;
ledappOff();
}else {
ledapp=1;
ledappOn();
}
timer_start(ledapptimer, 500);
}
break;
case HEAT:
if (heater == ON && timer_expired(apptimer)) {
temp++;
timer_start(apptimer, 1000);
}
if (temp == 45) {
heater = OFF;
valve2 = ON;
state = EMPTY;
timer_start(apptimer, 1000);
}
if (timer_expired(ledapptimer)) {
if (ledapp) {
ledapp=0;
ledappOff();
timer_start(ledapptimer, 1000);
}else {
ledapp=1;
ledappOn();
timer_start(ledapptimer, 250);
}
}
break;
case EMPTY:
if (valve2 == ON && timer_expired(apptimer)) {
liquid--;
temp--;
timer_start(apptimer, 1000);
}
if (liquid == 0) {
valve2 = OFF;
state = STOP;
ledapp=0;
ledappOff();
if (cycle)
state = STARTED;
break;
}
if (timer_expired(ledapptimer)) {
if (ledapp) {
ledapp=0;
ledappOff();
}else {
ledapp=1;
ledappOn();
}
timer_start(ledapptimer, 50);
}
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -