Hi All,

I'm working on a small project that reads a 2-digit Ascii charcter (e.g. "23") into a Pic16F84 and displaying it onto 2x 7Seg displays.
The 2digit data comes from a temperature sensor unit, but for testing on the bench i use Hyperterm, and simply type "2" then "3" to see "23" appear on the 7-Segs.

Briefly, Port-B is the 7-segment data, and Port A.0 / A.1 are the cathode enables (via driver tranny) to the displays.

By alternating 2 variables (MSB & LSB) onto Port-B and toggling the 2 cathodes i have a 2 digit multiplexed display....

However, as simple as this sounds, i can't get my loops to work correctly.

I need the main part of my code to constantly send data to the 7-segs, while also taking a look at the serial pin for new data to be displayed..

At the moment, the following code works, but the 7seg data disappears almost immediately after it's displayed.
I realised when my code is idling it's 'blanking' my LSB/MSB variables, hence no display.
I can't find the right condition to keep data looping on the 7segs while still looking for new RS232 data.....

After a few changes, i can get the data to display nicely, but ONLY if i lock the loop into itself, which means it then doesnt read incoming data.
After resetting the Pic, i can enter new data, but only Once!


I know i'm probably only 2-3 lines of code from perfecting this, and i know most of you will probably re-write my code into 10 lines, but i thought i'd scream out for help and how what happens ;-)

Code:
'--------------------------------------------------------------------------------------------------------- 

DEFINE OSC 4			'set OSC to 4Mhz

INCLUDE "modedefs.bas"		'Enables RS232 comms library....

RS_Data		VAR BYTE	'RS232 Data assigned into "RS_Data"

LSB		VAR BYTE	'RS232 -UNITS- Data assigned into "LSB"
MSB		VAR BYTE	'RS232 -TENS-  Data assigned into "MSB"

Counter		VAR BIT		'A 1-bit "status" to indicate the 1st or 2nd digit is being processed.

Digits	 	VAR BYTE	'Search "Digits" for a number value 0-9 (lookdown)

Units_com	VAR PORTA.0	'COMmon Cathode Transistor driver (Hi-enable) for "Units" display.
Tens_com	VAR PORTA.1	'COMmon Cathode Transistor driver (Hi=enable) for "Tens" display.
Neg_seg		VAR PORTA.2	'NEGative Segment Transistor driver (Hi=enable) - for NEGATIVE Temperature.
Spare		VAR PORTA.3	'spare
RS232		VAR PORTA.4	'RS232 RX Data Pin (A.4) read into PIC.

Seg7		VAR PORTB	'7 segment display data (7 bits=number, 8th bit=decimal point).


'-----[ INITIALISE ALL the PORTS and setup bits in a CLEAN startup condition ]------------------------------------

Init:

	seg7 		= $00	'7-Seg data (portB) to $00 (Blank).			
	Units_com	= 0	'cathode "Units" OFF.
	Tens_com	= 0	'cathode " Tens" OFF.
	Neg_seg		= 0	'NEG-segment LEDs OFF.
	Counter		= 0	'set as the "1st" digit to be processed.	
	TRISA		= $10	'PortA all OUTPUTS on bits 0,1,2,3 and set Bit4 as INPUT (Serial IN).
	TRISB 		= $00	'PortB all OUTPUTS
	RS_Data		= $00	'cleared, until serial data arrives.
	Digits		= $00	'cleared, until Lookups fill it.	
	LSB		= $00	'cleared, until Lookups fill it.
	MSB 		= $00	'cleared, until Lookups fill it.


	GoTo Start	'Goto start of program...


'-----[ Get RS232 Data input, and assign into MSB & LSB Data to be displayed ]------------------------------------

GetData:

	SerIn RS232,T9600,RS_Data	'Read Serial Data on Pin RS232 (A.4) and assign value into "RS_Data"
				
					'Assign any of the "0123456789-" characters to "digits".  
	LookDown RS_Data,["0123456789-"],Digits	
					'Match number from RS_Data, and assign 7seg data to it into Digits.

	IF Counter	= 0 Then										
	LookUp Digits,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$00],MSB	'If "Counter" is "0" then store in MSB.
	Else		'(	0	1	2	3	4	5	6	7	8	9	- )
	LookUp Digits,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$00],LSB	'If "Counter" is "1" then store in LSB.
	EndIF


	IF Counter	= 0 Then	'If counter=0, then this is the first digit to be processed.
	Counter		= 1 		'Now make counter=1, to show (next time) that the 2nd digit will be processed.
	GoTo GetData			'Repeat to get 2nd digit to process.
	Else 				'
	Counter		= 0		'Otherwise, make counter=0, ready to process 1st digit of the next "2 numbers to arrive".
	EndIF				'		
			
	Return				'Return back to Start, and display MSB & LSB onto the 2x 7-Seg displays.


'-----[ Display MSB & LSB Data onto 2x 7-Segment Displays ]-------------------------------------------------------

Start:

	'UNITS:
	seg7 = LSB		'place data "LSB" onto PortB 7Seg info.
	units_com = 1		'ENable UNITs cathode.
	Pause 10		'Keep UNITs ON for 10mS before going back to TENS
	units_com = 0		'DISable UNITs cathode.

	'TENS:
	seg7 = MSB		'place data "MSB" onto PortB 7Seg info.
	tens_com = 1		'ENable TENs cathode.
	Pause 10		'Keep TENs ON for 10mS before going back to UNITS
	tens_com = 0		'DISable TENs cathode.

	GoSub GetData		'Go and check for new serial numbers arriving.
	GoTo Start		'Repeat this section again, dispaying the 7-Seg data etc.


'-----[ END ]-----------------------------------------------------------------------------------------------------
Thanx greatly in advance,
Marty.