' ********************************************************************** ' ** Program name: KND08au.BAS - Version : 1.2 - 07 March 2001 ** ' ** Compiler : BASCOM AVR (IDE V. 1.11.5.0, LIB V. 1.11.5.0) ** ' ** 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: Graziano GAIBA ** ' ********************************************************************** ' ' 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 CN2 of K51-AVR. ' To configure the BASCOM terminal in menu Options/Communication ' select the COM port and set Baud Rate to 19200, parity to none, ' databits to 8, stopbits to 1. ' The board used to drive KND 08 is K51-AVR, connections are: ' K51-AVR KND 08 ' L1 (pin4 CN6) ----> SC (pin2 CN1 KND08) ' L2 (pin5 CN6) ----> SD (pin1 CN1 KND08) ' Supply both the boards. ' ' ++++++********** ATTENTION **********++++++ ' + + ' + To compile correctly the program: + ' + 1) enter menu Options/Compiler/Chip + ' + 2) set to 130 the value of Stacksize + ' + 3) set to 80 the value of Framesize + ' + + ' ++++++********** ATTENTION **********++++++ ' '*********************************************************************** ' '********************* Compiler Directives ***************************** ' $regfile = "8515def.DAT" ' AT90s8515 registers list $romstart = &H0 ' code start address $crystal = 5529600 ' micro clock frequence $baud = 19200 ' baud rate ' Configures timer 0 as timer and set prescaler to divide clock signal by 256 Config Timer0 = Timer , Prescale = 256 ' '********************* Constants declaration *************************** ' Pclk Alias Portd.3 ' line L1 on CN6 of K51-AVR Config Pind.3 = Output ' drives Clock signal. Psda Alias Portd.4 ' line L2 on CN6 of K51-AVR Config Pind.4 = Output ' drives Data signal. Const Ric = 151 ' generates an interrupt every ' 4.88 mS witc clock ' frequence 5.5296MHz. Const Cler = 12 ' clear screen code Const Bel = 7 ' Bell code 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 Long ' four figures number for display ' DY5, DY6, DY7, DY8. Dim Num_l As Long ' four figures number for display ' DY1, DY2, DY3, DY4. Dim Decpt As Long ' 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 Tasto As Byte ' general purpose Dim Tstr As String * 1 ' general purpose string variable Dim Numh As Long ' parameters passage Dim Numl As Long ' parameters passage ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' 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 Long ' units figure of DY5 Dim Cif_dh As Long ' decines figure of DY6 Dim Cif_ch As Long ' hundreds figure of DY7 Dim Cif_mh As Long ' thousands figure of DY8 Dim Cif_ul As Long ' units figure of DY1 Dim Cif_dl As Long ' decines figure of DY2 Dim Cif_cl As Long ' hundreds figure of DY3 Dim Cif_ml As Long ' thousands figure of DY4 Dim Cif_u As Long ' units figure Dim Cif_d As Long ' decines figure Dim Cif_c As Long ' hundreds figure Dim Cif_m As Long ' thousands figure Dim Cif_h As Long ' stores 1 figure for 5678 Dim Cif_l As Long ' 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 Dim Cifra As Long ' parameters passage '******************************************************************************* ' '************************** Procedure declarations ***************************** ' Declare Function Iv() As Long ' Decimal value input Declare Sub Iniz ' Peripherals initialization etc. Declare Function Att_key() As Byte ' 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(byval Decpt As Long) ' 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 Function Conv7 (byval Cifra As Long) As Byte ' converts a number from 0 to 9 ' in 7 segments Declare Sub C_cifre (num As Long , Dp As Byte) ' Converts a four figures number ' in four separated figures; ' activates the decimal point Declare Sub Conv_bit (byval Cifh As Long , Byval Cifl As Long) ' 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 matched to K51-AVR REL.1.2 07.03.2001 **" 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 Tasto = Att_key() ' wait for a key Print "Key=" ; If Tasto <> 0 Then Print Chr(tasto); End If ' Show last key pressed Print Chr(13); ' back to beginning of line Loop Until Tasto <> 0 ' exit if received a character Select Case Tasto 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 Led1 = 0 : Led2 = 0 : Led3 = 0 Led4 = 0 : Led5 = 0 : Led6 = 0 Call Press ' "Press a Key" message Tasto = Att_key() ' Wait for key pressed Case Else : Print Chr(bel); ' key not valid End Select Loop ' ' ******************** 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 Timer0 = Ric ' reload initial value Start Timer0 ' start timer0 Select Case Disp ' according to selected display Case 0 : Call Conv_bit(cif_mh , Cif_ml) ' prepare bits for DY4 and DY8 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(cif_ch , Cif_cl) ' prepare bits for DY3 and DY7 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(cif_dh , Cif_dl) ' prepare bits for DY2 and DY6 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(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 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 Dp_h = 0 ' decimal point 5678 off Dp_l = 0 ' decimal point 1234 off Timer0 = Ric ' when timer0 reaches 0, ' interrupt is triggered Enable Interrupts ' enable interrupts Enable Timer0 ' enable interrupt of timer0 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 Local T As Byte 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 T = Att_key() ' wait a key Select Case T 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 T = "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 Local T As Byte Print Print Print " Insert a number between 0 and 99999999 ? " ; Numero = Iv() If Numero > 99999999 Then ' if greater than 99999999 Numero = 99999999 ' set it to 99999999 End If 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 T = 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 Local T As Byte , L As Long 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 Print " Insert a number between 0 and 8 ? " ; L = Iv() Call Dec_point(l) ' turn on indicated decimal point Call Press ' "Press a Key" message T = 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 (byval Decpt As Long) Select Case Decpt 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 Local T As Byte , D As Long 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 (byval Cifh As Long , Byval Cifl As Long) ' converts 2 figures for 5480 IC1 Local X8 As Byte Local Bit32 As Long Bit23 = 0 X8 = Cifh ' store byte 0, with 1st figure Bit23 = X8 X8 = Cifl ' store byte 1, with 2nd figure Bit32 = X8 Shift Bit32 , Left , 8 Bit23 = Bit23 Or Bit32 Select Case Disp ' select wanted display match Case 0 : X8 = &B00001110 ' turn on displays 4 and 8 and Led If Led3 = 1 Then ' if LED 3 ON X8 = X8 Or &B00010000 ' configure corresponding bit End If If Led2 = 1 Then ' if LED 2 ON X8 = X8 Or &B00100000 ' configure corresponding bit End If If Led1 = 1 Then ' if LED 1 ON X8 = X8 Or &B01000000 ' configure corresponding bit End If Case 1 : X8 = &B00001101 ' turn on displays 3 and 7 If Led6 = 1 Then ' if LED 6 ON X8 = X8 Or &B00010000 ' configure corresponding bit End If If Led5 = 1 Then ' if LED 5 ON X8 = X8 Or &B00100000 ' configure corresponding bit End If If Led4 = 1 Then ' if LED 4 ON X8 = X8 Or &B01000000 ' configure corresponding bit End If Case 2 : X8 = &B00001011 ' turn on displays 2 and 6 Case Is => 3 : X8 = &B00000111 ' turn on displays 1 and 5 End Select Bit32 = X8 ' store byte 2 Shift Bit32 , Left , 16 Bit23 = Bit23 Or Bit32 End Sub ' ' ********************************************************************** ' ' ********************************************************************** ' * 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 Long , Dp As Byte) ' Converts 1 four figures number ' in 4 separated figures; manages ' decimal point Local X16 As Word 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 Digit = 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 Digit = 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 Digit = 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 Digit = 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. ' ************************************************************************ ' Function Conv7 (byval Cifra As Long) As Byte ' Converts a figure from 0 to 9 ' in 7 segments If Cifra < 10 Then ' if lower than 10 Conv7 = Lookup(cifra , Tab_7seg) ' read value from table Else Conv7 = 0 ' if = or > 10 turn off display End If End Function ' ' ************* 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 bit23 Long (used 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. Local I As Byte Call Sinc5480 ' Synchronize the sequence Psda = 1 ' start Call Sendclk ' start sequence For I = 1 To 34 ' send bits ' sequences from 1 to 34 Select Case I Case 1 : ' sequence 1 Call Sendclk Case 9 To 11: ' sequences from 9 to 11 Call Sendclk Case 16 To 19: ' sequences from 16 to 19 Call Sendclk Case 26 : ' sequence 1 Call Sendclk Case 28 To 29 : ' sequence 1 Call Sendclk Case Else: Call Testbit0 ' sends bit Call Sendclk ' sends clock pulse Shift Bit23 , Right ' Prepare next bit End Select Next I Psda = 0 Call Sendclk ' sequence 35 Call Sendclk ' sequence 36 Call Sendclk ' sequence 37 End Sub ' ' *************** Moves bit0 of accumulator in bit Psda ********************** ' Parameters: none ' Input : nothing ' Output : nothing ' **************************************************************************** ' Sub Testbit0 Psda = Bit23.0 ' Least significant bit of ' Bit32 is sent to Data signal End Sub ' ' ************************ Outputs a CLK impulse ******************************* ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Sendclk Pclk = 0 ' set CLK to zero Waitus 2 ' Waits for 2 usec Pclk = 1 ' set CLK to one Waitus 2 ' Waits for 2 usec End Sub ' ' *************************** Synchronize M5480 sequence *********************** ' This procedure outputs 37 CLK impulses to synchronize the data ' sequence. ' Parameters: ' Input : nothing ' Output : nothing ' ****************************************************************************** ' Sub Sinc5480 Local X As Byte 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 ' ****************************************************************************** ' Function Att_key() As Byte Local T As Byte Do T = Inkey() ' read character from the serial Loop Until T <> 0 ' wait for a valid character Att_key = T ' Return the character End Function ' ' ******************************************************************* ' Sub Press ' "Press a key" message Print Print Print Print "Press a key to continue..." Print End Sub ' ' ************************ Decimal value input ****************************** ' * Parameters: 1 output * ' * Ingresso: * ' * Uscita: type byte, contains the value input through serial port * ' **************************************************************************** ' Function Iv() As Long Local Count As Byte ' number of characters received Local Key As Byte ' characters read Local Valore As String * 10 ' final string Local Strkey As String * 1 ' character read -> string Count = 0 ' Inizialize counter Valore = "" ' Inizialize string Do Do Key = Inkey() ' read one character Loop Until Key <> 0 ' exit if valid character If Count < 10 Then ' read less than 10 characters? Select Case Key ' If key read is... Case "0" To "9": ' ...a decimal figure Strkey = Chr(key) ' Converts in string Print Strkey; ' Echo Valore = Valore + Strkey ' Queues to final string Incr Count ' Increments counter End Select End If Loop Until Key = 13 ' Exits if Enter Print ' New line Iv = Val(valore) ' Returns final string End Function ' ' ******************************************************************* ' ' ' ***************** 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 ' ************************************************************************** '