Hi everyone,
I was wondering if anyone can enlighten me in achieving my application in mind. I want to receive data from pc with in the following format "A123", B"10", "C5"
where A, B and C is the start data letter and after it are numeric values ranging from 1-255. I did a little research, and mostly I found HSERIN command being used ex.(hserin 1000, _WaitTimeOut, [str rbuffer\5\13]). but not really sure how I can incorporate what I have so far.
The following code (from Mr_e) is what I'm using right now, but I need to incorporate a string filtering for incoming data like "A123".
Thanks in advance,Code:Include "modedefs.bas" DEFINE osc 20 ' We're using a 4 MHz oscillator ' Define ADCIN parameters Define ADC_BITS 8 ' Set number of bits in result Define ADC_CLOCK 3 ' Set clock source (3=rc) Define ADC_SAMPLEUS 50 ' Set sampling time in uS adval Var Byte ' Create adval to store result i Var Byte ' For-loop variable position Var Byte ' LED position variable bright1 Var Byte ' Brightness variable ' PORT setting ' ============ ' TRISA = 000001 ' Set PORTA to all input ADCON1 = 000010 ' Set PORTA analog and right justify result TRISB=000000 TRISD=000000 TRISC=000000 ' RC.7 => USART RX pin set to input ' all other pin set to output ' TRISB=0 ' RB<7:0> set to output ' USART setting ' ============= ' Since we will not use HSERIN/HSEROUT, we must ' write directly to internal PIC register ' TXSTA=$24 ' enable transmit and SPBRGH=1 RCSTA=$90 ' Enable USART and continuous receive SPBRG=129 ' BAUD RATE = 9600 BAUDS ' Interrupt definition ' ==================== ' PIE1.5 =1 ' enable USART receive interrupt INTCON.6 =1 ' enable peripheral interrupt ' Alias definition ' ================ ' RCIF var PIR1.5 ' receiver interrupt StatusLED var PORTB.2 ' the LED who show a 'running process' ' Variable definition ' =================== ' Delay var word ' DataIn var byte ' use to store RCREG content Discard var byte ' use to erase RCREG register cntr var byte cntr = 1 ' Hardware/software initialisation ' ================================ ' PORTB=0 ' clear PORTB PORTC=0 PORTD=0 on interrupt goto USARTInterrupt PAUSE 500 ' Wait .5 second loop1: ADCIN 0, adval ' Store ADC value to adval Hserout["Data recieve:",adval,13] GOTO loop1 ' Do it forever END disable interrupt USARTInterrupt: ' Here's the interrupt routine who will make the user ' much happy by giving him the feeling to have the ' control on the machine when the status of the user ' LED will change ' RCSTA=0 ' Disable serial port AND ' clear possible error (FERR,OERR) datain=RCREG ' Get data while RCif ' wait untill the RCREG is empty discard=RCREG ' by reading it and store result in a wend ' don't care variable select case datain ' What to do with that data??? case "1" ' User selection = 1 PortB.0 = 1 case "2" ' User selection =2 PortB.0 = 0 '------------------------------1--------------------------------- end select RCSTA=$90 ' Re-enable the serial PORT AND resume ' get out of here enable interrupt
tacbanon




Bookmarks