Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-systema para riego automatico con manguera y regadera-*/
- /*-en este update el display muestra el rate flow en litros. -*/
- # include <16F877A.h>
- #include <stdbool.h>
- //# include <ios.h>
- # use Delay(clock=4000000)
- # use Fast_io(c)
- # fuses XT,NOWDT
- #USE FAST_IO (A)
- #USE FAST_IO (B)
- //-"direccionamiento de ports-//
- #byte port_A = 0x05
- #byte port_B = 0x06
- #byte port_c = 0x07
- #byte port_d = 0x08
- #byte port_e = 0x09
- #byte PCON = 0x8e
- #define data_pin PIN_b1
- #define clock_pin PIN_b4
- #define latch_pin PIN_b3
- /*-"Declaracion de funciones"-*/
- //int32 seg(int32 num);
- void write_data(int16 disply );
- void write_Nunbers(int16 numbers[]);
- Void AnimationDisply(void);
- //void write_Nunbers(void);
- void Retardo_30seg(void);
- void timer_on(void);
- //void timer_off(void);
- /*-"Declaracion de VARIABLES Globales"-*/
- int const animationNun=0b00000000000110; //variable usada para la animacion del disply cuando hay un reset por hardware
- int16 const digitos[]={0x3f3f,0x4f3f,0x7d3f // Digitos para mostrar por Display del 0 al 29
- ,0x6f3f,0x7171,0x7171,
- 0x7171,0x7171,0x7171,0x7171,0x3f5b, 0x065b,0x5B5b,0x4f5b,
- 0x665b,0x6d5b,0x7d5b,0x075b,0x7f5b,0x6f5b
- };
- int16 const RateFlow[]={0x383f,0x3806,0x385B,0x384f,0x3866,0x386d,0x387d,0x3807,0x387f,0x386f}; // caracteres o-li to 9-li a mostrar en el dysplay
- int const EE_Address[]={0x00,0x01}; // Registro de la eeprom donde se guarda el tiempo de docificacion
- int16 TimerOn[]={0x00,0x00,0x0600,0x3100,0x4031,0x543f,0x543f,0x543f}; //variable usada para animation de caracteres t-on
- int16 TimerOff[]={0x00,0x00,0x0600,0x3100,0x4031,0x715c,0x715c,0x715C};//variable usada para animation de caracteres t-off
- short i;
- int g=0;
- int z =0;
- int n=0x00;
- int j=0;
- int w=0;
- //short boot=1;
- VOID MAIN() {
- SET_TRIS_A(0x07);
- SET_TRIS_b(0x01);
- SET_TRIS_c(0x00);
- SET_TRIS_d(0x00);
- SET_TRIS_e(0x00);
- output_b(0xff);
- output_HIGH(pin_B6);
- output_c(0x00);
- output_d(0x00);
- output_e(0x00);
- write_eeprom(0x00,0);
- write_eeprom(0x01,0);
- if(!bit_test(PCON,1)){
- BIT_SET(PCON,1);
- do
- {
- write_data(0x543f);
- delay_ms(100);
- g++;
- }while(G<=10);//me paro aqui un segundo
- Goto T_forward;
- }else if (bit_test(PCON,1))
- {
- for(int i=0;i<=15;i++)
- {
- write_eeprom(i,0x00);//limpio la eeprom
- }
- }
- //while(true)
- do{
- if(input(pin_b0) == 0) {goto override;}
- AnimationDisply();
- output_Toggle(pin_B6);
- }while(input(pin_a1)); // preciono la Entrada A1 para selecionar el timer A setiar
- output_high(pin_B6); // encienfo fijo el led de power
- T_forward: // etiqueta T_fowar para regresar de la parte donde le doy valor al timer
- while(true)//(Linea 98 to 126) Rutina para Seleccionar Rate Flow o el Tiempo entere cada riego.
- {
- do{
- if(!input(pin_a0) || (!input(pin_a2))) {GOTO set_timer;} // si pin A0 o Pin_a1 ==0 ir al timer para add o disminuir Tiempo
- if(input(pin_b0) == 0) {goto Automatic;}
- }while(input(pin_a1));
- if(w==0)
- {
- write_Nunbers(Timeron);
- n=0;
- Z=(read_eeprom(0x00));
- }else{
- write_Nunbers(TimerOff);
- n=1;
- Z=(read_eeprom(0x01));
- }
- delay_ms(500);
- if(n==0)
- {
- write_data(RateFlow[z]);
- }else{
- write_data(digitos[(read_eeprom(w))]);
- }
- w++;
- if(w>1){w=0;}
- }
- //Rutina para comenzar la temporizacion del riego.
- Automatic:
- write_Nunbers(Timeron);
- delay_ms(1000);
- output_high(pin_c7);// Salida donde que activa el contactor para la water poomp
- Retardo_30seg();
- while(1){
- OpenValvula:
- write_Nunbers(Timeron);
- output_high(pin_D4); // salida para acivar la valvula de 24volt
- delay_ms(1000);
- output_low(pin_c5); // Red led used to disply manual overide
- for(int i=1;i<=read_eeprom(0x00);i++)
- {
- for(int j=0;j<=11;j++)
- {
- if(input(pin_b0) == 0) {goto override;}
- delay_ms(500);
- }
- }
- write_Nunbers(TimerOff);
- output_low(pin_D4);
- delay_ms(1000);
- output_low(pin_D0);
- for (int h=1;h<=read_eeprom(0x01);h++)
- {
- for(int x=0;x<=3;x++)
- {
- if(input(pin_b0) == 0) {goto override;}
- delay_ms(1000);
- }
- }
- if(input(pin_b0) == 0) {goto override;}
- }
- override:
- while(true)
- {
- do {
- if(!input(pin_a1))
- {
- goto Automatic;
- }
- output_Toggle(pin_c5);
- delay_ms(250);
- }while(input(pin_b0));
- write_data(0x543f);//display t-on.
- output_low(pin_D4);//apagar valvula de riego.
- output_high(pin_c7);//encender water poomp.
- // delay_ms(1000);
- //output_high(pin_D0);
- output_high(pin_c5);
- // write_data(0x543f);
- delay_ms(450);
- do {
- output_Toggle(pin_c5);
- delay_ms(250);
- if(!input(pin_a1))
- {
- goto OpenValvula;
- }
- }while(input(pin_b0));
- write_data(0x715c);//display t-off.
- delay_ms(50);
- output_low(pin_D4);//apagar valvula de riego.
- output_low(pin_c7);//apagar water poomp.
- //delay_ms(50);
- // output_low(pin_D0);
- output_high(pin_c5);
- write_data(0x715c);
- delay_ms(450);
- }
- set_timer:
- WHILE(1)
- {
- if(input(pin_a0) == 0)
- {
- if (z <=0)
- {
- z = 9; //z = 5;
- }
- z--;
- delay_ms(100);
- }
- if(input(pin_a2) == 0)
- {
- if (z >=9)
- {
- z = 0;
- }
- z++;
- delay_ms(100);
- }
- write_eeprom(EE_Address[n],z); // escribo en la EE el valor decimal de Z en direcion N, N puede tomar valores desde 0 o 1....
- if(!input(pin_a1)) {GOTO T_forward;} //llamado desde la rutina que seleciona el numero de timer....
- if(input(pin_b0) == 0) {goto Automatic;}
- if(n==0){
- write_data(RateFlow[z]);// esta linea para mostrar los litros.....
- }else{
- write_data(digitos[z]); // esta linea es para mostrar el tiempo ensegundos.....
- }
- delay_ms(250);
- }
- // }
- }// End del Main
- //FUNCION PARA ESCRBIR LOS DIGITOS EN EL DISPLAY
- void write_data( int16 disply){
- for( int16 j = 0x8000; j > 0; j = j >> 1) {
- if(disply & j) //and ligico entre j y number para detectar bit a bit 0 o 1 de number
- output_high(data_pin);
- //output_low(data_pin);
- //output_high(clock_pin);
- else
- output_low(data_pin);
- output_high(clock_pin);
- output_low(clock_pin);
- }
- output_high(latch_pin);
- output_low(latch_pin);
- }
- Void AnimationDisply()
- {
- for(long j=0;j<=1275;j++)
- {
- if(j<=0 && j<=125){write_data(animationNun<<3);} //Primera barra
- if(j>125 && j<=250){write_data(animationNun);}//Segunda Barra
- if(j>250 && j<=375){write_data(animationNun<<11);}//Tercera Barra
- if(j>375 && j<=500 ) {write_data(animationNun<<8);}//Cuarta Barra
- if(j>500 && j<=625){write_data(0x00);}//
- if(j>625 && j<=750){write_data(animationNun<<8);}//tersera Barra
- if(j>750 && j<=825){write_data(animationNun<<11);}//2da barra
- if(j>825 && j<=975 ){write_data(animationNun);}//1ra barra
- if(j>975 && j<=1125){write_data(animationNun<<3);}//1ra barra
- if(j>1125 && j<=1274 ){write_data(0x00);}
- delay_ms(1);
- }
- }
- void Retardo_30seg(){
- for (int i=0;i<=10;i++){
- for(long j=0;j<=999;j++){
- //if(input(pin_a2) == 0) {goto override;}
- delay_ms(1);
- }
- }
- }
- void timer_on(){
- for (int i=0;i<=read_eeprom(0x00);i++){
- for(int j=0;j<=11;j++){
- //if(input(pin_a2) == 0) {goto override;}
- delay_ms(500);
- }
- j=0;
- }
- }
- void timer_off(){
- for (int i=1;i<=read_eeprom(0x01);i++){
- for(long j=0;j<=20;j++){
- //if(input(pin_a2) == 0) {goto override;}
- delay_ms(500);
- }
- j=0;
- }
- }
- // Funcion Que Hace el Efecto que Los Numero mayor de 9 se desplacen de Derecha a Isquierda //
- void write_Nunbers(int16 numbers[]){ //
- for(int j=0;j<=7;j++){
- write_data(numbers[j]);
- delay_ms(200);
- }
- j=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement