View Full Version : how to store received values in serial communication ?
engasm
- 24th June 2012, 19:54
hi all
i recieve values in the following form from a device
=123456
i want to store the 3 decimal values after the "=" character
i can't figure out a way to do this
i used this line but it only stores one values and i don't know if it store it as decimal or not, what should the # do to the values ?
the line i used
SERIN RX,T2400,["="],SER1
when i tried to store two values it didn't give me anything !
SERIN RX,T2400,["="],SER1,SER2
can u help me plz
urgent !
mackrackit
- 24th June 2012, 20:03
http://melabs.com/samples/PBP-mixed/ser2mod.htm
engasm
- 24th June 2012, 20:26
could u give me a line that i can use instead of a 30 line that i should read !
engasm
- 24th June 2012, 20:36
IT SHOWS ME THESE ERRORS WHEN trying to use it
Serin2 RX,396,[WAIT("="),DEC A0]
Serout2 TX,396,["3: ",DEC A0,13,10]
\NEW FOLDER (2)\WEIGHT.PBP ERROR Line 87: Bad expression.
\NEW FOLDER (2)\WEIGHT.PBP ERROR Line 88: Bad expression.
mackrackit
- 24th June 2012, 20:45
Maybe you could post your code and tell us what chip you are using...
engasm
- 25th June 2012, 00:15
'************************************************* ***************
'* Name : 7SEG-MULTIPLEXING.BAS *
'* Author : [ Eng. Mohammad Aqel ] *
'* Date : 11/9/2007 *
'************************************************* ***************
DEFINE OSC 20
' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' Set LCD Register Select bit
DEFINE LCD_RSBIT 0
' Set LCD Enable port
DEFINE LCD_EREG PORTD
' Set LCD Enable bit
DEFINE LCD_EBIT 1
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
INCLUDE "modedefs.bas"
' Set baud rate
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 129 ' 2400 Baud @ 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
datain var byte
SerialData var byte
COUNTER VAR WORD
COUNTER1 VAR BYTE
COUNTER2 VAR BYTE
ASCII VAR BYTE
Ser var byte[40]
Ser1 var byte
A var byte[5]
B var byte[5]
i var byte
j var byte
ADCON1 = 6 'PORTA AND e DIGITAL
TRISC = %10000000 ' PORTC.7 is the RX input
' PORTC.6 is the TX output
TRISB=0
TRISD=0
TRISA=0
PORTD=$FF
PORTB=0
A0 var WORD
A1 var WORD
A2 var WORD
A3 var byte
A4 var byte
A5 var byte
A6 var byte
DEFINE SER2_BITS 4 ' Set Serin2 and Serout2 data bits to 4
DEFINE SER2_BITS 5 ' Set Serin2 and Serout2 data bits to 5
DEFINE SER2_BITS 6 ' Set Serin2 and Serout2 data bits to 6
DEFINE SER2_BITS 7 ' Set Serin2 and Serout2 data bits to 7
DEFINE SER2_BITS 8 ' Set Serin2 and Serout2 data bits to 8 (default)
b0 var byte
num var byte
Hex_input var byte
A_D_A VAR WORD [9]
MAIN:
'hserin [WAIT( "=" ) ,dec3 a0]
'Serin2 RX,396,[WAIT("="),dec a0]
Serin2 RX,396,[WAIT("="),DEC A0]
Serout2 TX,396,["3: ",DEC A0,13,10]
Serin2 RX,396,[WAIT("Y-"),DEC A0]
Serout2 TX,396,["3: ",DEC A0,13,10]
A3=Ser dig 3
A4=a0 dig 0
A5=a0 dig 1
A6=a0 dig 2
LCDOUT $fe,$80, dec2 A0
LCDOUT $fe,$c0, dec A4, dec A5, dec A6
goto MAIN
eND
----------
i used pic16f877
mackrackit
- 25th June 2012, 00:42
PORTC.7 is the RX input
' PORTC.6 is the TX output
Add to the Variable section of your code to let the compiler know the pins you are using
RX VAR PORTC.7
TX VAR PORTC.6
Or
Serout2 POTRC.6,396,["3: ",DEC A0,13,10]
And the same for SERIN2.
Either way, you need to tell the compiler.
Why are you adding
DEFINE SER2_BITS 4 ' Set Serin2 and Serout2 data bits to 4
DEFINE SER2_BITS 5 ' Set Serin2 and Serout2 data bits to 5
DEFINE SER2_BITS 6 ' Set Serin2 and Serout2 data bits to 6
DEFINE SER2_BITS 7 ' Set Serin2 and Serout2 data bits to 7
DEFINE SER2_BITS 8 ' Set Serin2 and Serout2 data bits to 8 (default)
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.