Moderadores: andre_luis, 51, guest2003, Renie
void main()
{
int x;
x=0;
for ( ;; ) // looping infinito
{
delay_ms(1000); // delay de 1 segundo
if ( x==0 )
{ // enche de agua
}
if ( x == 300 )
{ // 5 minutos.... faz o que tem que fazer qdo for 5 minutos
}
x++; // incrementa
}
}
if ( funcao==1 )
{
Switch ( estado )
{
case ENCHE_DE_AGUA : { ... }
case OPERA_5MIN : { ... }
case PARA_3MIN : { ... }
case OPERA_4MIN : { ... }
case PARA_3MIN : { ... }
case DESCARTA_AGUA_1A_VEZ: { ... }
case ENCHE_PARA_ENXAGUAR : { ... }
case OPERA_6MIN: { ... }
case DESCARTA_AGUA_2A_VEZ: { ... }
case SINALIZA_TERMINO : { ... }
}
}
enum {
FIM,
ESPERA_2MIN = 2,
ESPERA_3MIN,
ESPERA_4MIN,
ESPERA_5MIN,
ESPERA_6MIN,
LIGAR_MOTOR,
DESLIGAR_MOTOR,
COMPLETAR_AGUA,
DESCARTAR_AGUA,
} STEPS;
const unsigned char funcao1[] = {
COMPLETAR_AGUA,
LIGAR_MOTOR,
ESPERA_5MIN,
DESLIGAR_MOTOR,
ESPERA_3MIN,
LIGAR_MOTOR,
ESPERA_4MIN,
DESLIGAR_MOTOR,
ESPERA_3MIN,
DESCARTAR_AGUA,
COMPLETAR_AGUA,
LIGAR_MOTOR,
ESPERA_6MIN,
DESCARTAR_AGUA,
FIM
};
const unsigned char funcao2[] = {
COMPLETAR_AGUA,
LIGAR_MOTOR,
ESPERA_5MIN,
DESLIGAR_MOTOR,
ESPERA_2MIN,
LIGAR_MOTOR,
ESPERA_3MIN,
DESLIGAR_MOTOR,
ESPERA_2MIN,
DESCARTAR_AGUA,
FIM
};
void executar(const unsigned char *passos);
int main(){
while(1){
if(BOTA01){
executar(funcao1);
} else if(BOTA02){
executar(funcao2);
}
}
}
void executar(const unsigned char *passos){
unsigned int i;
for(; *passos; passos++){
switch(*passos){
case ESPERA_2MIN:
case ESPERA_3MIN:
case ESPERA_4MIN:
case ESPERA_5MIN:
case ESPERA_6MIN:
i = 60 * (*passos);
while(i--) delay_ms(1000);
break;
case LIGAR_MOTOR:
// ...
break;
case DESLIGAR_MOTOR:
// ...
break;
case COMPLETAR_AGUA:
// Ativar solenóide e aguardar o nível ser completado
break;
case DESCARTAR_AGUA:
// Ativar solenóide e aguardar esvaziamento
break;
default: // FIM
// Acionar sirene
return;
}
}
}
#define nivel_agua pin_a2
#define programa_1 pin_a3
#define programa_2 pin_a0
#define encher_tanquinho pin_b3
#define esvaziar_tanquinho pin_b0
#define alarme pin_b5
#define rodar_motor pin_b4
int1 a=0, b=0, c=0;
int16 func1=0, func2=0, func3=0;
int contagem_t0=0;
int processo_normal, processo_enxague;
static boolean led;
#int_RTCC
void RTCC_isr(void) {
set_timer0 (131-get_timer0());
contagem_t0++;
if(contagem_t0==125)
{
contagem_t0=0;
led=!led;
output_bit(pin_a6,led);
if(func1==2000)
{
func1=0;
}
else{
func1++;
}
if(func2==3000)
{
func2=0;
}
else{
func2++;
}
if(func3==1000)
{
func3=0;
}
else{
func3++;
}
}
}
void processo_normal(void){
while(!input(programa_1))
for(;;){
a=1;
//func1=0;
//programa_1==1;
if(a==1 && func1>=0 && func1<=30)
{
output_high(rodar_motor);
}
if(a==1 && func1>=31 && func1<=60 )
{
output_low(rodar_motor);
}
if(a==1 && func1>=61 && func1<=100 )
{
output_high(rodar_motor);
}
if(a==1 && func1>=101 && func1<=120 )
{
output_low(rodar_motor);
}
if(a==1 && func1>=121 && func1<=160 )
{
output_high(rodar_motor);
}
if(a==1 && func1>=161 && func1<=180 )
{
output_low(rodar_motor);
}
if(a==1 && func1>=181 && func1<=220 )
{
output_high(rodar_motor);
}
if(a==1 && func1>=221 && func1<=250 )
{
output_low(rodar_motor);
}
if(a==1 && func1>=251 && func1<=270 )
{
output_high(rodar_motor);
}
if(a==1 && func1>=271 && func1<=280 )
{
output_low(rodar_motor);
}
if(a==1 && func1>=281 && func1<=460 )
{
output_high(esvaziar_tanquinho);
}
if(a==1 && func1>=461 && func1<=465 )
{
output_low(esvaziar_tanquinho);
}
if(a==1 && func1>=466 && func1<=467 )
{
output_high(alarme);
delay_ms(250);
output_low(alarme);
delay_ms(250);
output_high(alarme);
delay_ms(250);
output_high(alarme);
delay_ms(250);
output_low(alarme);
delay_ms(250);
output_high(alarme);
delay_ms(250);
}
if(a==1 && func1>=468 && func1<=469 )
{
output_low(alarme);
}
if(a==1 && func1>=470 && func1<=471 )
{
output_high(alarme);
}
if(a==1 && func1>=472 && func1<=473 )
{
output_low(alarme);
}
if(a==1 && func1>=474 && func1<=475 )
{
output_high(alarme);
}
if(a==1 && func1>=476 && func1<=477 )
{
output_low(alarme);
}
}
break;
}
//}
void processo_enxague(void){
while(!input(programa_2))
for(;;){
b=1;
//func2=0;
//programa_2==1;
if(b==1 && func2>=0 && func2<=10)//roda 10 segundos
{
output_high(rodar_motor);
}
if(b==1 && func2>=11 && func2<=20 )//para 10 segundos
{
output_low(rodar_motor);
}
if(b==1 && func2>=21 && func2<=40 )//roda 20 segundos
{
output_high(rodar_motor);
}
if(b==1 && func2>=41 && func2<=60 )//para 20 segundos
{
output_low(rodar_motor);
}
if(b==1 && func2>=61 && func2<=80 )// roda 20 segundos
{
output_high(rodar_motor);
}
if(b==1 && func2>=81 && func2<=100 )// para 20 segundos
{
output_low(rodar_motor);
}
if(b==1 && func2>=101 && func2<=120 )// roda 20 segundos
{
output_high(rodar_motor);
}
if(b==1 && func2>=121 && func2<=140 )// para 20 segundos
{
output_low(rodar_motor);
}
if(b==1 && func2>=141 && func2<=160 ) // roda 20 segundos
{
output_high(rodar_motor);
}
if(b==1 && func2>=161 && func2<=170 )// para 10 segundos
{
output_low(rodar_motor);
}
if(b==1 && func2>=171 && func2<=350 )
{
output_high(esvaziar_tanquinho);
}
if(b==1 && func2>=351 && func2<=355 )
{
output_low(esvaziar_tanquinho);
output_high(encher_tanquinho);
}
if(!input(nivel_agua)==0){
output_low(encher_tanquinho);
c=1;
func3=0;
set_timer0(0);
}
if(c==1 && func3>=0 && func3<=10)
{
output_high(rodar_motor);
}
if(c==1 && func3>=11 && func3<=20)
{
output_low(rodar_motor);
}
if(c==1 && func3>=21 && func3<=30)
{
output_high(rodar_motor);
}
if(c==1 && func3>=0 && func3<=10)
{
output_low(rodar_motor);
}
break;
}
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
set_timer0(131);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
while(true){
output_low(rodar_motor);
if(input(programa_1)==0){
set_timer0(0);
func1=0;
processo_normal();
}
if(input(programa_2)==0){
set_timer0(0);
func2=0;
processo_enxague();
}
}
}
carlucio escreveu:quando se aciona uma função e quando a mesma chega ao final, se eu quiser utilizar a outra função o mesmo não aceita e tem de resetar o mesmo. O que esta faltando ou errado?
for (; *passos; passos++) {
if ( (*passos == ESPERA_2MIN) || (*passos == ESPERA_3MIN) || (*passos == ESPERA_4MIN) || (*passos == ESPERA_5MIN) || (*passos == ESPERA_6MIN) ) {
i = 60 * (*passos);
while(i--) delay_ms(1000);
} else if (*passos == LIGAR_MOTOR) {
// ...
} else if (*passos == DESLIGAR_MOTOR) {
// ...
} else if (*passos == COMPLETAR_AGUA) {
// Ativar solenóide e aguardar o nível ser completado
} else if (*passos == DESCARTAR_AGUA) {
// Ativar solenóide e aguardar esvaziamento
} else { // FIM
// Acionar sirene
return;
}
}
void executar(const unsigned char *passos){
unsigned int i;
for(; *passos; passos++){ // Incrementa se 'passos' for diferente de 'FINAL'. (FINAL = 0)
switch(*passos){
case ESPERA_2MIN: // Se 'passos' for igual a ESPERA_2MIN, executará desde aqui, até o 'break'
case ESPERA_3MIN: // ESPERA_2MIN = 2 ~ ESPERA_6MIN = 6
case ESPERA_4MIN:
case ESPERA_5MIN:
case ESPERA_6MIN:
i = 60 * (*passos); // Se 'passos' for igual a ESPERA_4MIN, i = 240.
while(i--) delay_ms(1000); // Enquanto 'i' for maior que 0, espera 1 segundo. Após, decrementa 'i'.
break;
case LIGAR_MOTOR:
// ...
break;
case DESLIGAR_MOTOR:
// ...
break;
case COMPLETAR_AGUA:
// Ativar solenóide e aguardar o nível ser completado
break;
case DESCARTAR_AGUA:
// Ativar solenóide e aguardar esvaziamento
break;
default: // FIM
// Acionar sirene
return;
}
}
}
passos = 1;
switch (passos) { // <- Vai pular para a linha "case 1"
case 0:
case 1: // <- Continua executando a partir daqui
break;
case 2:
case 3:
}
passos = 'A';
switch (passos) { // <- Vai pular para a linha "case 'A'"
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 'A': // <- Continua executando a partir daqui
}
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante