TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: f-traxx en 14 de Octubre de 2010, 13:28:17

Título: problema RC2 PIC16F610
Publicado por: f-traxx en 14 de Octubre de 2010, 13:28:17
Hola buenas despues de estar un tiempo si hacer preguntas aqui estoy otra vez incordiando, lo que me pasa ahora es que estoy probando un trozo de codigo y se me encalla en una parte "realmente facil" he sustituido todo mi trozo de codigo para hacer que en la parte que falla, me encienda un Led o me lo apague, el problema es que el PIN C2 pasa de mi completamente...

aqui os dejo el codigo haber si me podeis ayuadar a descubrir el problema.

Código: C
  1. #include <16F610.h>
  2.  
  3. #FUSES NOWDT                    //No Watch Dog Timer
  4. #FUSES INTRC_IO                    //Internal RC Osc, no CLKOUT
  5. #FUSES NOPROTECT                //Code not protected from reading
  6. #FUSES IOSC4                    //INTOSC speed 4 MHz
  7. #FUSES NOMCLR                   //Master Clear pin used for I/O
  8. #FUSES NOBROWNOUT               //No brownout reset
  9. #FUSES NOPUT                    //No Power Up Timer
  10.  
  11. //#byte cm1con0 = 0x1a
  12. //#byte cm2con0 = 0x1b
  13.  
  14. #bit A0= 0x5.0
  15. #bit A1= 0x5.1
  16. #bit A2= 0x5.2
  17. #bit A3= 0x5.3
  18. #bit A4= 0x5.4
  19. #bit A5= 0x5.5
  20. #bit C0= 0x7.0
  21. #bit C1= 0x7.1
  22. //#bit C2= 0x7.2
  23. #bit C3= 0x7.3
  24. #bit C4= 0x7.4
  25. //#bit C5= 0x7.5
  26.  
  27. #define rebre  PIN_C2     //Si camvio esto por C5, el programa funciona perfectamente, ose quando pulso mi boton se apaga y
  28.                                     //quando lo suelto se enciende. Poniendo C2 todo el rato esta encendido.
  29.  
  30. #use delay(clock=4000000)
  31.  
  32. #use fast_IO(A)
  33. #use fast_IO(C)
  34.  
  35. void main()
  36. {
  37.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  38.    setup_timer_1(T1_DISABLED);
  39.    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
  40.    //Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
  41.    set_tris_a(0b000000);
  42.    set_tris_c(0b111111);
  43.    
  44.    //cm1con0=0b00000000;
  45.    //cm2con0=0b00000000;
  46.    
  47.    while (true)
  48.    {
  49.       if (input(rebre))
  50.       {
  51.       A0=0;
  52.       }
  53.       if (!input(rebre))
  54.       {
  55.       A0=1;
  56.       //delay_ms(200);
  57.       //A0=1;
  58.       }  
  59.    }
  60. }

Haber si puedo encontrar el fallo... gracias a todos de antemano :)
Título: Re: problema RC2 PIC16F610
Publicado por: f-traxx en 18 de Octubre de 2010, 06:00:01
Ya hemos encotrado el fallo que habia, lo que pasava es que el registro ANSEL viene predefinido con 11111111 y para que se pusieran las entradas como digitales, tenia que estar todo a 0.
Aqui dejo el codigo por si alguien tiene problemas con inicializar las variables de este pic
Código: C
  1. #include <16F610.h>
  2.  
  3. #FUSES NOWDT                    //No Watch Dog Timer
  4. #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
  5. #FUSES NOPROTECT                //Code not protected from reading
  6. #FUSES IOSC4                    //INTOSC speed 4 MHz
  7. #FUSES NOMCLR                   //Master Clear pin used for I/O
  8. #FUSES NOBROWNOUT               //No brownout reset
  9. #FUSES NOPUT                    //No Power Up Timer
  10.  
  11. #use delay(clock=4000000)
  12.  
  13. #use fast_IO(A)
  14. #use fast_IO(C)
  15.  
  16. #bit A0= 0x5.0
  17. #bit A1= 0x5.1
  18. #bit A2= 0x5.2
  19. #bit A3= 0x5.3
  20. #bit A4= 0x5.4
  21. #bit A5= 0x5.5
  22. #bit C0= 0x7.0
  23. #bit C1= 0x7.1
  24. #bit C2= 0x7.2
  25. #bit C3= 0x7.3
  26. #bit C4= 0x7.4
  27. #bit C5= 0x7.5
  28. #define rebre  PIN_C2
  29.  
  30. #byte ansel=0x91  //Dirección de memoria del registro ANSEL
  31.  
  32. void main()
  33. {
  34.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  35.    setup_timer_1(T1_DISABLED);
  36.    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
  37.    
  38.    ANSEL=00000000; // Establir com digitals
  39.    
  40.    set_tris_a(0b111000);
  41.    set_tris_c(0b111100);
  42.    output_a(0x00);
  43.    output_c(0x00);
  44.    
  45.    while (true)
  46.    {
  47.       if (input(rebre))
  48.       {
  49.       A0=0;
  50.       }
  51.       if (!input(rebre))
  52.       {
  53.       A0=1;
  54.       }  
  55.    }
  56. }

Dar las gracias por toda la ayuda prestada a toda la gente de

http://www.aquihayapuntes.com/foro/viewtopic.php?f=11&t=101&sid=230e01faacbd7deb64703d13507d244d