Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <simples_2.h>
- int1 LD = 0;
- int chavefun = 0;
- void piscaled(int16 qtd, int16 temp)
- {
- for(int16 i=0; i < qtd; i++)
- {
- output_high(LED);
- delay_ms(temp);
- output_low(LED);
- delay_ms(temp);
- }
- }
- /*void bip(int16 temp)
- {
- for(int16 i = 0; i <= temp; i++)
- {
- output_high(buzzer);
- delay_us(250);
- output_low(buzzer);
- delay_us(250);
- }
- }*/
- void freio(int1 at)
- {
- output_toggle(at_freio);
- if (at == 1)
- {
- piscaled(5,500);
- }
- }
- void encher(int temp)
- {
- if(input(pressostato) == 0)
- {
- output_low(valvula1);
- output_low(valvula2);
- freio(1);
- do{
- output_high(motor1);
- output_low(motor2);
- delay_ms(500);
- output_low(motor1);
- output_low(motor2);
- piscaled(temp,500);
- output_high(motor1);
- output_low(motor2);
- delay_ms(500);
- output_low(motor1);
- output_low(motor2);
- piscaled(temp,500);
- }while(input(pressostato) == 0);
- output_high(motor1);
- output_low(motor2);
- delay_ms(800);
- output_low(motor1);
- output_low(motor2);
- output_high(valvula1);
- output_high(valvula2);
- freio(0);
- }
- }
- void bater(int16 batidas, int16 intervalo, int mult)
- {
- for(int x=0; x < mult; x++)
- {
- for (int16 i=0; i < batidas; i++)
- {
- output_high(motor1);
- output_low(motor2);
- delay_ms(500);
- output_low(motor1);
- output_low(motor2);
- delay_ms(250);
- output_low(motor1);
- output_high(motor2);
- delay_ms(500);
- output_low(motor1);
- output_low(motor2);
- delay_ms(intervalo);
- }
- }
- }
- void molho(int16 intervalom, int mult)
- {
- for(int x=0; x < mult; x++)
- {
- for(int16 x=0; x < intervalom; x++)
- {
- output_high(LED);
- delay_ms(500);
- output_low(LED);
- delay_ms(500);
- }
- }
- }
- void exaustao(int16 duracao)
- {
- output_low(bomba);
- piscaled(duracao,500);
- output_high(bomba);
- }
- void enxague(int duracao)
- {
- freio(1);
- //int dividir = (duracao/10);
- int dividir = (duracao/2);
- //int j = 0;
- for(int i=0; i < duracao; i++)
- {
- if(i == dividir)
- {
- output_low(bomba);
- output_low(valvula1);
- output_low(valvula2);
- }
- output_high(motor1);
- piscaled(3,500);
- output_low(motor1);
- piscaled(7,500);
- }
- freio(0);
- output_high(bomba);
- output_high(valvula1);
- output_high(valvula2);
- piscaled(1,500);
- }
- void centrifugar(int16 duracao)
- {
- freio(1);
- output_low(bomba);
- piscaled(1,500);
- output_high(motor1);
- piscaled(duracao,500);
- output_low(motor1);
- output_high(bomba);
- piscaled(10,500);
- freio(0);
- }
- /*void funcao1()
- {
- encher(20);
- for(int i=0; i < 6; i++)
- {
- bater(86,500);
- molho(150);
- }
- exaustao(300);
- centrifugar1(300);
- centrifugar2(300);
- encher(20);
- for(int x=0; x < 6; x++)
- {
- bater(86,500);
- molho(150);
- }
- exaustao(600);
- centrifugar1(300);
- centrifugar2(600);
- }*/
- #INT_TIMER1
- void TIMER1_isr(void) // 8:1 500ms
- {
- set_timer1 (3036); //Iniciar o Timer1 em
- //t1++;
- if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 1) // 0 - inicio/fim
- {
- chavefun = 0;
- }
- if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 1) // 1 - N/C
- {
- chavefun = 1;
- }
- if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 1) // 2 - N/C
- {
- chavefun = 2;
- }
- if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 1) // 3 - N/C
- {
- chavefun = 3;
- }
- if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 0) // 4 - Molho Longo + agitação
- {
- chavefun = 4;
- }
- if(input(chave1) == 1 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 0) // 5 -
- {
- chavefun = 5;
- }
- if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 0) // 6 - molho + agitação
- {
- chavefun = 6;
- }
- if(input(chave1) == 1 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 0) // 7 -
- {
- chavefun = 7;
- }
- if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 0) // 8 - molho curto + agitação
- {
- chavefun = 8;
- }
- if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 0) // 9 -
- {
- chavefun = 9;
- }
- if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 0) // 10 - agitação
- {
- chavefun = 10;
- }
- if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 0) // 11 -
- {
- chavefun = 11;
- }
- if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 1 && input(chave4) == 1) // 12 - enxágue
- {
- chavefun = 12;
- }
- if(input(chave1) == 0 && input(chave2) == 0 && input(chave3) == 0 && input(chave4) == 1) // 13 -
- {
- chavefun = 13;
- }
- if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 0 && input(chave4) == 1) // 14 - centrifugação
- {
- chavefun = 14;
- }
- if(input(chave1) == 0 && input(chave2) == 1 && input(chave3) == 1 && input(chave4) == 1) // 15 -
- {
- chavefun = 15;
- }
- if(input(power) == 0)
- {
- switch(LD)
- {
- case 0:
- LD = 1;
- break;
- case 1:
- reset_cpu();
- break;
- }
- }
- }
- void main()
- {
- output_high(bomba);
- output_high(at_freio);
- output_high(motorchave);
- output_high(valvula1);
- output_high(valvula2);
- output_low(motor1);
- output_low(motor2);
- output_low(buzzer);
- piscaled(1,500);
- //bip(1000);
- setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //524 ms overflow
- enable_interrupts(GLOBAL);
- enable_interrupts(INT_TIMER1);
- while(TRUE)
- {
- if (LD == 1)
- {
- delay_ms(200);
- //bip(500);
- output_low(LED);
- switch(chavefun)
- {
- case 0: //maquina desligada ou inicio/fim do processo
- //chavefun = 1;
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 0);
- output_high(motorchave);
- break;
- case 1: // posição sem função
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 1);
- output_high(motorchave);
- break;
- case 2: // posição sem função
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 2);
- output_high(motorchave);
- break;
- case 3: // posição sem função, passa direto...
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 3);
- output_high(motorchave);
- break;
- case 4: // molho longo (30 minutos)
- encher(40);
- bater(172,500,1);
- molho(300,6);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 4);
- output_high(motorchave);
- break;
- case 5: // continuação do molho longo (30 minutos)
- encher(40);
- bater(172,500,1);
- molho(300,6);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 5);
- output_high(motorchave);
- break;
- case 6: // molho (15 minutos)
- encher(20);
- bater(172,500,1);
- molho(300,3);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 6);
- output_high(motorchave);
- break;
- case 7: // continuação molho (+15 minutos)
- encher(20);
- bater(172,500,1);
- molho(300,3);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 7);
- output_high(motorchave);
- break;
- case 8: // molho cuto (10 minutos)
- encher(20);
- bater(86,500,1);
- molho(300,2);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 8);
- output_high(motorchave);
- break;
- case 9: // continuação do molhor curto (+10 minutos)
- encher(20);
- bater(86,500,1);
- molho(300,2);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 9);
- output_high(motorchave);
- //bip(500);
- break;
- case 10: // agitação por 20 minutos
- encher(20);
- bater(172,500,4);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 10);
- output_high(motorchave);
- break;
- case 11: // continuação da agitação (+ 20 minutos)
- encher(20);
- bater(172,500,4);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 11);
- output_high(motorchave);
- //bip(500);
- break;
- case 12: // enxágue (extração da agua (5 minutos)
- exaustao(180);
- enxague(15);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 12);
- output_high(motorchave);
- break;
- case 13: // continuação do anchague (começa a centrifugar jogando agua dentro e fora) +5 minutos
- encher(20);
- bater(172,500,6);
- exaustao(300);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 13);
- output_high(motorchave);
- //bip(500);
- break;
- case 14: // inicio da centrifugação (começa a centrifugar jogando agua dentro e fora) +5 minutos
- enxague(15);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 14);
- output_high(motorchave);
- break;
- case 15: // centrfugação por 10 minutos.
- centrifugar(600);
- output_low(motorchave);
- do
- {
- piscaled(1,250);
- }
- while(chavefun == 15);
- output_high(motorchave);
- //bip(1000);
- LD = 0;
- break;
- }
- }
- else if (LD == 0)
- {
- delay_ms(50);
- output_high(LED);
- }
- }
- }
Add Comment
Please, Sign In to add comment