Instrucciones Seleccionadas del Compilador CCS C para PIC

Anuncio
UNIVERSIDAD TECNOLÓGICA NACIONAL
FACULTAD REGIONAL TUCUMÁN
Departamento: ELECTRÓNICA
Carrera: Ingeniería Electrónica – Ciclo 2014/15
Cátedra: INFORMÁTICA II
Introducción a
Programación de
MCU – CCS C
Compiler
Instrucciones Seleccionadas del Compilador CCS C para PIC.
output_high( )
Syntax:
output_high (pin)
Parameters:
Pin to write to. 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 . The PIN could also be a variable. The variable must have a
value equal to one of the constants (like PIN_A1) to work properly. The tristate register is
updated unless the FAST_IO mode is set on port A. Note that doing I/O with a variable
instead of a constant will take much longer time.
Returns:
Undefined
Function:
Sets a given pin to the high state. The method of I/O used is dependent on the last USE *_IO
directive.
Availability:
All devices.
Requires:
Pin constants are defined in the devices .h file
Examples:
output_high(PIN_A0);
Int16 i=PIN_A1;
output_low(PIN_A1);
output_low( )
Syntax:
output_low (pin)
Parameters:
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 . The PIN could also be a variable. The variable must have a value equal to one
of the constants (like PIN_A1) to work properly. The tristate register is updated unless the
FAST_IO mode is set on port A. Note that doing I/O with a variable instead of a constant will
take much longer time.
Returns:
Undefined
Function:
Sets a given pin to the ground state. The method of I/O used is dependent on the last USE
*_IO directive.
Availability:
All devices.
Requires:
Pin constants are defined in the devices .h file
Examples:
output_low(PIN_A0);
Int16i=PIN_A1;
output_low(PIN_A1);
___________________________________________________________________________ Página 1 de 4
UNIVERSIDAD TECNOLÓGICA NACIONAL
FACULTAD REGIONAL TUCUMÁN
Departamento: ELECTRÓNICA
Carrera: Ingeniería Electrónica – Ciclo 2014/15
Cátedra: INFORMÁTICA II
Referencias de
instrucciones de
CCS C Compiler
output_toggle( )
Syntax:
output_toggle(pin)
Parameters:
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:
Undefined
Function:
Toggles the high/low state of the specified pin.
Availability:
All devices.
Requires:
Pin constants are defined in the devices .h file
Examples:
output_toggle(PIN_B4);
output_x( )
Syntax:
output_a (value)
output_b (value)
output_c (value)
output_d (value)
output_e (value)
output_f (value)
output_g (value)
output_h (value)
output_j (value)
output_k (value)
Parameters:
value is a 8 bit int
Returns:
Undefined
Function:
Output an entire byte to a port. The direction register is changed in accordance with the last
specified #USE *_IO directive.
Availability:
All devices, however not all devices have all ports (A-E)
Requires:
Nothing
Examples:
OUTPUT_B(0xf0);
___________________________________________________________________________ Página 2 de 4
UNIVERSIDAD TECNOLÓGICA NACIONAL
FACULTAD REGIONAL TUCUMÁN
Departamento: ELECTRÓNICA
Carrera: Ingeniería Electrónica – Ciclo 2014/15
Cátedra: INFORMÁTICA II
Referencias de
instrucciones de
CCS C Compiler
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 .
The PIN could also be a variable. The variable must have a value equal to one of the
constants (like PIN_A1) to work properly. The tristate register is updated unless the
FAST_IO mode is set on port A. note that doing I/O with a variable instead of a constant will
take much longer time.
Returns:
0 (or FALSE) if the pin is low,
1 (or TRUE) if the pin is high
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.
Availability:
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");
int16 i=PIN_B1;
while(!i);
//waits for B1 to go high
input_state( )
Syntax:
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 high or low. A 1 indicates the pin is high and a 0 indicates it is
low.
Function:
This function reads the level of a pin without changing the direction of the pin as INPUT()
does.
Availability:
All devices.
Requires:
Nothing
Examples:
level = input_state(pin_A3);
printf("level: %d",level);
___________________________________________________________________________ Página 3 de 4
UNIVERSIDAD TECNOLÓGICA NACIONAL
FACULTAD REGIONAL TUCUMÁN
Departamento: ELECTRÓNICA
Carrera: Ingeniería Electrónica – Ciclo 2014/15
Cátedra: INFORMÁTICA II
Referencias de
instrucciones de
CCS C Compiler
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();
___________________________________________________________________________ Página 4 de 4
Descargar