Documentos de Académico
Documentos de Profesional
Documentos de Cultura
PICS. El C fue desarrollado en los Laboratorios Bell a principios de los años 70, por Dennis Ritchie y
Brian Kernighan. Programar en C presenta numerosas ventajas si se le compara a la programación en
lenguaje ensamblador.
C permite definir variables enteras ó de punto flotante, cuenta con librerías para realizar todo tipo de
operaciones aritméticas, el manejo de arreglos ó tablas de datos y de strings , el uso de declaraciones
condicionales e iterativas (do/while, for, if/else, switch/case).
La estructura de las funciones, permite transferir parámetros ó argumentos de entrada y salida en forma
directa al llamar a determinada función.
http://www.puntoflotante.net/PORQUE-USAR-LENGUAJE-ANSI-C.htm
PROGRAMACION EN C18 Y HITECH
IF STATEMENTS
if (condition expression )
{ instrucciones ;
}
Ejemplo:
IF - ELSE
Ejemplo:
Si la entrada PORTA,0 = 0 entonces PORTA,1=1, de lo contrario PORTA,1=0
if ((RA0 == 0)
{RA1= 1;}
Else
{RA1= 0;}
SWITCH (CASE)
switch(value)
{
case value: statement or group of statements;
case value: statement or group of statements;
default: statement or group of statements;
}
Ejemplo: switch (pepe) {
case 0: printf("cmd 0"); break;
case 1: printf("cmd 1"); break;
default: printf("bad cmd"); break; }
C ansi_c.pdf pag 35
WHILE LOOPS
while (condition is true)
{
statement or group of statements;
}
DO LOOPS
void main(void)
{
int COUNT;
TRISA = 0xFF;
ADCON1 = 0x06;
TRISB = 0x00;
TRISC = 0x00;
COUNT = 0;
Do
{
if ((RA0 == 0)
{
COUNT += 1;
}
Else
{
COUNT -= 1;
}
PORTC = COUNT & 0x00FF;
PORTB = (COUNT >> 8) & 0x00FF;
} while (1>0);
}
FOR-NEXT
Existen varias maneras de manejar los bits en C, una manera de conseguirlo es asi:
#include <p18c452.h>
PORTCbits.RC0=0;
struct RS485_del_com
{
unsigned char procesando :1;
unsigned char finalizo :1;
unsigned char denegada :1;
unsigned char crc16_ok :1;
}rs485={0};
CONFIGURACION DE HARDWARE
Úselo siempre en
*******************************************************************************************/
sus programas
#pragma config OSC =HS
#pragma config PWRT = ON,BOR = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config CP0 = ON,CP1 = ON,CP2 = ON
#pragma config CPB = ON,CPD = ON
#pragma config WRT0 = ON,WRT1 = ON,WRT2 = ON
#pragma config WRTB = ON,WRTC = ON,WRTD = ON
#pragma config EBTR0 = ON,EBTR1 = ON,EBTR2 = ON
#pragma config EBTRB = ON
/*******************************************************************************************
*******************************************************************************************/
/*******************************************************************************************
*******************************************************************************************/
/*******************************************************************************************
SUBRUTINAS
*******************************************************************************************/
tiempo--;
}
ESTRUCTURA BASICA DE LA RUTINA PRINCIPAL DE UN PROGRAMA
while (1)
{
if (PORTBbits.RB0==1)
{
}
else
{