Autor Tema: Como testear un pin?  (Leído 6715 veces)

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

Desconectado manwenwe

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 2211
Como testear un pin?
« en: 20 de Octubre de 2006, 13:57:16 »
Hola! Se que os parecerá una pregunta absurda, pero es que acabo de empezar con C para PICs y hay cosas que no me entran... ¿Como testeo un pin en CCS? He probado a hacer un (ej.) if(pin_a5==FALSE) { .......} También he probado igualando a un entero o a un binario(se supone que un pin es booleano no?) y tampoco funciona... el caso, que estoy perdido. GRACIAS!
Ojo por ojo y todo el mundo acabará ciego - Mahatma Gandhi -

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Como testear un pin?
« Respuesta #1 en: 20 de Octubre de 2006, 14:48:52 »
Te aconsejo que te des una vuelta por Ejemplitos en C para 16F648A y por Microcursillo en C. Ahí tienes ejemplos de todo

Pero si te interesa esto es lo que dice el Manual de CCS

INPUT()
Syntax:
value = input (pin)
Parameters:
Pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43
Returns:
0 (or FALSE) if the pin is low,
1 (or TRUE) if the pin is high
Availability:
input_x(), output_low(), output_high(), #use xxxx_io
Function:
This function returns the state of the indicated pin. The method of I/O is dependent on the last USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input.
All devices.
Requires
Pin constants are defined in the devices .h file
Examples:
while ( !input(PIN_B1) );
// waits for B1 to go high
if( input(PIN_A0) )
printf("A0 is now high\r\n");
Example Files:
EX_PULSE.C
Also See:
C Compiler Reference Manual
120

INPUT_STATE()
Syntax:
Nothing
value = input_state(pin)
Parameters:
pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port A (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43.
Returns:
Bit specifying whether pin is input or output. A 1 indicates the pin is input and a 0 indicates it is output.
Function:
This function reads the I/O state of a pin without changing the direction of the pin as INPUT() does.
Availability:
All devices.
Requires
Examples:
dir = input_state(pin_A3);
printf("Direction: %d",dir);
Example Files:
None
Also See:
input(), set_tris_x(), output_low(), output_high()
Built-In Functions
121

INPUT_x()
Syntax:
value = input_a()
value = input_b()
value = input_c()
value = input_d()
value = input_e()
value = input_f()
value = input_g()
value = input_h()
value = input_j()
value = input_k()
Parameters:
None
Returns:
An 8 bit int representing the port input data.
Function:
Inputs an entire byte from a port. The direction register is changed in accordance with the last specified #USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input.
Availability:
All devices.
Requires
Nothing
Examples:
data = input_b();
Example Files:
ex_psp.c
Also See:
input(), output_x(), #USE xxxx_IO
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado Mario_2004

  • PIC10
  • *
  • Mensajes: 30
Re: Como testear un pin?
« Respuesta #2 en: 20 de Octubre de 2006, 14:51:45 »
Hola manwenwe, no te preocupes todos hemos empezado. La instrucción que buscas es INPUT( ).

Y estos ejemplos, son de la ayuda del CCS, espero te sea de ayuda:

Código: [Seleccionar]
while ( !input(PIN_B1) );
// waits for B1 to go high

if( input(PIN_A0) )
   printf("A0 is now high\r\n");

saludos,
Mario

Desconectado manuelroin24

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 665
Re: Como testear un pin?
« Respuesta #3 en: 20 de Octubre de 2006, 20:00:11 »
    input es como si fuera preguntar por 1 no???

    !input es como si fuera preguntar por 0 no ???

    gracias......
El conocimiento se consigue a base de esfuerzo...

Desconectado Cryn

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4169
Re: Como testear un pin?
« Respuesta #4 en: 20 de Octubre de 2006, 20:21:18 »
si, en efecto, con input preguntas por estado de entrada en un pin, si su valor es uno
y !input si es cero.
.