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,
Bookmarks