Monday, July 23, 2012

0 Programas echos en C para PIC




**********************Programa basico encender y apagar un puerto*******************
#include <p18f452.h>
#include <delays.h>



void main (void){

TRISB = 0XFF;
TRISD = 0X00;

while(1)
{
if(PORTBbits.RB0==0) {

PORTD = 0XFF;
Delay10KTCYx(64);

PORTD = 0X00;
Delay10KTCYx(64);


}

else
PORTD = 0X00;
}
}



********************************secuencia de luces **********************************


#include <p18f452.h>
#include <delays.h>

int n,F;


void main (void){


TRISD = 0X00;

TRISC = 0X00;

PORTC=0;
PORTCbits.RC0 = 1;

while(1)
{

for (n=0; n<8; n=n++) {

switch (n) {

case 0:
PORTD= 0b00000001;
Delay10KTCYx(5);
break;
case 1:
PORTD= 0b00000010;
Delay10KTCYx(5);
break;
case 2:
PORTD= 0b00000100;
Delay10KTCYx(5);
break;
case 3:
PORTD= 0b00001000;
Delay10KTCYx(5);
break;
case 4:
PORTD= 0b00010000;
Delay10KTCYx(5);
break;
case 5:
PORTD= 0b00100000;
Delay10KTCYx(5);
break;
case 6:
PORTD= 0b01000000;
Delay10KTCYx(5);
break;
case 7:
PORTD= 0b10000000;
Delay10KTCYx(5);
break;

default: PORTD=0XFF;

}
}

for (n=0; n<8; n=n++) {

switch (n) {

case 0:
PORTD= 0b00000001;
Delay10KTCYx(5);
break;
case 7:
PORTD= 0b00000010;
Delay10KTCYx(5);
break;
case 6:
PORTD= 0b00000100;
Delay10KTCYx(5);
break;
case 5:
PORTD= 0b00001000;
Delay10KTCYx(5);
break;
case 4:
PORTD= 0b00010000;
Delay10KTCYx(5);
break;
case 3:
PORTD= 0b00100000;
Delay10KTCYx(5);
break;
case 2:
PORTD= 0b01000000;
Delay10KTCYx(5);
break;
case 1:
PORTD= 0b10000000;
Delay10KTCYx(5);
break;

default: PORTD=0XFF;

}
}
}
}



*****************************Conversor Analogo Digital *********************************


#include <p18f452.h>
#include <delays.h>

int ALTA,BAJA;


void main (void){


TRISB = 0X00;
TRISD = 0X00;
TRISA = 0XFF;
ADCON0 = 0X01;
ADCON1 = 0X8E;


while(1)
{
ADCON0bits.GO=1;
if (ADCON0bits.GO = 1){

ALTA = ADRESH;
BAJA = ADRESL;

PORTD = BAJA;
PORTB = ALTA;

}
}
}





***************************************Mostrar nombre LCD********************************

#include <p18f452.h>
#include <delays.h>

int ALTA,BAJA;

void puertos (void);
void conver (void);
void intro (void);
void control (void);
void imprimir (void);
void escribir (void);


void main (void){


puertos();
intro();
imprimir();

}

void puertos (void)
{
TRISB = 0X00;
TRISD = 0X00;
TRISC = 0X00;
TRISA = 0XFF;

}// fin metodo configuracion de puertos

void intro (void)
{
int dato;
PORTCbits.RC0 = 0;

dato = 0X01; // borrar display
control();

dato = 0X30; // 8 bits
control();

dato = 0X01; // borrar display
control();

dato = 0X0E; //lcd on, parpadeo on, cursor on
control();

dato = 0X06; //visualizacion incrementa
control();

}// fin metodo introduccion

void control (void)
{ int dato;


PORTCbits.RC2 = 0;
PORTCbits.RC1 = 0;
PORTB = dato;
PORTCbits.RC0 = 1;
Delay10KTCYx(5);
PORTCbits.RC0 = 0;

}// fin metodo control de la lcd



void imprimir (void)
{
int dato;
PORTCbits.RC0 = 0;

dato = 0X5F;
escribir();

dato = 0X35;
escribir();

dato = 0X11;
escribir();

dato = 0X22;
escribir();

dato = 0X44;
escribir();

}// fin metodo introduccion

void escribir (void)
{ int dato;


PORTCbits.RC2 = 1;
PORTCbits.RC1 = 0;
PORTB = dato;
PORTCbits.RC0 = 1;
Delay10KTCYx(5);
PORTCbits.RC0 = 0;

}// fin metodo control de la lc




//************************************** PWM*******************************************

#include <p18cxxx.h>

void main (void)

{

TRISC=0X00;
TRISD=0X00;

ADCON0=0X01;
ADCON1=0X8E;

while(1){


PR2=0xFF;
CCP1CON=0x3F;
T2CON=0X04;


ADCON0bits.GO=1;
if (ADCON0bits.GO = 1){

CCPR1L=ADRESL;
PORTD=CCPR1L;

}
}
}



*************************************8programas en uno ***********************************


#include<p18f4550.h>
#include<delays.h>
int i,x,y,control;
void main(void)
{
ADCON1=0x0E;
TRISD=0x00;
TRISB=0xFF;
control=PORTB;
control=control>>2;
control=control&0x07;
switch(control)
{
case 0: //PROGRAMA 1//
{
control==0;
TRISB=0x03;
x=PORTB;
switch(x)
{
case 0:
x==0;
PORTD=0x55;
break;
case 1:
x==1;
PORTD=0xAA;
break;
case 2:
x==2;
PORTD=0x22;
break;
case 3:
x==3;
PORTD=0x33;
break;
default: PORTD=0x00;
}
}
break;
case 1: //PROGRAMA 2//
{
control==1;
TRISB=0x01;
while(1)
{
if(PORTBbits.RB0==0)
{
for (i=0; i<10; i++)
{
PORTD=i;
Delay10KTCYx(64);
}
}
else
{
for (i=9; i>=0; i--)
{
PORTD=i;
Delay10KTCYx(64);
}
}
}
}
break;
case 2: //PROGRAMA 3//
{
control==2;
TRISB=0x01;
PORTD=0x00;
while(PORTBbits.RB0==0)
{}
for (i=0; i<10; i++)
{
PORTD=i;
Delay10KTCYx(64);
}
}
case 3: //PROGRAMA 4//
{
control==3;
TRISB=0x03;
PORTD=0x00;
{
if(PORTBbits.RB0==1)
PORTD=0x55;
else
if(PORTBbits.RB1==1)
PORTD=0xAA;
else
PORTD=0x00;
}
}
break;
case 4: //PROGRAMA 5//
{
control==4;
TRISE=0x04;
ADCON2=0x88;
while(1)
{
if(PORTEbits.RE2==1)
{
ADCON0=0x01;
ADCON0bits.GO=1;
}
else
{
ADCON0=0x05;
ADCON0bits.GO=1;
}
while(ADCON0bits.GO==1)
{}
x=ADRESL;
y=ADRESH;
PORTD=x;
PORTE=y;
}
}
break;
case 5: //PROGRAMA 6//
{
control==5;
ADCON0=0x01;
ADCON2=0x08;
TRISCbits.TRISC2=0;
PR2=0xFF;
CCP1CON=0x3F;
T2CON=0X07;
PORTD=0x00;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.GO==1)
{}
x=ADRESH;
CCPR1L=x;
}
}
break;


o

{
control==5;
TRISB=0x01;
ADCON0=0x01;
ADCON2=0x08;
TRISCbits.TRISC2=0;
PR2=0xFF;
CCP1CON=0x3F;
T2CON=0X07;
PORTD=0x00;
//while(1)
{
if(PORTBbits.RB0==1)
{
ADCON0bits.GO=1;
while(ADCON0bits.GO==1)
{}
x=ADRESH;
CCPR1L=x;
}
else
goto default;
}
}
break;


case 6: //PROGRAMA 7//
{
control==6;
ADCON0=0x01;
ADCON2=0x08;
TRISCbits.TRISC2=0;
PR2=0xFF;
CCP1CON=0x3F;
T2CON=0X07;
PORTD=0x00;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.GO==1)
{}
x=ADRESH;
CCPR1L=x;
}
}
break;
case 7: //PROGRAMA 8//
control==7;
PORTD=0x80;
break;
default: PORTD=0xFF;
}
}

About the Author

Author info. Go to Blogger edit html and find these sentences.Now replace these with your own descriptions, if you like it Subscribe to Our Feed and Follow Me on Twitter

    Other Recommended Posts

0 comments:

Post a Comment

 
back to top //PART 2