Ejemplos programacion en c para pic
Ejemplo 01 (EX01-LED) LED parpadeante
2
LED parpadeante
#include "pic.h" int main(void) { char val = 0; TRISB = 0x01; while(1) { if(RB0==1) { val = ~val; RB1 = val; }else RB1 = 0; } return 0; }
3
LED parpadeante
#include "pic.h"
#define
_XTAL_FREQ 4000000
int main(void) { char val = 0; TRISB = 0x01; while(1) { if(RB0==1) { val = ~val; RB1 = val; }else RB1 = 0;
__delay_ms(1000);
} return 0; }
4
Ejemplo 02 (EX02-7SEG) Decodificador 7 Segmentos
5
Decodificador 7 Segmentos
#include "pic.h"
int main(void) { char val; TRISC =0x0F; TRISB = 0x00; while(1) { ……… } return 0; }
6
Decodificador 7 Segmentos
val = PORTC & 0x0F; switch(val) { case 0 : PORTB = case 1 : PORTB = case 2 : PORTB = case 3 : PORTB = case 4 : PORTB =case 5 : PORTB = case 6 : PORTB = case 7 : PORTB = case 8 : PORTB = case 9 : PORTB = default: PORTB = }
0x3F; 0x06; 0x5B; 0x4F; 0x66; 0x6D; 0x7D; 0x07; 0x7F; 0x6F; 0x00;
break; break; break;break; break; break; break; break; break; break;
7
Ejemplo 03 (EX03-LUCES) Juego de Luces
8
Juego de Luces
#include "pic.h" #define _XTAL_FREQ 4000000 int main(void) char val = TRISB =TRISC = do { ……………… { 0x01; 0x00; 0x01;
} while (1); return 0;
}
9
Juego de Luces
PORTB = val; if(RC0 == 1) { if(val==0x80) else } else { if(val==0x01) else } __delay_ms(500);
val = 0x01;val = val > 1;
10
Ejemplo 04 (EX04-SEMAFORO) Semáforo
11
Semáforo
#include "pic.h"
#define
_XTAL_FREQ 4000000
int main(void) { char c = 1; TRISB = 0x00; TRISC = 0x01; for(;;) {……………
} return 0;
}
12
Semáforo
// Funcion Normal if(RC0==1) { if(c==4) c=1; else c++; switch(c) { case 1: PORTB case 2: PORTB case 3: PORTB case 4: PORTB } }
= = = =
0x14; 0x12;0x41; 0x21;
__delay_ms(3000); __delay_ms(1000); __delay_ms(3000); __delay_ms(1000);
break; break; break; break;
13
Semáforo
// Intermitente else { if(c>=2) c=1; else c=2; switch(c) {...
Regístrate para leer el documento completo.