Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
- // CONTROL AUTOMATICO LUCES PARA HYDROPONICO //
- // Version 2.0.3 //
- // CopyRight "EL GUAJIRIGALLO" //
- // CURRENT UPDATE WILL ALLOW CONTROLLER RECOVER AFTER //
- // BEEN THREE TIMES TRIGGERED DUE THE TEMPERATURE ISSUE //
- // IF TEMPERATURE SENSOR IS TRIGGERED THREE TIMES AND //
- // PROCESS STILL UNSTEADY CONTROLLER WILL BE SHUT-DOWN //
- //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
- #include <16f628A.h>
- #fuses NOWDT
- #fuses MCLR
- #fuses NOBROWNOUT
- #fuses NOLVP
- #USE DELAY(INTERNAL=4000000)
- #USE FAST_IO (A)
- #USE FAST_IO (B)
- //-"direccionamiento de ports-//
- #byte port_A = 0x05
- #byte port_B = 0x06
- #byte PCON = 0x8e
- #define data_pin PIN_B5
- //#define clock_pin PIN_B6
- //#define latch_pin PIN_B7
- #define latch_pin PIN_B6
- #define clock_PIN PIN_B7
- int contador=0;
- # int_ext
- void ext_isr()
- {
- clear_interrupt(int_ext);
- if( contador ==3 ){
- output_low(pin_b1);
- output_low(pin_b3);
- output_low(pin_b4);
- output_low(pin_a1);
- output_low(pin_a6);
- output_low(pin_b2);//shut douwn the whole prossesor
- do{
- for(int i=0;i<=1;i++){
- for(int j=0;j<=3;J++){
- output_toggle(PIN_A7);
- delay_ms(75);
- //output_low(pin_b2);//FAN ROOM A
- //output_low(pin_a6);//FAN ROOM B
- }
- delay_ms(150);
- }
- }while(1); //si cae aqui ya no sale mas.
- }
- contador++;
- switch (read_eeprom(0x1A)){
- case 0XFF:
- do{
- output_low(pin_b4);
- output_low(pin_a1);
- output_low(pin_a6);
- output_low(pin_b1);
- output_low(pin_b2);
- output_low(pin_b3);
- }while(!input(PIN_b0));
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_High(pin_b1);
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_high(pin_b2);
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_high(pin_b3);
- break;
- case 0X00:
- do{
- output_low(pin_b4);
- output_low(pin_a1);
- output_low(pin_a6);
- output_low(pin_b1);
- output_low(pin_b2);
- output_low(pin_b3);
- }while(!input(PIN_b0));
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_high(pin_b4);
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_high(pin_a6);
- for(int j=0;j<=60;j++){
- Delay_ms(1000);
- }
- output_high(pin_a1);
- break;
- }
- }
- /*-"Declaracion de funciones"-*/
- unsigned int seg(int num);
- void write_data(unsigned int number);
- void start(void);
- void Led_display1(void); // funsion para escribir una H half Zona
- void Led_display2(void); // funsion para escribr una F full Zona
- void RetarDo(void); // funsion para el retardo de apagado (30 seg) .
- void Retardo_M3(); //funsion para el
- void lumina_zona_a(void); //funsion que enciende la zona A
- void apaga_zona_a(void); //funsion que apaga la zona A
- void lumina_zona_b(void); //funsion que enciende la zona B
- void apaga_zona_b(void); //funsion que apaga la zona B
- void Waiting(void); //funsion para cuando se prenda la caja con la sonda de temperatura caliente
- /*-"Declaracion de VARIABLES Globales"-*/
- int const digitos[]={0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f}; //digitos a mostrar en el Display 7 segmentos
- short s;
- unsigned int j, digit;
- unsigned int z = 1;
- int number=0X00;
- VOID MAIN()
- {
- enable_interrupts(INT_EXT);
- ext_int_edge(H_TO_L);
- enable_interrupts(GLOBAL);
- SET_TRIS_A(0x3d);
- SET_TRIS_b(0x01);
- output_low(pin_A1); //apago todos los pines de salida
- output_low(pin_A6);
- output_low(pin_A7);
- output_b(0);
- //-"Rutina de comprovacion para Hard Reset o power off"-//
- if(!bit_test(PCON,1)){
- BIT_SET(PCON,1);
- RetarDo();
- goto ROOM_A;
- }else if(bit_test(PCON,1)){
- ////\\\///\\\////\\\\--"SELECT--"///\\\///\\\///\\\///\\\
- while(true)
- {
- WHILE(1)
- {
- if(input(PIN_A4))
- s = 1; // LAS TRES PRIMERAS INSTRUCTIONES DE ESTE WHLE LO QUE HACE ES VERIFICAR QUE LA TECLA NO ESTE PRECIONADA
- // si S==1 se procede con lo demas si S=0 se salta todo para comenzar de nuevo
- if(s ==1) { //
- if(input(PIN_A4) == 0){ //AQUI PRIMERO BORRO FLAG(S=0);INCRMENTO (I) Y ESCRIBO SU VALOR EN ADDREES 0X07
- s = 0;
- z++;
- //write_eeprom(0x07,z); //
- if(z >= 5) //SI A2 NO ESTA PRCIONADA COMPRUEVO QUE I NO ES MAYOR QUE NUEVE , SI LO ES LE DOY VALOR DE 1
- z = 1;
- write_eeprom(0x07,z);
- }
- // write_eeprom(0x07,z);
- }
- if(input(PIN_A3) == 0) {GOTO SELECT;}
- digit = seg(read_eeprom(0x07)); //Paso el valor a la fucion seg() y guardo el resultado en la variable digit
- write_data(digit);// escribo el caracter
- delay_ms(1);
- }
- ////////////////////////////////////////////////////////////
- SELECT:
- Led_display1(); //escribe una H means Half
- delay_ms(500);
- do{
- if(!input(pin_a2)){ //Pin !a2=Start/SW
- start();
- //delay_ms(50);
- goto ROOM_A;
- }
- }while(input(pin_a3));
- Led_display2(); //escribe una F means Full
- WRITE_EEPROM(0x03,0xff);
- WRITE_EEPROM(0x06,0xff); // Flag para leer al principio del programa para saber a que parte ir despues de un blackout
- // write_eeprom(0x00,0xff); // Flag paara arrancar con las todas las salidas activadas despues de un Reset
- delay_ms(500);
- do{
- if(!input(pin_a2)){ //Pin !a2=Start /SW
- start();
- //delay_ms(50);
- goto ROOM_A;
- }
- }while(input(pin_a3));
- }
- } //End of Select
- ROOM_A:
- if(!input(pin_b0)){Waiting();}
- if(!input(pin_a0)){
- WRITE_EEPROM(0x1A,0xff);
- lumina_zona_a();
- while(true){
- do{
- if(input(pin_a0)){
- WRITE_EEPROM(0x1A,0x00);
- apaga_zona_a();
- goto ROOM_B;
- }
- delay_ms(250);
- }while(input(pin_a2));
- output_toggle(PIN_A6);
- }
- }else
- ROOM_B:
- if(input(pin_a0)){
- WRITE_EEPROM(0x1A,0x00);
- lumina_zona_b();
- }
- while(1){
- do{
- if(!input(pin_a0)){
- WRITE_EEPROM(0x1A,0xff);
- apaga_zona_b();
- goto ROOM_A;
- }
- delay_ms(250);
- }while(input(pin_a2));
- output_toggle(PIN_b2);
- }
- } //End MAin
- /*********Funciones*********/
- unsigned int seg(int num) { //DIGITOS PARA MOSTRAR
- switch (num) {
- case 1 : return 0x06;
- case 2 : return 0x5b;
- case 3 : return 0x4f;
- case 4 : return 0x66;
- case 5 : return 0x6d;
- case 6 : return 0x7d;
- case 7 : return 0x07;
- case 8 : return 0x7f;
- case 9 : return 0x6f;
- //case 0 : return 0x3f;
- }
- }
- //FUNCION PARA ESCRBOR LOS DIGITOS EN EL DISPLAY
- void write_data(unsigned int number){
- for(j = 0x80; j > 0; j = j >> 1) {
- if(number & j) //and ligico entre j y number para detectar bit a bit 0 o 1 de number
- output_high(data_pin);
- else
- output_low(data_pin);
- output_high(clock_pin);
- output_low(clock_pin);
- }
- output_high(latch_pin);
- output_low(latch_pin);
- } //End
- void start()
- {
- int const AniMation[]={0x20,0x01,0x02,0x04,0x08,0x10,0x20};
- //int *p=0;
- //int w=0;
- int n=0;
- //int k=0;
- //w= AniMation[k];
- //p=&w;
- for(int x=1;x<=5;x++)
- {
- for(int j=0;j<=6;j++)
- {
- //k= (w+n);
- write_data(AniMation[n]);
- n++;
- Delay_ms(50);
- if(n>=7){n=0;}
- }
- //delay_ms(5);
- }
- }
- //Funsion que se encarga de mostrar que el sensor de temperatura esta mas alla del set point
- void Waiting(){
- output_low(pin_b1);
- output_low(pin_b2);
- output_low(pin_b3);
- output_low(pin_b4);
- output_low(pin_A1);
- output_low(pin_A7);
- do{
- //output_bit(pin_A6,1);
- output_low(pin_A7);
- delay_ms(750);
- //output_low(pin_A6);
- output_high(pin_A7);
- delay_ms(750);
- }while(!input(pin_b0));
- } //End
- void Led_display1(){
- for(int i=0;i<=1;i++){
- output_toggle(PIN_A7);
- delay_ms(250);
- }
- write_data(0x76);
- }
- void Led_display2(){
- for(int i=0;i<=1;i++){
- output_toggle(PIN_A7);
- delay_ms(250);
- }
- write_data(0x71);
- }
- void RetarDo(){
- for(int i=0;i<=9;i++){
- write_data(digitos[i]);
- delay_ms(3000);
- }
- }
- // Funcion que define el tiempo de Retardo entre las salidas-1,2,3,4,5,6
- void Retardo_M3(){
- int n=0;
- for(int x=1;x<=(read_eeprom(0x07));x++){
- for(int j=0;j<=60;j++){
- write_data(digitos[n]);
- n++;
- Delay_ms(1000);
- if(n>=10){n=0;}
- }
- }
- }
- void lumina_zona_a()
- {
- output_bit(pin_b1,1);
- //Delay_ms(1000);
- Retardo_M3();
- output_bit(pin_b2,1);
- //Delay_ms(1000);
- Retardo_M3();
- output_bit(pin_b3,1);
- write_data(seg(read_eeprom(0x07)));
- }
- void lumina_zona_b()
- {
- output_bit(pin_b4,1);
- Retardo_M3();
- //Delay_ms(1000);
- output_bit(pin_a6,1);
- Retardo_M3();
- //Delay_ms(1000);
- output_bit(pin_a1,1);
- write_data(seg(read_eeprom(0x07)));
- }
- void apaga_zona_a()
- {
- output_bit(pin_b1,0);
- RetarDo();
- output_bit(pin_b2,0);
- RetarDo();
- output_bit(pin_b3,0);
- }
- void apaga_zona_b()
- {
- output_bit(pin_b4,0);
- RetarDo();
- output_bit(pin_a6,0);
- RetarDo();
- output_bit(pin_a1,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement