' ********************************************************************** ' ** Program name: KND08_F2.BAS - Version : 1.1 - 17 May 2000 ** ' ** Compiler : BASCOM 8051, (IDE V.1.0.0.20, LIB V.1.20) ** ' ** Board : KND 08 ** ' ** Firm: grifo(r) ITALIAN TECHNOLOGY ** ' ** Via Dell' Artigiano 8/6 40016 San Giorgio di Piano (BO) ** ' ** Tel.+39 051 892 052 Fax +39 051 893 661 ** ' ** http://www.grifo.com http://www.grifo.it ** ' ** sales@grifo.it tech@grifo.it grifo@grifo.it ** ' ** ** ' ** Written by: Adriano Pedrielli ** ' ********************************************************************** ' ' This program allows to manage the board resources of KND 08 card through a ' menu, using 2 TTL lines driven by a familiy 51 microcontroller. ' This program is managed through a RS 232 serial line, so it is essential ' to connect a free COM port of the PC to connector CN3 of GPC(r) F2. ' To configure the BASCOM 8051 terminal in menu Options/Communication ' select the COM port and set Baud Rate to 9600, parity to none, ' databits to 8, stopbits to 1. ' The board used to drive KND 08 is GPC(r) F2, connections are: ' GPC F2 KND 08 ' +5Vdc (pin15 CN3) ----> +5Vdc (pin4 CN1) ' Gnd (pin16 CN3) ----> Gnd (pin3 CN1) ' T0 P3.4 (pin3 CN3) ----> SC (pin2 CN1) ' T1 P3.5 (pin1 CN3) ----> SD (pin1 CN1) ' ' Before compiling in menu Option/Compiler/Misc set Byte End(Hex) = 65. ' ' If the MO52 monitor program is installed, select Option/Communication, ' a dialog window will be opened. ' Set baudrate to 9600, stopbits to 1, select the tab "Monitor" then set: ' Monitor with HEX upload, Upload speed 9600, in the box "Monitor prefix" ' write "L{13}", leave blank the boxes "Monitor delay" and "Prefix delay", ' in the box "Monitor suffix" write "{27}". ' After this, before uploading, activate the terminal window, turn on the ' board with the EPROM of the monitor installed, if the MO52 monitor starting ' message appears it is possible to upload using the File menu of the ' termina emulator. ' '*********************************************************************** ' '********************* Compiler Directives ***************************** ' $regfile = "REG51.DAT" ' list of CPU registers $romstart = &H8050 ' code start address ' &H8050 for MO52 Rel.1.1 in RAM IC8 ' &H0000 for EPROM without RAM IC8 $ramstart = &HD000 ' add. of variables external RAM $ramsize = &H2800 ' assign 10K of external RAM ' to variables $crystal = 11059200 ' CPU clock frequence $baud = 9600 ' RS-232 communication speed $large ' 16 bit addredding Config Timer0 = Timer , Gate = Internal , Mode = 1 'Timer0 = timer : timer0 programmed as timer 'Gate = Internal : full abilitation 'Mode = 1 : resolution is 16-bit, when timer reaches 0 the interrupt ' is triggered and timer must be reloaded manually. ' '********************* Constants declaration *************************** ' Pclk Alias P3.4 ' line P3.4 or T0 (pin 3 of CN3) ' on GPC(r) F2 is Clock signal. Psda Alias P3.5 ' line P3.5 or T1 (pin 1 of CN3) ' on GPC(r) F2 is Data signal. Const Cler = 12 ' ASCII code of clear screen Const Bel = 7 ' ASCII code of Bell Const Ric = 19 ' generates an interrupt every ' 4.88 mS when clock frequence ' is 11.0592MHz. ' to change the interrupt time ' use this proportion: ' 19 : 4.88 = n : mS . ' for example a time of 7ms is: ' (7*19)/4.88= 27 ' N.B. : Max value is 255 (65mS) Const N_rinf = 5 ' numbero of refreshes before ' updating the value, each unit ' lasta (interrupt time) * 4. ' E.g.:Timer0= 5mS *4= 20mS ' 1 refresh ' '*********************** Variables declaration ******************************** ' Dim Rinfvr As Bit ' indicates which set of display ' must be updated, 1234 or 5678 Dim Led1 As Bit ' indicates status of Led 1 Dim Led2 As Bit ' indicates status of Led 2 Dim Led3 As Bit ' indicates status of Led 3 Dim Led4 As Bit ' indicates status of Led 4 Dim Led5 As Bit ' indicates status of Led 5 Dim Led6 As Bit ' indicates status of Led 6 Dim Numero As Long ' indicates the number to show Dim Num_h As Word ' four figures number for display ' DY5, DY6, DY7, DY8. Dim Num_l As Word ' four figures number for display ' DY1, DY2, DY3, DY4. Dim D As Byte ' indicates decimal point on Dim Dp_h As Byte ' position of decimal point in ' display set 5678 Dim Dp_l As Byte ' position of decimal point in ' display set 1234 Dim T As Byte ' contains character received Dim X As Byte ' general purpose Dim N As Long ' general purpose Dim Tstr As String * 1 ' general purpose string variable ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' Dim X8 As Byte ' general purpose for interrupt Dim X16 As Word ' general purpose Dim Bit23 As Long ' 24 bits wide variable that ' stores the bit frame for M5480 Dim Rinf As Byte ' stores the number of refreshes ' for displays before updating ' their value Dim Digit As Byte ' contains conversion in digit Dim Cif_uh As Byte ' units figure of DY5 Dim Cif_dh As Byte ' decines figure of DY6 Dim Cif_ch As Byte ' hundreds figure of DY7 Dim Cif_mh As Byte ' thousands figure of DY8 Dim Cif_ul As Byte ' units figure of DY1 Dim Cif_dl As Byte ' decines figure of DY2 Dim Cif_cl As Byte ' hundreds figure of DY3 Dim Cif_ml As Byte ' thousands figure of DY4 Dim Cif_u As Byte ' units figure Dim Cif_d As Byte ' decines figure Dim Cif_c As Byte ' hundreds figure Dim Cif_m As Byte ' thousands figure Dim Cif_h As Byte ' stores 1 figure for 5678 Dim Cif_l As Byte ' stores 1 figure for 1234 Dim Num As Word ' general purpose Dim Dp As Byte ' indicates decimal point Dim Disp As Byte ' indicates which display is ' currently visualizing '******************************************************************************* ' '************************** Procedure declarations ***************************** ' Declare Sub Iniz ' Peripherals initialization etc. Declare Sub Conv_key ' conversion key in string Declare Sub Att_key ' Wait for key pressed Declare Sub Press ' "Press a Key" message Declare Sub Demo ' displays management demo Declare Sub Ins_num ' Input a number of max 8 figures Declare Sub Ins_dp ' Insert decimal point Declare Sub Chek_rinf ' Check that is not refreshing Declare Sub Sendclk ' outputs a CLK signal Declare Sub Sinc5480 ' RESETS M5480 OUTPUTS Declare Sub Testbit0 ' sets Psda as Bit0 status Declare Sub T_send ' Transmits a bit Declare Sub Leds ' LEDs On / Off management Declare Sub Dec_point(d As Byte) ' turn on indicated point decimal Declare Sub Send5480 (bit23 As Long) ' Communicates to M5480 the ' status of the outputs, through ' a 24 bits variable Declare Sub Conv7 (digit As Byte) ' converts a number from 0 to 9 ' in 7 segments Declare Sub C_cifre (num As Word , Dp As Byte) ' Converts a four figures number ' in four separated figures; ' activates the decimal point Declare Sub Conv_bit (disp As Byte , Cif_h As Byte , Cif_l As Byte) ' converts figures in bits for ' 5480 On Timer0 T0_int ' Response procedure to timer 0 ' interrupt ' ' ****************************** Main Program ********************************** ' Main: Waitms 1 ' Delay for signals settling Call Iniz ' variables initializations etc. Do Do Print Chr(cler) ; ' clear the screen Print "** DEMO program for KND08 with GPC(r) F2 REL.1.1 17.05.2000 **" Print Print "1) Count example" Print "2) Insert a number made of max 8 figures" Print "3) Insert the decimal point" Print "4) Turn LEDs On and Off" Print "5) Reset" Print Print "SELECT THE DESIRED MENU : " Print Call Att_key ' Wait a key pressed Print "Key=" ; If T = 0 Then Print Tstr; ' Show last key pressed Else If T > 31 Then Print Chr(t); ' Show key pressed Else Print Tstr; ' Show last key pressed End If End If Print Chr(13); ' back to line beginning Loop Until T <> 0 ' exit if received a character Call Conv_key ' convert key in string Select Case Tstr Case "1" : Call Demo ' display managemet demo Case "2" : Call Ins_num ' Input an 8 figures number Case "3" : Call Ins_dp ' Insert decimal point Case "4" : Call Leds ' LEDs management Case "5" : Num_h = 0 ' reset variables Num_l = 0 : Numero = 0 Dp_h = 0 : Dp_l = 0 D = 0 Led1 = 0 : Led2 = 0 : Led3 = 0 Led4 = 0 : Led5 = 0 : Led6 = 0 Call Press ' "Press a Key" message Call Att_key ' Wait for key pressed Case Else : Print Chr(bel); ' key not valid End Select Loop End ' ' ******************************** Program end ********************************* ' ' ' ******************************* Procedures *********************************** ' ' ************************ variables initialization etc. ********************** ' This procedure performs all the variables initializations, activates the ' TIMER 0 interrupt management. ' Parameters: ' Input : nothing ' Output : nothing ' ***************************************************************************** ' Sub Iniz ' variables initialization etc. Pclk = 0 ' set to low CLK signal Psda = 0 ' set to low Data signal Rinf = 0 ' reset refreshes count Disp = 0 ' point to displays 1 and 5 Led1 = 0 ' turn off Led 1 Led2 = 0 ' turn off Led 2 Led3 = 0 ' turn off Led 3 Led4 = 0 ' turn off Led 4 Led5 = 0 ' turn off Led 5 Led6 = 0 ' turn off Led 6 Numero = 0 ' resets the 8 figures number Num_h = 0 ' resets the figures on 5678 Num_l = 0 ' resets figures of display 1234 D = 0 ' turn off decimal point Dp_h = 0 ' decimal point 5678 off Dp_l = 0 ' decimal point 1234 off Load Timer0 , Ric ' when timer0 reaches 0, ' interrupt is triggered Enable Interrupts ' enable interrupts Enable Timer0 ' enable interrupt of timer0 Priority Set Timer0 ' timer0 interrupt priority high Start Timer0 ' timer0 starts Waitms 1 ' Delay for signals settling End Sub ' ' ************************** LEDs On / Off management ************************** ' This procedure allows to turn on and off the 6 LEDs on the KND 08 board. ' Parameters: ' Input : nothing ' Output : nothing ' ***************************************************************************** ' Sub Leds ' LEDs On / Off management Print Chr(cler) ; ' clear the screen Print Print "LEDs On / Off management" Print "1) On / Off LED 1" Print "2) On / Off LED 2" Print "3) On / Off LED 3" Print "4) On / Off LED 4" Print "5) On / Off LED 5" Print "6) On / Off LED 6" Print "7) Exit" Print Print "SELECT THE DESIRED LED : " Print Do Call Att_key ' wait a key Call Conv_key ' convert key in string Select Case Tstr Case "1" : Led1 = Not Led1 ' Turn On or Off LED 1 Case "2" : Led2 = Not Led2 ' Turn On or Off LED 2 Case "3" : Led3 = Not Led3 ' Turn On or Off LED 3 Case "4" : Led4 = Not Led4 ' Turn On or Off LED 4 Case "5" : Led5 = Not Led5 ' Turn On or Off LED 5 Case "6" : Led6 = Not Led6 ' Turn On or Off LED 6 End Select Loop Until Tstr = "7" ' exit if "7" is pressed End Sub ' ' ********************* Input of max 8 figures ********************************* ' This procedure allows to assing an 8 figures number to display ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_num ' Input of max 8 figures Print Print Input " Insert a number between 0 and 99999999 ? " , N If N > 99999999 Then ' if greater than 99999999 N = 99999999 ' set it to 99999999 End If Numero = N ' assign the selected number Call Chek_rinf ' Check that is not refreshing ' split the 8 figures number in two 4 figures number If Numero < 10000 Then ' if number is made of 4 figures Num_l = Numero ' low figures Num_h = 0 ' high figures Else Num_h = Numero / 10000 ' calculate low figures from the Num_l = Numero Mod 10000 ' remainder of high figures End If Call Press ' "Press a Key" message Call Att_key ' Wait for key pressed End Sub ' ' ************************ Insert decimal point ******************************* ' This procudire allows to turn on one of the 8 decimal points on the displays. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_dp ' Insert decimal point Print Print " Decimal point management" Print " 0 -> Turn off decimal point" Print " 1 -> Decimal point on units DY1" Print " 2 -> Decimal point on decines DY2" Print " 3 -> Decimal point on hundreds DY3" Print " 4 -> Decimal point on thousands DY4" Print " 5 -> Decimal point on units DY5" Print " 6 -> Decimal point on decines DY6" Print " 7 -> Decimal point on hundreds DY7" Print " 8 -> Decimal point on thousands DY8" Print Input " Insert a number between 0 and 8 ? " , D Call Dec_point(d) ' turn on indicated decimal point Call Press ' "Press a Key" message Call Att_key ' Wait for key pressed End Sub ' ' ********************* Turn on indicated decimal point ************************ ' This procedure selects a decimal point indicated with a number from 0 to 8. ' Parameters: 1 input ' Input: D as byte, value from 0 to 8. ' Output: Dp_l as byte, 0 turn off ' 1 turn on the decimal point of DY1 ' 2 turn on the decimal point of DY2 ' 3 turn on the decimal point of DY3 ' 4 turn on the decimal point of DY4 ' Dp_h as byte, 0 turn off ' 5 turn on the decimal point of DY5 ' 6 turn on the decimal point of DY6 ' 7 turn on the decimal point of DY7 ' 8 turn on the decimal point of DY8 ' ***************************************************************************** ' Sub Dec_point (d As Byte) Select Case D Case 0 : Dp_h = 0 ' turn off d. p. of DY5, 6, 7, 8 Dp_l = 0 ' turn off d. p. of DY1, 2, 3, 4 Case 1 : Dp_l = 1 ' turn on d. p. of DY1 Dp_h = 0 ' turn off d. p. of DY5, 6, 7, 8 Case 2 : Dp_l = 2 ' turn on d. p. of DY2 Dp_h = 0 ' turn off d. p. of DY5, 6, 7, 8 Case 3 : Dp_l = 3 ' turn on d. p. of DY3 Dp_h = 0 ' turn off d. p. of DY5, 6, 7, 8 Case 4 : Dp_l = 4 ' turn on d. p. of DY4 Dp_h = 0 ' turn off d. p. of DY5, 6, 7, 8 Case 5 : Dp_h = 1 ' turn on d. p. of DY5 Dp_l = 0 ' turn off d. p. of DY1, 2, 3, 4 Case 6 : Dp_h = 2 ' turn on d. p. of DY16 Dp_l = 0 ' turn off d. p. of DY1, 2, 3, 4 Case 7 : Dp_h = 3 ' turn on d. p. of DY7 Dp_l = 0 ' turn off d. p. of DY1, 2, 3, 4 Case Is => 8 : Dp_h = 4 ' turn on d. p. of DY8 Dp_l = 0 ' turn off d. p. of DY1, 2, 3, 4 End Select End Sub ' ' ************************ Verify that is not refreshing *********************** ' This procedure checks that interrupt is not executing a calculation to update ' the values to show on the displays. ' In facts the two variables Num_r and Num_v, are used to obtain the figures, ' so these variables must not be changed while the figures calculation is ' running. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Chek_rinf ' Verify that is not refreshing Do If Rinf < N_rinf Then ' not refreshing Exit Do Else If Disp <= 2 Then ' not visualizing on the Exit Do ' fourth display End If End If Loop ' check for displays update ' not running, else wait for ' 5ms. max End Sub ' ' ******************* Display management demo ********************************** ' This performs a count using an 8 figures number. ' During the count, a shift of all the decimal point and the 6 red LEDs occours. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Demo ' Display management demo Do For D = 0 To 8 ' visualize eight decimal points ' in sequence. Call Dec_point(d) Call Chek_rinf ' Verify that is not refreshing Incr Numero ' increment the counter If Numero > 99999999 Then ' if greater than 8 figures Numero = 0 ' reset it End If ' split the 8 figures number in two 4 figures number If Numero < 10000 Then ' if number is made of 4 figures Num_l = Numero ' low figures Num_h = 0 ' high figures Else Num_h = Numero / 10000 ' calculate low figures from the Num_l = Numero Mod 10000 ' remainder of high figures End If Led1 = 0 ' turn off Led 1 Led2 = 1 ' turn on Led 2 Led3 = 0 ' turn off Led 3 Led4 = 1 ' turn on Led 4 Led5 = 0 ' turn off Led 5 Led6 = 1 ' turn on Led 6 Waitms 100 ' delay Led1 = 1 ' turn on Led 1 Led2 = 0 ' turn off Led 2 Led3 = 1 ' turn on Led 3 Led4 = 0 ' turn off Led 4 Led5 = 1 ' turn on Led 5 Led6 = 0 ' turn off Led 6 Waitms 100 ' delay T = Inkey ' read a char from serial port If T <> 0 Then ' if a key was pressed Exit For ' exit from demo End If Next D Loop Until T <> 0 ' exit if a key was pressed End Sub ' ' ************************************************************************** ' * This procedure prepares the bits to send to M5480 (IC1 on KND 08) * ' * Parameters: 3 inputs, 1 output * ' * Inputs : var. Disp byte (da 0 a 3), indicates which display will be * ' * managed * ' * 0 -> DY4 and DY8 * ' * 1 -> DY3 and DY7 * ' * 2 -> DY2 and DY6 * ' * 3 -> DY1 and DY5 * ' * var. cif_v byte (from 0 to 255),7 segments figure for green * ' * var. cif_r byte (from 0 to 255),7 segments figure for red * ' * * ' * * ' * output : var. Bit23 Long * ' * Variable Bit23 ( 4 byte) is structured this way : * ' * Bit23+0 -> byte 0 indicates the figure for DY5, DY6, DY7, DY8 green * ' * * ' * Bit23+1 -> byte 1 indicates the figure for DY1, DY2, DY3, DY4 red * ' * * ' * Bit23+2 -> byte 2 * ' * bit0 enables display 4 and 8 enables Led1, 2, 3 * ' * bit1 enables display 3 and 7 enables Led4, 5, 6 * ' * bit2 enables display 2 and 6 * ' * bit3 display 1 and 5 * ' * bit4 Led3 and Led6 * ' * bit5 Led2 and Led5 * ' * bit6 Led1 and Led4 * ' * bit7 Not used * ' * Bit23+3 -> byte 3, all the 8 bit sare not used. * ' * * ' * A general purpose variable X8 is used. * ' * Variable X8 must be declared in the internal RAM, otherwise assembler * ' * instructions cannot be executed. * ' * * ' * var. Led1 bit (=1 led on) * ' * var. Led2 bit (=1 led on) * ' * var. Led3 bit (=1 led on) * ' * var. Led4 bit (=1 led on) * ' * var. Led5 bit (=1 led on) * ' * var. Led6 bit (=1 led on) * ' ************************************************************************** ' Sub Conv_bit (disp As Byte , Cif_h As Byte , Cif_l As Byte) ' converts 2 figures for 5480 IC1 X8 = Cif_h mov {bit23+0},{x8} ' store byte 0, with figure 1 X8 = Cif_l mov {bit23+1},{x8} ' store byte 1, with figure 2 Select Case Disp ' select wanted displays match Case 0 : X8 = &B00001110 ' turn on display 4 and 8 and Led If Led3 = 1 Then ' if LED 3 on X8 = X8 Or &B00010000 ' configure matched bit End If If Led2 = 1 Then ' if LED 2 on X8 = X8 Or &B00100000 ' configure matched bit End If If Led1 = 1 Then ' if LED 1 on X8 = X8 Or &B01000000 ' configure matched bit End If Case 1 : X8 = &B00001101 ' turn on display 3 and 7 If Led6 = 1 Then ' if LED 6 on X8 = X8 Or &B00010000 ' configure matched bit End If If Led5 = 1 Then ' if LED 5 on X8 = X8 Or &B00100000 ' configure matched bit End If If Led4 = 1 Then ' if LED 4 on X8 = X8 Or &B01000000 ' configure matched bit End If Case 2 : X8 = &B00001011 ' turn on display 2 and 6 Case Is => 3 : X8 = &B00000111 ' turn on display 1 and 5 End Select mov {bit23+2},{x8} ' store byte 2 End Sub ' ' ******************** Response to Timer0 interrupt ************************ ' * Response to Timer0 interrupt ( Timer1 is used for serial port) * ' * Every 5mS (see Const Ric) the visualization of two 7 segments displays * ' * are updated, the next intperrupt updates the other two ones until all * ' * 8 displays are updated in four passages. After 5 refresher (see Const * ' * N_rinf) the new figures to display are obtained from numbers Num_v and * ' * Num_r. * ' ************************************************************************** ' T0_int: Stop Timer0 ' stop timer0 Load Timer0 , Ric ' reload initial value Start Timer0 ' start timer0 Select Case Disp ' according to selected display Case 0 : Call Conv_bit(disp , Cif_mh , Cif_ml) ' prepare bits for DY4 and DY8 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(disp , Cif_ch , Cif_cl) ' prepare bits for DY3 and DY7 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(disp , Cif_dh , Cif_dl) ' prepare bits for DY2 and DY6 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(disp , Cif_uh , Cif_ul) ' prepare bits for DY1 and DY5 Disp = 0 ' restart from display 4 and 8 Incr Rinf ' 1 refresh completed, increment End Select Call Send5480(bit23) ' send informations to M5480 IC1 If Rinf => N_rinf Then ' if N refreshes occoured If Rinfvr = 0 Then ' refresh DY5, 6, 7, 8 Call C_cifre(num_h , Dp_h) ' recalculate four figures Num_h Cif_mh = Cif_m ' store thousands Cif_ch = Cif_c ' store hundreds Cif_dh = Cif_d ' store decines Cif_uh = Cif_u ' store units Else ' refresh i DY1, 2, 3, 4 Call C_cifre(num_l , Dp_l) ' recalculate four figures Num_l Cif_ml = Cif_m ' store thousands Cif_cl = Cif_c ' store hundreds Cif_dl = Cif_d ' store decines Cif_ul = Cif_u ' store units Rinf = 0 ' reset refresh counter End If Rinfvr = Not Rinfvr ' invert bit status End If Return ' ********************************************************************** ' ' ********************************************************************** ' * Converts 1 four figures number in 4 separated figures * ' * for the 7 segments displays, also manages decimal point for one of * ' * the four displays. * ' * * ' * Parameters : 2 inputs, 4 outputs * ' * inputs : var. num (from 0 to 9999) * ' * var. dp byte (from 0 to 4) * ' * dp =0 -> decimal point off * ' * dp =1 -> decimal point units on * ' * dp =2 -> decimal point decines on * ' * dp =3 -> decimal point hundreds on * ' * dp =4 -> decimal point thousands on * ' * * ' * outputs :Cif_m tipo byte, figure of thousands * ' * Cif_c Tipo Byte , figure of hundreds * ' * Cif_d Tipo Byte , figure of decines * ' * Cif_u Tipo Byte , figure of units * ' * N.B. var. X16 word general purpose * ' ********************************************************************** ' Sub C_cifre (num As Word , Dp As Byte) ' Converts 1 four figures number ' in 4 separated figures; manages ' decimal point If Num > 9999 Then ' if greater than 9999 Num = 9999 ' set it to 9999 End If Cif_m = Num / 1000 ' obtain figure of thousands X16 = Num Mod 1000 ' obtain remainder Cif_c = X16 / 100 ' obtain figure of hundreds X16 = X16 Mod 100 ' obtain remainder Cif_d = X16 / 10 ' obtain figure of decines X16 = X16 Mod 10 ' obtain remainder Cif_u = X16 ' obtain figure of units Call Conv7(cif_m) ' convert figure in 7 segments Cif_m = Digit ' store the value If Dp = 4 Then ' if "dp" of thousands is on Cif_m = Cif_m Or &B10000000 ' turn on decimal point End If Call Conv7(cif_c) ' convert figure in 7 segments Cif_c = Digit If Dp = 3 Then ' if "dp" of hundreds is on Cif_c = Cif_c Or &B10000000 ' turn on decimal point End If Call Conv7(cif_d) ' convert figure in 7 segments Cif_d = Digit If Dp = 2 Then ' if "dp" of decines is on Cif_d = Cif_d Or &B10000000 ' turn on decimal point End If Call Conv7(cif_u) ' convert figure in 7 segments Cif_u = Digit If Dp = 1 Then ' if "dp" of units is on Cif_u = Cif_u Or &B10000000 ' turn on decimal point End If End Sub ' ' *********** Converts a figure in range from 0 to 9 in 7 segments ******* ' This procedure converts a figure in range from 0 to 9 in 7 segments ' format, if value is greater than 9 the display is off. Decimal point is ' always off. ' Parameters: ' Input : digit as byte, value from 0 to 9 ' Output : digit as byte, value in 7 segments format. ' ************************************************************************ ' Sub Conv7 (digit As Byte) ' Converts a figure from 0 to 9 ' in 7 segments If Digit < 10 Then ' if lower than 10 Digit = Lookup(digit , Tab_7seg) ' read value from table Else Digit = 0 ' if = or > 10 turn off display End If End Sub ' ' ************* Communicates to M5480 IC1 status of outputs ************ ' * Transmits the content of variable Bit23 type Long. * ' * Variable Bit23 must be declared in internal RAM, otherwise * ' * assembler instructions cannot be execured. * ' * Trasmette il contenuto della variabile Bit23 di tipo Long. * ' * * ' * Parameters: 1 input * ' * ingresso : variable bit32 Long (usaed 3 byte out of 4). * ' * output : nothing. * ' ********************************************************************** ' Sub Send5480 (bit23 As Long) ' Communicates to M5480 status of ' outputs, through the content of ' a 24 bits variable. push acc ' save accumulator push psw ' save carry Call Sinc5480 ' Synchronize sequence Psda = 1 ' start Call Sendclk ' start sequence Call Sendclk ' sequence 1 mov acc,{bit23+0} ' fetch byte 0 of 3 Call Testbit0 ' output bit 0 (bit1 pin12 5480) Call Sendclk ' sequence 2 Call T_send ' output bit 1 (bit2 pin11 5480) ' sequence 3 Call T_send ' output bit 2 (bit3 pin10 5480) ' sequence 4 Call T_send ' output bit 3 (bit4 pin9 5480) ' sequence 5 Call T_send ' output bit 4 (bit5 pin8 5480) ' sequence 6 Call T_send ' output bit 5 (bit6 pin7 5480) ' sequence 7 Call T_send ' output bit 6 (bit7 pin6 5480) ' sequence 8 Call Sendclk ' sequence 9 Call Sendclk ' sequence 10 Call Sendclk ' sequence 11 Call T_send ' output bit 7 (bit8 pin5 5480) ' sequence 12 mov acc,{bit23+1} ' fetch byte 1 of 3 Call Testbit0 ' output bit 0 (bit9 pin4 5480) Call Sendclk ' sequence 13 Call T_send ' output bit 1 (bit10 pin3 5480) ' sequence 14 Call T_send ' output bit 2 (bit11 pin2 5480) ' sequence 15 Call Sendclk ' sequence 16 Call Sendclk ' sequence 17 Call Sendclk ' sequence 18 Call Sendclk ' sequence 19 Call T_send ' output bit 3 (bit12 pin28 5480) ' sequence 20 Call T_send ' output bit 4 (bit13 pin27 5480) ' sequence 21 Call T_send ' output bit 5 (bit14 pin26 5480) ' sequence 22 Call T_send ' output bit 6 (bit15 pin25 5480) ' sequence 23 Call T_send ' output bit 7 (bit16 pin24 5480) ' sequence 24 mov acc,{bit23+2} ' fetch byte 2 of 3 Call Testbit0 ' output bit 0 (bit17 pin23 5480) Call Sendclk ' sequence 25 Call Sendclk ' sequence 26 Call T_send ' output bit 1 (bit18 pin22 5480) ' sequence 27 Call Sendclk ' sequence 28 Call Sendclk ' sequence 29 Call T_send ' output bit 2 (bit19 pin21 5480) ' sequence 30 Call T_send ' output bit 3 (bit20 pin20 5480) ' sequence 31 Call T_send ' output bit 4 (bit21 pin19 5480) ' sequence 32 Call T_send ' output bit 5 (bit22 pin18 5480) ' sequence 33 Call T_send ' output bit 6 (bit23 pin17 5480) ' sequence 34 Psda = 0 Call Sendclk ' sequence 35 Call Sendclk ' sequence 36 Call Sendclk ' sequence 37 pop psw ' restore carry pop acc ' restore accumulator End Sub ' ' *************** Moves bit0 of accumulator in bit Psda ********************** ' Parameters: none ' Input : nothing ' Output : nothing ' **************************************************************************** ' Sub Testbit0 mov c,acc.0 ' store accumulator bit 0 in carry mov {psda},c ' set pin using carry value End Sub ' ' ************************ Outputs a CLK impulse ******************************* ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Sendclk Pclk = 0 ' set CLK to zero Pclk = 1 ' set CLK to one End Sub ' ' Sub T_send rr acc ' rotate accumulator Call Testbit0 Call Sendclk End Sub ' ' *************************** Synchronize M5480 sequence *********************** ' This procedure outputs 37 CLK impulses to synchronize the data ' sequence. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Sinc5480 Psda = 0 ' set data signal to zero For X = 1 To 37 ' repeat 37 times Call Sendclk ' output CLK impulse Next X End Sub ' ' ****************** Wait for a key suspending the program ********************* ' Parameters: 1 output ' Input: nothing ' Output: T type byte, contains the code received from the serial line ' ****************************************************************************** ' Sub Att_key Do T = Inkey ' read character from the serial Loop Until T <> 0 ' wait for a character End Sub ' ' ******************************************************************* ' Sub Press ' "Press a key" message Print Print Print Print "Press a key to continue..." Print End Sub ' ' ******************** Conversion from key to string *************************** ' This procedure converts a character whose code ranges from 31 to 127 in a ' string. If character is out of range the string contains a blank ' Parameters: ' Input: T as byte, character received ' Output: Tstr as String *1, string obtained from character received ' ****************************************************************************** ' Sub Conv_key ' Conversion from key to string If T > 31 Then ' if printable character T = T And &H7F ' clear bit7 Tstr = Chr(t) ' convert the character in string Else ' otherwise Tstr = " " ' set string to a blank End If End Sub ' ' ******************************************************************* ' ' ' ***************** Conversion table for 7 segments figure ********************* Tab_7seg: ' num. 0 1 2 3 4 5 6 7 8 9 Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H6F ' ************************************************************************** '