' ********************************************************************** ' ** Program name: KND44_F2.BAS - Version : 1.1 - 17 May 2000 ** ' ** Compiler : BASCOM 8051, (IDE V.1.0.0.20, LIB V.1.20) ** ' ** Board : KND 44 ** ' ** 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 44 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 44 is K51-AVR, connections are. ' GPC F2 KND44 ' +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) = 60. ' ' 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 Clock 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 group (red or ' green displays) is to update 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 Num_v As Word ' four figures number for green ' displays DY5, DY6, DY7, DY8. Dim Num_r As Word ' four figures number for red ' displays DY1, DY2, DY3, DY4. Dim Dp_v As Byte ' position of decimal point in ' green displays group Dim Dp_r As Byte ' position of decimal point in ' red displays group Dim T As Byte ' contains the character received Dim V As Word , X As Byte , D As Byte ' generic use Dim Tstr As String * 1 ' generic use string variable ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' Dim X8 As Byte ' generic use for interrupt only Dim X16 As Word ' generic use Dim Bit23 As Long ' 24 bits wide variable that ' stores bit frame for l'M5480 Dim Rinf As Byte ' stores the number of renfreshes ' for green displays verdi, ' before updating the value Dim Digit As Byte ' contains conversion in digit Dim Cif_uv As Byte ' units figure of green DY5 Dim Cif_dv As Byte ' decines figure of green DY6 Dim Cif_cv As Byte ' hundreds figure of green DY7 Dim Cif_mv As Byte ' thousands figure of green DY8 Dim Cif_ur As Byte ' units figure of red DY1 Dim Cif_dr As Byte ' decines figure of red DY2 Dim Cif_cr As Byte ' hundreds figure of red DY3 Dim Cif_mr As Byte ' thousands figure of red 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_a As Byte ' contains 1 green display figure Dim Cif_b As Byte ' contains 1 red display figure Dim Num As Word ' generic number Dim Dp As Byte ' 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_n_v ' Insert 4 figures for green dis. Declare Sub Ins_n_r ' Insert 4 figures for red dis. Declare Sub Ins_dp_v ' Ins. decimal point for green d. Declare Sub Ins_dp_r ' Ins. decimal point for red dis. Declare Sub Chek_rinf ' Verify that not refreshing Declare Sub Sendclk ' outputs a CLK signal Declare Sub Sinc5480 ' RESETS M5480 OUTPUTS Declare Sub Testbit0 ' seta Psda as Bit0 status Declare Sub T_send ' Transmits a bit Declare Sub Leds ' LEDs On / Off management 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_a As Byte , Cif_b As Byte) ' converts figures in bits for ' 5480 On Timer0 T0_int ' Response procedure to timer 0 ' interrupt ' '************************* Programma main ****************************** ' Main: Waitms 1 ' Delay for signals settling Call Iniz ' variables initializations etc. Do Do Print Chr(cler) ; ' clear the screen Print "** DEMO program for KND 44 with GPC(r) F2 REL.1.1 17.05.2000 **" Print Print "1) Count example" Print "2) Insert 4 figures in the green displays" Print "3) Insert 4 figures in the red displays" Print "4) Decimal point in the green displays" Print "5) Decimal point in the red displays" Print "6) Turn LEDs On and Off" Print "7) 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_n_v ' Insert 4 figures for green d. Case "3" : Call Ins_n_r ' Insert 4 figures for red d. Case "4" : Call Ins_dp_v ' Ins. decimal point for green d. Case "5" : Call Ins_dp_r ' Ins. decimal point for red d. Case "6" : Call Leds ' LEDs management Case "7" : Num_v = 0 ' reset variables Num_r = 0 Dp_v = 0 : Dp_r = 0 Led1 = 0 : Led2 = 0 : Led3 = 0 Led4 = 0 : Led5 = 0 : Led6 = 0 Call Press ' "press a key" message Call Att_key ' wait a key 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 Num_v = 0 ' clear green displays Num_r = 0 ' clear red displays Dp_v = 0 ' decimal point of green off Dp_r = 0 ' decimal point of red 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 44 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 ' ' ***************** Insert four figures for green displays ********************* ' This procedure allows to assign a 4 figures number to the green displays ' DY5, DY6, DY7, DY8. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_n_v ' Insert 4 figures for green ones Print Print Input " Insert a number between 0 and 9999 ? " , V Call Chek_rinf ' Verify not renfreshing Num_v = V ' assign the number to green ones Call Press ' "Press a key" message Call Att_key ' wait a key End Sub ' ' ******************* Insert four figures for red displays ********************* ' This procedure allows to assign a 4 figures number to the red displays ' DY1, DY2, DY3, DY4. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_n_r ' Insert 4 figures for red ones Print Print Input " Insert a number between 0 and 9999 ? " , V Call Chek_rinf ' Verify not renfreshing Num_r = V ' assign the number to red ones Call Press ' "Press a key" message Call Att_key ' wait a key End Sub ' ' ************ Insert decimal point for green displays ************************* ' This procedure allows to turn on one of the decimal points in the four green ' displays DY5, DY6, DY7, DY8. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_dp_v ' Ins. decimal point for green d. Print Print " Green displays decimal point management" Print " 0 -> Turn off decimal point" Print " 1 -> Decimal point on units DY5" Print " 2 -> Decimal point on decines DY6" Print " 3 -> Decimal point on hundreds DY7" Print " 4 -> Decimal point on thousands DY8" Print Input " Insert a number between 0 and 4 ? " , D Dp_v = D ' assign decimal point Call Press ' "Press a key" message Call Att_key ' wait a key End Sub ' ' ************** Insert decimal point for red displays ************************* ' This procedure allows to turn on one of the decimal points in the four red ' displays DY1, DY2, DY3, DY4. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Ins_dp_r ' Ins. decimal point for green d. Print Print " Red displays 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 Input " Insert a number between 0 and 4 ? " , D Dp_r = D ' assign decimal point Call Press ' "Press a key" message Call Att_key ' wait a key End Sub ' ' ************************** Verify that 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 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 procedure initializes two different numbers for red and green displays, ' increments the number for one display and decrements the other one. ' 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 Num_v = 0 ' initialize count value Num_r = 9999 ' initialize count value Do For Dp_v = 0 To 4 ' visualize green decimal points ' in sequence. Call Chek_rinf ' check for not renfresh Incr Num_v ' increment the counter If Num_v > 9999 Then ' if over four figures Num_v = 0 ' reset it 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 200 ' delay Call Chek_rinf ' check for not renfresh Dp_r = 4 - Dp_v ' visualize red decimal points ' in sequence opposite to green. Decr Num_r ' decrement the counter If Num_r = 0 Then ' if reached aero Num_r = 9999 ' set it to highest value End If 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 200 ' delay T = Inkey ' read a char from serial port If T <> 0 Then ' is a key pressed Exit For ' exit from demo End If Next Dp_v Loop Until T <> 0 ' exit if a key pressed End Sub ' ' ************************************************************************** ' * This procedure prepares the bits to send to M5480 (IC1 on KND 44) * ' * Parameters: 3 inputs, 1 output * ' * Inputs : var. Disp byte (da 0 a 3), indicates which display will be * ' * managed * ' * red green * ' * 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 bitsare 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_a As Byte , Cif_b As Byte) ' converts 2 figures for 5480 IC1 X8 = Cif_a mov {bit23+0},{x8} ' store byte 0, with figure 1 X8 = Cif_b 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_mv , Cif_mr) ' prepare bits for DY4 and DY8 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(disp , Cif_cv , Cif_cr) ' prepare bits for DY3 and DY7 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(disp , Cif_dv , Cif_dr) ' prepare bits for DY2 e DY6 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(disp , Cif_uv , Cif_ur) ' prepare bits for DY1 e 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 green displays Call C_cifre(num_v , Dp_v) ' recalculate four figures Num_v Cif_mv = Cif_m ' store thousands Cif_cv = Cif_c ' store hundreds Cif_dv = Cif_d ' store decines Cif_uv = Cif_u ' store units Else ' refresh red displays Call C_cifre(num_r , Dp_r) ' recalculate four figures Num_r Cif_mr = Cif_m ' store thousands Cif_cr = Cif_c ' store hundreds Cif_dr = Cif_d ' store decines Cif_ur = 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 ********************** ' Parametri: nessuno ' Ingresso: ' Uscita: ' **************************************************************************** ' 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 whise code ranges from 31 to 127 in a ' string. If character is out of range the string contains a blank ' Questa procedura converte un carattere compreso fra 31 e 127 in stringa. ' 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 strig 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 ' ****************************************************************************** '