' ********************************************************************** ' ** Program name: KND44au.BAS - Version : 1.2 - 14 March 2001 ** ' ** Compiler : BASCOM AVR (IDE V. 1.11.5.0, LIB V. 1.11.5.0) ** ' ** 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: Graziano GAIBA ** ' ********************************************************************** ' ' 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 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 44 is K51-AVR, connections are. ' K51-AVR KND 44 ' L1 (pin4 CN6) ----> SC (pin2 CN1 KND44) ' L2 (pin5 CN6) ----> SD (pin1 CN1 KND44) ' 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 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 Long ' four figures number for green ' displays DY5, DY6, DY7, DY8. Dim Num_r As Long ' 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 Tasto As Byte ' generic use ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' 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 Long ' units figure of green DY5 Dim Cif_dv As Long ' decines figure of green DY6 Dim Cif_cv As Long ' hundreds figure of green DY7 Dim Cif_mv As Long ' thousands figure of green DY8 Dim Cif_ur As Long ' units figure of red DY1 Dim Cif_dr As Long ' decines figure of red DY2 Dim Cif_cr As Long ' hundreds figure of red DY3 Dim Cif_mr As Long ' thousands figure of red 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_a As Long ' contains 1 green display figure Dim Cif_b As Long ' 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 Dim Cifa As Long ' parameters passage Dim Cifb As Long ' parameters passage 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_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 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 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 Cifa As Long , Byval Cifb As Long) ' 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 matched to K51-AVR REL.1.2 14.03.2001 **" 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 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_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 Tasto = Att_key() ' wait a key 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_mv , Cif_mr) ' prepare bits for DY4 and DY8 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(cif_cv , Cif_cr) ' prepare bits for DY3 and DY7 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(cif_dv , Cif_dr) ' prepare bits for DY2 e DY6 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(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 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 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 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 Tasto = Att_key() ' wait a key Select Case Tasto 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 Tasto = "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 Local V As Long , T As Byte Print Print Print " Insert a number between 0 and 9999 ? " ; V = Iv() Call Chek_rinf ' Verify not renfreshing Num_v = V ' assign the number to green ones Call Press ' "Press a key" message T = 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 Local V As Long , T As Byte Print Print Print " Insert a number between 0 and 9999 ? " ; V = Iv() Call Chek_rinf ' Verify not renfreshing Num_r = V ' assign the number to red ones Call Press ' "Press a key" message T = 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. Local D As Long , T As Byte 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 Print " Insert a number between 0 and 4 ? " ; D = Iv() Dp_v = D ' assign decimal point Call Press ' "Press a key" message T = 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. Local D As Long , T As Byte 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 Print " Insert a number between 0 and 4 ? " ; D = Iv() Dp_r = D ' assign decimal point Call Press ' "Press a key" message T = 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 Local T As Byte 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 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 Cifa As Long , Byval Cifb As Long) ' converts 2 figures for 5480 IC1 Local X8 As Byte Local Bit32 As Long Bit23 = 0 X8 = Cifa ' store byte 0, with 1st figure Bit23 = X8 X8 = Cifb ' 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 ' ****************************************************************************** '