Code:' Defines for USART INCLUDE "bs2defs.bas" DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h '24h DEFINE HSER_BAUD 9600 '9600 baud DEFINE HSER_SPBRG 25 'No estaba ' Registros timer RCIF VAR PIR1.5 ' Alias RCIF (USART Receive Interrupt Flag) OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag) CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable) T0CS VAR OPTION_REG.5 PSA VAR OPTION_REG.3 PS0 VAR OPTION_REG.0 PS1 VAR OPTION_REG.1 PS2 VAR OPTION_REG.2 ' Declaracion de variables valor1 VAR WORD ' tiempos Timer valor2 VAR WORD valor3 VAR WORD estado VAR BYTE ' variable para disparar timer char0 VAR BYTE ' b0 dato a decodificar char1 VAR BYTE ' b1 dato a decodificar char2 VAR BYTE ' b2 dato a decodificar char3 VAR BYTE i VAR BYTE ' Contador string VAR BYTE[20] ' Paquete Recepcion TMR0Count VAR WORD c VAR BYTE ' Configuracion de puertos TRISB= %00100111 ' Configuracion inerrupciones INTCON = %11111000 ' Registro para habilitar las interrupciones ON INTERRUPT GoTo serialin ' AL realizarse interrupcion va ahi PIE1.5 = 1 ' Habilitar interrupcion en USART ' Defines RBO VAR PORTB.0 RX VAR PORTB.1 TX VAR PORTB.2 interruption VAR PORTB.3 led VAR PORTB.4 RB5 VAR PORTB.5 salida1 VAR PORTB.6 salida2 VAR PORTB.7 ' Inicio del programa i=0 c=0 char0=0 char1=0 char2=0 string[0]=0 string[1]=0 string[2]=0 string[3]=0 string[4]=0 string[5]=0 string[6]=0 string[7]=0 string[8]=0 string[9]=0 string[10]=0 string[11]=0 PORTB=0 Pause 1 HSerout ["Port has Started Ok!!"] High interruption 'Deparcing INICIO: IF i=255 Then High salida2 For i = 0 TO 20 IF string[i]=$52 Then char0=string[i] i=i+1 char1=string[i] i=i+1 char2=string[i] i=19 EndIF Next i EndIF IF char0="R" AND char1="1" AND char2="1" Then 'R11 High salida1 char0=0 char1=0 char2=0 string[0]=0 string[1]=0 string[2]=0 string[3]=0 string[4]=0 string[5]=0 string[6]=0 string[7]=0 string[8]=0 string[9]=0 string[10]=0 string[11]=0 Pause 2000 i=0 Low salida1 Low salida2 EndIF GoTo INICIO Disable interrupt ' Don't check for interrupts in this section serialin: HSerin [HEX2 b0] IF b0 = $7C Then GoTo jump EndIF string[c]=b0 c=c+1 RCIF=0 Resume jump: RCIF=0 c=0 i=255 Resume Enable interrupt End





Bookmarks