Documentos de Académico
Documentos de Profesional
Documentos de Cultura
h>
02.
03.#FUSES NOWDT
//No Watch Dog Timer
04.#FUSES INTRC_IO
//Internal RC Osc
05.#FUSES NOPUT
//No Power Up Timer
06.#FUSES NOPROTECT
//Code not protected from reading
07.#FUSES NOBROWNOUT
//No brownout reset
08.#FUSES NOMCLR
//Master Clear pin used for I/O
09.#FUSES NOLVP
//No low voltage prgming, B3(PIC16) or B5(PIC
18) used for I/O
10.#FUSES NOCPD
//No EE protection
11.#FUSES RESERVED
//Used to set the reserved FUSE bits
12.
13.#use delay(clock=4000000)
14.#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,STREAM=BLUE,error
s)
#include "conf.h"
02.#include <string.h>
03.
04.//direccin del registro TRISA
05.#byte TRISA = 85
06.
07.//direccin del puerto A
08.#byte puerto_a = 05
09.#bit RA0 = puerto_a.0
10.
11.
12.#int_RDA
13.//Cuando entra un mensaje se produce una interrupcin
14.void RDA_isr(void) {
15.
16. char entrada[5]="\0";
17.
18. //Guardamos el mensaje recibido
19. fgets(entrada,BLUE);
20.
21. char led1[3]="\0";
22. char led2[3]="\0";
23.
24. led1="1";
25. led2="2";
26.
27. //Comparamos el mensajes recibido para saber que hacer:
28.
29. if(strcmp(entrada,led1)==0)RA0=0; //ON
30. else if(strcmp(entrada,led2)==0)RA0=1;//OFF
31. else {
32.
int i;
33.
for( i=1; i<=10; i++){
34.
puerto_a=0x00;delay_us(300);puerto_a=0x03;delay_us(700);
35.
puerto_a=0x00;delay_ms(50); puerto_a=0x03;delay_ms(50);
36.
}
37. }
38.
39.}
40.
41.
42.void main() {
43. //Desactivamos los comparadores
44. setup_comparator(NC_NC_NC_NC);
45. setup_vref(FALSE);
46.
47. //Activamos las interrupciones
48. enable_interrupts(INT_RDA);
49. enable_interrupts(GLOBAL);
50.
51. //configuramos el puerto A
52. set_tris_a( 0xfe);
53. puerto_a =0x01;
54.
55. putc('Z');
56.
57.
//como el mensaje produce una interrupcin, el resto del tiempo estamos en
un bucle infinito sin hacer nada
58. while(true){
59.
60.
}
61. }