Tomorrow I will publiesh the code don`t have it with me..
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
HSerIn doesn't need to be used in an interrupt.
If you've got going what I think you've got going...
When your interrupt trips, you've got a character in the receive register. When you get into your interrupt routine, the HSerIn line will wait for the next character, not get the one that's already in the receive register.
And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.
errr... HEX2 wait for two character, RCIF=0 is is a read only. This bit is cleared when you read RCREG untill the USART buffer is empty (HSERIN should take care of it)
if this program work with Hyperterminal and not on another software, we need to know what's the other software. Could be handy to have a LCD attach to your PIC and display the incoming data.
mmm... really sure of it???And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks