COMPILADOR C DE CCS PRINCIPALES FUNCIONES Y DIRECTIVAS

  • Slides: 19
Download presentation
COMPILADOR C DE CCS PRINCIPALES FUNCIONES Y DIRECTIVAS

COMPILADOR C DE CCS PRINCIPALES FUNCIONES Y DIRECTIVAS

DIRECTIVAS DE PREPROCESADO

DIRECTIVAS DE PREPROCESADO

#DEVICE n Syntax: #device chip options – chip is the name of a specific

#DEVICE n Syntax: #device chip options – chip is the name of a specific processor (like: PIC 16 C 74), – Options are qualifiers to the standard operation of the device. n Example: – #device PIC 16 F 877

#INCLUDE n Syntax: – #include <filename> – #include "filename“ n Ejemplos: – #include <16

#INCLUDE n Syntax: – #include <filename> – #include "filename“ n Ejemplos: – #include <16 f 877. h> – #include “lcd. h”

#DEFINE n Syntax: #define id text n Used to provide a simple string replacement

#DEFINE n Syntax: #define id text n Used to provide a simple string replacement of the ID with the given text from this point of the program and on. n Examples: – #define verdadero 1 – #define falso 0

#USE ****_I/O n Afectan a como utilizamos los TRISX n Syntax: – #use fast_io

#USE ****_I/O n Afectan a como utilizamos los TRISX n Syntax: – #use fast_io (port) – #use fixed_io (port_outputs=pin, pin? ) – #USE STANDARD_IO (port) n Ejemplo – #use fast_io (A)

#USE DELAY n Syntax: #use delay (clock=speed(Hz)) n Tells the compiler the speed of

#USE DELAY n Syntax: #use delay (clock=speed(Hz)) n Tells the compiler the speed of the processor and enables the use of the built-in functions: delay_ms() and delay_us(). n Ejemplo: – #use delay (clock=20000000)

#BYTE n Syntax: #byte id = x n Elements: id is a valid C

#BYTE n Syntax: #byte id = x n Elements: id is a valid C identifier, x is a C variable or a constant n Coloca la variable id en la posicion de memoria x. n Ejemplo: – #byte portb=5

#INT_xxx n Indica que la funcion a continuacion es la rutina de atencion de

#INT_xxx n Indica que la funcion a continuacion es la rutina de atencion de una determinada interrupción n #INT_EXT External interrupt n #INT_RTCC Timer 0 (RTCC) overflow n #INT_TIMER 1 Timer 1 overflow

FUNCIONES ESPECIFICAS DEL COMPILADOR n RS 232 n I 2 C I/O n Discrete

FUNCIONES ESPECIFICAS DEL COMPILADOR n RS 232 n I 2 C I/O n Discrete I/O n SPI two wire I/O n Parallel Slave I/O n Delays n Processor Controls n. Bit/Byte n. Capt/Comp/PWM n. Timers n. A/D Conversion n. EEPROM n. C Math n. Etc.

DELAYS n delay_ms(tiempo) n delay_us(tiempo) n delay_cycles(ciclos) (0 -255) – 1 ciclo= 4 ciclos

DELAYS n delay_ms(tiempo) n delay_us(tiempo) n delay_cycles(ciclos) (0 -255) – 1 ciclo= 4 ciclos de reloj

INPUT( ) n Syntax: value = input (pin) n Returns: – 0 (or FALSE)

INPUT( ) n Syntax: value = input (pin) n Returns: – 0 (or FALSE) if the pin is low, – 1 (or TRUE) if the pin is high n Ejemplo: – Encendido=input(PIN_A 4)

INPUT_x() n Syntax: – value = input_a() – value = input_b() – value =

INPUT_x() n Syntax: – value = input_a() – value = input_b() – value = input_c() –. . . n Returns: An 8 bit int representing the port input data.

OUTPUT_X() n Syntax: – output_a (value) – output_b (value) –. . . n Parameters:

OUTPUT_X() n Syntax: – output_a (value) – output_b (value) –. . . n Parameters: value is an 8 bit int n Function: Output an entire byte to a port.

OUTPUT_BIT( ) n Syntax: output_bit (pin, value) n Function: Outputs the specified value (0

OUTPUT_BIT( ) n Syntax: output_bit (pin, value) n Function: Outputs the specified value (0 or 1) to the specified I/O pin. n Ejemplos – Output_bit (PIN_D 1, 0) – Output_bit(PIN_A 3, 1)

OUTPUT_xxxx() n OUTPUT_HIGH( ) – Syntax: output_high (pin) – Function: Sets a given pin

OUTPUT_xxxx() n OUTPUT_HIGH( ) – Syntax: output_high (pin) – Function: Sets a given pin to the high state. n OUTPUT_LOW( ) – Syntax: output_low (pin) – Function: Sets a given pin to the ground state.

SET_TRIS_X() n Configura los registros de direccionamiento de los puertos (TRIS) n 0 significa

SET_TRIS_X() n Configura los registros de direccionamiento de los puertos (TRIS) n 0 significa salida n 1 significa entrada n Ejemplo: – Set_tris_a(0 b 00001011)

ENABLE/DISABLE INTERRUPTS n Permiten o inhiben las interrupciones. n Ejemplos: – enable_interrupts(GLOBAL); – disable_interrupts(INT_TIMER

ENABLE/DISABLE INTERRUPTS n Permiten o inhiben las interrupciones. n Ejemplos: – enable_interrupts(GLOBAL); – disable_interrupts(INT_TIMER 0); – enable_interrupts(INT_TIMER 1);

OTRAS FUNCIONES setup_adc_ports() n setup_adc() n set_adc_channel() n read_adc() n setup_timer_X() n set_timer_X() n

OTRAS FUNCIONES setup_adc_ports() n setup_adc() n set_adc_channel() n read_adc() n setup_timer_X() n set_timer_X() n get_timer_X() n n swap() setup_ccp. X() n set_pwm. X_duty() n