Autor Tema: Crear un puerto virtual de salida a partir de pines dispersos...  (Leído 2308 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado CarloS_32

  • PIC10
  • *
  • Mensajes: 27
Crear un puerto virtual de salida a partir de pines dispersos...
« en: 28 de Octubre de 2010, 22:08:32 »
Hola..lo que se me ocurrio intentar para tratar de aprovechar mejor las patitas del pic es crear un puerto a partir de pines libres de diferentes puertos..por que pasa muchas veces que según el proyecto se necesitan los 8 pines de un puerto completo pero se tienen ocupados algunos aunque se dispone de  de 8 pines I/O de puertos distintos todavia..entonces se me ocurrio hacer una cosa asi..quiero sus opiniones y mejoras de esto..

Código: [Seleccionar]
[b]
#define RA0 PIN_A0 //Aqui podria agregar todos estos define al .h del pic
#define RA1 PIN_A1              //O bien crear uno nuevo..
etc
etc

int PORT_VIRTUAL_8;

main()
{
               PORT_VIRTUAL=15;          //Registro del puerto virtual cargado con 15 decimal..
               Salida_PORT_VIRTUAL_8(RA0,RD1,RB5,RB6,RB7,RE1,RE2,RC4);
                                         //Aqui se saca por este "puerto" lo que tiene cargado                                          //su registro...
        }



void Salida_PORT_VIRTUAL_8(int bit_0,int bit_1,...,int bit_7)
{
output_bit(bit_0,(00000001 & PORT_VIRTUAL_8));
output_bit(bit_1,(00000010 & PORT_VIRTUAL_8));
output_bit(bit_2,(00000100 & PORT_VIRTUAL_8));
output_bit(bit_3,(00001000 & PORT_VIRTUAL_8));
output_bit(bit_4,(00010000 & PORT_VIRTUAL_8));
output_bit(bit_5,(00100000 & PORT_VIRTUAL_8));
output_bit(bit_6,(01000000 & PORT_VIRTUAL_8));
output_bit(bit_7,(10000000 & PORT_VIRTUAL_8));
}
[/b]

Bueno espero mejoras..desde ya gracias espero se entienda..

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #1 en: 29 de Octubre de 2010, 01:37:31 »
¿Te funciona el paso de pines por parámetros a una función?

Desconectado CarloS_32

  • PIC10
  • *
  • Mensajes: 27
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #2 en: 29 de Octubre de 2010, 14:47:39 »
¿Te funciona el paso de pines por parámetros a una función?

Hola..no lo he probado pero un pin cualquiera no es mas que una constante creo como se puede ver en el .h del pic..,entonces yo pienso que deberia poderse..ahora a mi me gustaria entender mejor si por ejemplo lo que se esta pasando (o sea a lo que se refiere esa constante) como argumento a una función I/O será una direccion a cargar en un puntero eso no se (ya que no se puede ver el cuerpo de esa función),ahora voy a probar esto con varias combinaciones de pines aislados a ver si tira o no y te cuento

Desconectado CarloS_32

  • PIC10
  • *
  • Mensajes: 27
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #3 en: 29 de Octubre de 2010, 15:36:47 »
Bueno al parecer no se puede..al compilar tira este mensaje:


Error 44 ..:Internal Error- Contact CCS LABEL SCR=336


Y viendo la ayuda a este mensaje
Citar
Internal Error - Contact CCS

This error indicates the compiler detected an internal inconsistency.  This is not an error with the source code; although, something in the source code has triggered the internal error.  This problem can usually be quickly corrected by sending the source files to CCS so the problem can be re-created and corrected.


Creo que dice que no hay error en el código.. y este es el código

Código: [Seleccionar]
[b]

#include <16f877a.h>
#fuses HS,PUT,NOPROTECT,NOWDT,BROWNOUT,NOLVP
#use delay(clock=20M)
#byte porta=5
#byte portb=6
#byte portc=7
#byte portd=8
#byte porte=9

void Salida_PORT_VIRTUAL_8 (int bit_0,int bit_1,int bit_2,int bit_3,int bit_4,int bit_5,int bit_6,int bit_7);
int PORT_VIRTUAL_8;

   main()
   {
      while (1)
      {
               PORT_VIRTUAL_8=15;          //Registro del puerto virtual cargado con 15 decimal..
               Salida_PORT_VIRTUAL_8(PIN_A0,PIN_D1,PIN_B5,PIN_B6,PIN_B7,PIN_E1,PIN_E2,PIN_C4);
                                                         //Aqui se saca por este "puerto" lo que tiene cargado                                       
      }
   }   



      void Salida_PORT_VIRTUAL_8(int bit_0,int bit_1,int bit_2,int bit_3,int bit_4,int bit_5,int bit_6,int bit_7)
      {
      output_bit(bit_0,(00000001 & PORT_VIRTUAL_8));
      output_bit(bit_1,(00000010 & PORT_VIRTUAL_8));
      output_bit(bit_2,(00000100 & PORT_VIRTUAL_8));
      output_bit(bit_3,(00001000 & PORT_VIRTUAL_8));
      output_bit(bit_4,(00010000 & PORT_VIRTUAL_8));
      output_bit(bit_5,(00100000 & PORT_VIRTUAL_8));
      output_bit(bit_6,(01000000 & PORT_VIRTUAL_8));
      output_bit(bit_7,(10000000 & PORT_VIRTUAL_8));
      }[/b]

Tendra solución?

Desconectado CarloS_32

  • PIC10
  • *
  • Mensajes: 27
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #4 en: 29 de Octubre de 2010, 15:52:17 »
Ahora que curioso agregando estos #define si funciona y compila bien o sea quedando asi:


Código: CSS
  1. [b]
  2. #include <16f877a.h>
  3. #fuses HS,PUT,NOPROTECT,NOWDT,BROWNOUT,NOLVP
  4. #use delay(clock=20M)
  5. #byte porta=5
  6. #byte portb=6
  7. #byte portc=7
  8. #byte portd=8
  9. #byte porte=9
  10. #use standard_io (a,b,c,d,e,f)
  11.  
  12. #define RA0 PIN_A0                   //Estos son mis pines pero podemos definir todos los pines del pic en un .h de esta forma..
  13. #define RD1 PIN_D1
  14. #define RB5 PIN_B5
  15. #define RB6 PIN_B6
  16. #define RB7 PIN_B7
  17. #define RE1 PIN_E1
  18. #define RE2 PIN_E2
  19. #define RC4 PIN_C4
  20.  
  21. void Salida_PORT_VIRTUAL_8(int bit_0,int bit_1,int bit_2,int bit_3,int bit_4,int bit_5,int bit_6,int bit_7);
  22. int PORT_VIRTUAL_8;
  23.  
  24.    main()
  25.    {
  26.       while (1)
  27.       {
  28.                PORT_VIRTUAL_8=15;          //Registro del puerto virtual cargado con 15 decimal..
  29.                Salida_PORT_VIRTUAL_8 (RA0,RD1,RB5,RB6,RB7,RE1,RE2,RC4);
  30.                                          //Aqui se saca por este "puerto" lo que tiene cargado                                          //su registro...
  31.       }
  32.    }  
  33.  
  34.  
  35.  
  36.       void Salida_PORT_VIRTUAL_8(int bit_0,int bit_1,int bit_2,int bit_3,int bit_4,int bit_5,int bit_6,int bit_7)
  37.       {
  38.       output_bit(RA0,(0b00000001 & PORT_VIRTUAL_8));
  39.       output_bit(RD1,(0b00000010 & PORT_VIRTUAL_8));
  40.       output_bit(RB5,(0b00000100 & PORT_VIRTUAL_8));
  41.       output_bit(RB6,(0b00001000 & PORT_VIRTUAL_8));
  42.       output_bit(RB7,(0b00010000 & PORT_VIRTUAL_8));
  43.       output_bit(RE1,(0b00100000 & PORT_VIRTUAL_8));
  44.       output_bit(RE2,(0b01000000 & PORT_VIRTUAL_8));
  45.       output_bit(RC4,(0b10000000 & PORT_VIRTUAL_8));
  46.       }
  47. [/b]

Por que? no me lo pregunten jajaja

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #5 en: 29 de Octubre de 2010, 16:06:25 »
Bueno, lo importante es que lo has conseguido. Enhorabuena

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Crear un puerto virtual de salida a partir de pines dispersos...
« Respuesta #6 en: 29 de Octubre de 2010, 22:33:23 »
  Perdón que me meta ya que no utilizo CCS y por eso tengo cierta duda.

En el cuerpo de la función (o sea, en la implementación) figura esto
Código: C
  1. output_bit(RA0,(0b00000001 & PORT_VIRTUAL_8));
  2. output_bit(RD1,(0b00000010 & PORT_VIRTUAL_8));
  3. output_bit(RB5,(0b00000100 & PORT_VIRTUAL_8));
  4. output_bit(RB6,(0b00001000 & PORT_VIRTUAL_8));
  5. output_bit(RB7,(0b00010000 & PORT_VIRTUAL_8));
  6. output_bit(RE1,(0b00100000 & PORT_VIRTUAL_8));
  7. output_bit(RE2,(0b01000000 & PORT_VIRTUAL_8));
  8. output_bit(RC4,(0b10000000 & PORT_VIRTUAL_8));

entiendo que serían cada uno de los bits del puerto virtual. Pero no debería ser algo así

Código: C
  1. output_bit(bit_0,(0b00000001 & PORT_VIRTUAL_8));
  2. output_bit(bit_1,(0b00000010 & PORT_VIRTUAL_8));
  3. output_bit(bit_2,(0b00000100 & PORT_VIRTUAL_8));
  4. output_bit(bit_3,(0b00001000 & PORT_VIRTUAL_8));
  5. output_bit(bit_4,(0b00010000 & PORT_VIRTUAL_8));
  6. output_bit(bit_5,(0b00100000 & PORT_VIRTUAL_8));
  7. output_bit(bit_6,(0b01000000 & PORT_VIRTUAL_8));
  8. output_bit(bit_7,(0b10000000 & PORT_VIRTUAL_8));

ya que si es como se indica inicialmente, la implementación de la función siempre va a hacer uso de RA0, RD1, RB5, RB6, RB7, RE1, RE2, RC4 como si fueran los bits del puerto virtual
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas


 

anything