' ********************************************************************** ' ** Program name: KAD082F2.BAS - Version : 1.1 - 17 May 2000 ** ' ** Compiler : BASCOM 8051, (IDE V.1.0.0.20, LIB V.1.20) ** ' ** Board : KAD 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 resources on the KAD 08 board through a ' menu and 2 TTL lines driven by a microcontroller of the 51 family. ' This program is controlled through the RS 232 serial line so it is essential ' to connect a free COM port on the PC to the connector CN3 of GPC(r) F2. ' Configure the BASCOM 8051 terminal using menu Option/Communication, select ' the COM port and set baud rate to 9600, parity to none, databits to 8 and ' stopbits to 1. ' The master board is GPC(r) F2 which must be connected to KAD 08 as follows: ' GPC F2 KAD 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) = 50. ' ' 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 ' clear screen code Const Bel = 7 ' Bell code 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) ' '*********************** Variables declaration ******************************** ' Dim Led1 As Bit ' indicates status of Led 1, 1=On Dim Led2 As Bit ' indicates status of Led 2, 1=On Dim Led3 As Bit ' indicates status of Led 3, 1=On Dim Led4 As Bit ' indicates status of Led 4, 1=On Dim C1 As Byte ' code for DY4/1 Dp1 Alias C1.7 ' decimal point of DY4/1, 1=On Dim C2 As Byte ' code for DY4/2 Dp2 Alias C2.7 ' decimal point of DY4/2, 1=On Dim C3 As Byte ' code for DY3/1 Dp3 Alias C3.7 ' decimal point of DY3/1, 1=On Dim C4 As Byte ' code for DY3/2 Dp4 Alias C4.7 ' decimal point of DY3/2, 1=On Dim C5 As Byte ' code for DY2/1 Dp5 Alias C5.7 ' decimal point of DY2/1, 1=On Dim C6 As Byte ' code for DY2/2 Dp6 Alias C6.7 ' decimal point of DY2/2, 1=On Dim C7 As Byte ' code for DY1/1 Dp7 Alias C7.7 ' decimal point of DY1/1, 1=On Dim C8 As Byte ' code for DY1/2 Dp8 Alias C8.7 ' decimal point of DY1/2, 1=On Dim D As Byte ' tells which decimal point is on Dim T As Byte ' saves character received Dim Tstr As String * 1 ' one-char generic use string Dim X As Byte ' general purpose variable Dim N As Byte ' general purpose variable ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' Dim X8 As Byte ' general purpose for interrupt Dim Bit32 As Long ' 32 bits wide variable that ' stores the bit frame for M5480 Dim Bit3 As Byte ' 3 bits for M5451 frame Dim Digit As Word ' contains conversion in digit Dim Disp As Byte ' indicates which display is ' currently visualizing Dim Cif_h As Byte ' digit on DY4 and DY3 Dim Cif_l As Byte ' digit on DY2 and DY1 ' ****************************************************************************** ' '************************** Procedure declarations ***************************** ' Declare Sub Iniz ' Peripherals initialization etc. Declare Sub Conv_key ' converts key pressed in string Declare Sub Att_key ' wait for key pressed Declare Sub Press ' "Press a key..." message Declare Sub Demo ' display management example Declare Sub Decimal_point ' decimal point activation Declare Sub Ins_car ' show ASCII char on displays Declare Sub Leds ' On / Off LEDs management Declare Sub Sendclk ' outputs a CLK signal Declare Sub Sinc5451 ' resets M5451 outputs Declare Sub Testbit0 ' sets Psda as status of Bit0 Declare Sub T_send ' sends a bit Declare Sub Send5451 (bit32 As Long , Bit3 As Byte) ' Communicates to M5451 the ' status of the outputs, through ' a 32+3 bits variable Declare Sub Ruota ' rotates left the displays Declare Sub Conv14 (digit As Word) ' converts a number from 0 to 127 ' in 14 segments (see ASCII code) 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. N = 0 ' reset the variable Do ' visualize a ROM message C8 = Lookup(n , Messaggio) ' read a character of the message ' and display it on DY1/2 If C8 <> 0 Then ' if character is not null Incr N ' increment by 1 the variable Waitms 150 ' delay Call Ruota ' left shift of the 8 displays End If Loop Until C8 = 0 ' exit only if character is = 0 Do Do Print Chr(cler) ; ' clear the screen Print "** DEMO for KAD 08 connected to GPC(r) F2 REL.1.1 17.05.2000 **" Print Print "1) Example of use" Print "2) Show an ASCII char from 0 to 127" Print "3) Decimal point activation" Print "4) Turn LEDs On and Off" Print "5) Reset" Print Print "SELECT THE DESIRED MENU : " Print Call Att_key ' wait for a key Print "Key=" ; If T = 0 Then Print Tstr; ' show last key Else If T > 31 Then ' if printable Print Chr(t); ' show last key pressed Else Print Tstr; ' show last key End If End If Print Chr(13); ' back to beginning of line Loop Until T <> 0 ' exit if received a character Call Conv_key ' convert key to string Select Case Tstr Case "1" : Call Demo ' example of display management Case "2" : Call Ins_car ' display an ASCII char Case "3" : Call Decimal_point ' decimal point activation Case "4" : Call Leds ' LEDs management Case "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 C1 = 32 ' put blank character on DY4/1 C2 = 32 ' put blank character on DY4/2 C3 = 32 ' put blank character on DY3/1 C4 = 32 ' put blank character on DY3/2 C5 = 32 ' put blank character on DY2/1 C6 = 32 ' put blank character on DY2/2 C7 = 32 ' put blank character on DY1/1 C8 = 32 ' put blank character on DY1/2 Call Press ' "Press a key.." message Call Att_key ' wait for a key Case Else : Print Chr(bel); ' key is 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 Disp = 0 ' point displays DY4/1 and DY2/1 Led1 = 0 ' turn off Led 1 Led2 = 0 ' turn off Led 2 Led3 = 0 ' turn off Led 3 Led4 = 0 ' turn off Led 4 C1 = 32 ' put blank character on DY4/1 C2 = 32 ' put blank character on DY4/2 C3 = 32 ' put blank character on DY3/1 C4 = 32 ' put blank character on DY3/2 C5 = 32 ' put blank character on DY2/1 C6 = 32 ' put blank character on DY2/2 C7 = 32 ' put blank character on DY1/1 C8 = 32 ' put blank character on DY1/2 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 ' ' *********************** Rotate left the 8 displays *************************** ' This procedure performs the sliding to the left of the content of the 8 ' displays, making possible to realize sliding strings from right to left. ' The characters shift one display to the left, the new character of the string ' is put in display C8 (DY1/2). ' Parameters: ' Input : nothing ' Output : nothing ' ***************************************************************************** ' Sub Ruota ' rotate left the 8 displays C1 = C2 ' clear character on DY4/1, and ' copy character from DY4/2. C2 = C3 ' clear character on DY4/2, and ' copy character from DY3/1. C3 = C4 ' clear character on DY3/1, and ' copy character from DY3/2. C4 = C5 ' clear character on DY3/2, and ' copy character from DY2/1. C5 = C6 ' clear character on DY2/1, and ' copy character from DY2/2. C6 = C7 ' clear character on DY2/2, and ' copy character from DY1/1. C7 = C8 ' clear character on DY1/1, and ' copy character from DY1/2. End Sub ' ' ************************************************************************** ' * This procedure prepares the bits to send to M5451 (IC1 on KAD 08) * ' * Each display is matched to a variable from C1 to C8, if the variable * ' * contains a number greater than 127 the decimal point of hte matched * ' * display is automatically turned on. * ' * * ' * Parameters: 3 inputs, 2 outputs * ' * Inputs: var. Disp byte (from 0 to 3), indicates which display will * ' * be managed * ' * 0 -> DY4/1 and DY2/1 * ' * 1 -> DY4/2 and DY2/2 * ' * 2 -> DY3/1 and DY1/1 * ' * 3 -> DY3/2 and DY1/2 * ' * var. cif_h byte ( from 0 to 127), digit for DY4 and DY3 * ' * var. cif_l byte ( from 0 to 127), digit for DY2 and DY1 * ' * * ' * Output : var. Bit32 Long * ' * Variable Bit32 ( 4 byte) is structured like this: * ' * Bit32+0 -> byte 0 0..7 indicates segment a,b,c,d,e,f,g,h on DY4 and DY3* ' * * ' * Bit32+1 -> byte 1 0..6 indicates segment j,k,l,m,n,p,dp on DY4 and DY3 * ' * byte 1.7 indicates segment a on DY2 and DY1 * ' * * ' * Bit32+2 -> byte 2 0..7 indicates segment b,c,d,e,f,g,h,j on DY2 and DY1* ' * * ' * Bit32+3 -> byte 3 0..5 indicates segment k,l,m,n,p,dp on DY2 and DY1 * ' * byte 3.6 if = 0 activates displays DY3/2 and DY1/2, LD1 * ' * byte 3.7 if = 0 activates displays DY3/1 and DY1/1, LD2 * ' * * ' * Bit 3 -> bit 0 if = 0 activates displays DY4/2 e DY2/2, LD3 * ' * bit 1 if = 0 activates displays DY4/1 e DY2/1, LD4 * ' * bit 2 if = 0 enables the 4 LEDs. LD1, LD2, LD3, LD4 * ' * * ' * A general puprpose variable called X8 is used. * ' * Variables X8, bit32 and bit3 must be declared in 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) * ' ************************************************************************** ' Sub Conv_bit (disp As Byte , Cif_h As Byte , Cif_l As Byte) ' converts 2 digits for 5451 IC1 Call Conv14(cif_h) ' converts a char in 14 segments X8 = Low(digit) ' fetch low byte mov {Bit32+0},{x8} ' byte 0 a,b,c,d,e,f,g,h ' for DY4 and DY3 X8 = High(digit) ' fetch high byte If Cif_h > 127 Then ' if char is greater than 127 X8 = X8 Or &B01000000 ' turn on decimal point End If mov {Bit32+1},{x8} ' byte 1 j,k,l,m,n,p,dp ' for DY4 and DY3 ' byte 1.7 = 0 Call Conv14(cif_l) ' converts a char in 14 segments X8 = Low(digit) ' fetch low byte If X8.0 = 1 Then ' if bit 0 is on mov {x8},{Bit32+1} ' fetch byte 1 X8 = X8 Or 128 ' turn on bit 7 mov {Bit32+1},{x8} ' store byte 1,if byte1.7=1 "a" End If Digit = Digit And &HFFFE ' clear bit0 clr c Rotate Digit , Right ' right shift one bit X8 = Low(digit) ' fetch low byte mov {Bit32+2},{x8} ' byte 2 b,c,d,e,f,g,h,j ' for DY2 and DY1 X8 = High(digit) ' fetch high byte If Cif_l > 127 Then ' if char is greater than 127 X8 = X8 Or &B00100000 ' turn on decimal point End If X8 = X8 Or &B11000000 ' keep turned off DY3 and DY1 mov {Bit32+3},{x8} ' byte 3 k,l,m,n,p,dp ' for DY2 and DY1 ' byte 3.6=1 DY1/2 and DY3/2 Off ' byte 3.7=1 DY1/1 and DY3/1 Off Bit3 = &B00000011 ' bit3.0=1 DY2/2 and DY4/2 Off ' bit3.1=1 DY2/1 and DY4/1 Off ' bit3.2=0 LED1, 2, 3, 4 Off Select Case Disp ' on selected match of displays Case 0 : Bit3.1 = 0 ' DY2/1 and DY4/1 On If Led4 = 1 Then ' if LED4 is enabled Bit3.2 = 1 ' turn on LED4 End If Case 1 : Bit3.0 = 0 ' DY2/2 and DY4/2 On If Led3 = 1 Then ' if LED3 is enabled Bit3.2 = 1 ' turn on LED3 End If Case 2 : Bit32 = Bit32 And &H7FFFFFFF ' DY1/1 and DY3/1 On If Led2 = 1 Then ' if LED2 is enabled Bit3.2 = 1 ' turn on LED2 End If Case Is => 3 : Bit32 = Bit32 And &HBFFFFFFF ' DY1/2 and DY3/2 On If Led1 = 1 Then ' if LED1 is enabled Bit3.2 = 1 ' turn on LED1 End If End Select 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 14 segments displays* ' * are updated, the next interrupt updates the other two ones until all * ' * 8 displays are updated in four passages lasting 5 ms each * ' ************************************************************************** ' T0_int: Stop Timer0 ' stop timer0 Load Timer0 , Ric ' reload starting value Start Timer0 ' restart timer0 Select Case Disp ' according to selected display Case 0 : Call Conv_bit(disp , C1 , C5) ' prepare bit for DY4/1 and DY2/1 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(disp , C2 , C6) ' prepare bit for DY4/2 and DY2/2 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(disp , C3 , C7) ' prepare bit for DY3/1 and DY1/1 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(disp , C4 , C8) ' prepare bit for DY3/2 and DY1/2 Disp = 0 ' point displays DY4/1 and DY2/1 End Select Call Send5451(bit32) ' send informations to M5451 IC1 Return ' ' ********* Converts a number from 0 to 127 in 14 segments code ******** ' * * ' * Parameters: 1 input, 1 output * ' * input : variable Digit type word (from 0 to 127) * ' * output: variable Digit type Word (conversion for 14 segments) * ' * * ' ********************************************************************** ' Sub Conv14(digit As Word) ' Converts a number from 0 to 127 ' in 14 segments code Digit = Digit And &H007F ' mask values greater than 127 Digit = Lookup(digit , Tab_16seg) ' read from table ASCII character ' matched to the number End Sub ' ' ************* Communicates to M5451 IC1 the outputs status *********** ' * Sends the content of variables Bit32 type Long, and Bit3. * ' * Variables Bit32 and Bit3 must be declared in internal RAM, * ' * otherwise assembler instructions cannot be executed. * * ' * * ' * Parameters: 2 inputs * ' * input : variable bit32 type Long and Bit3 type byte * ' * output : nothing * ' ********************************************************************** ' Sub Send5451 (bit32 As Long , Bit3 As Byte) ' Communicates to M5451 IC1 the ' outputs status, through the ' content of a 32+3 bit variable push acc ' save accumulator push psw ' save the register with carry Call Sinc5451 ' synchronize the sequence Psda = 1 ' start Call Sendclk ' start sequence mov acc,{Bit32+0} ' fetch byte 0 of 4 Call Testbit0 ' output bit 0 (bit1 pin18 5451) Call Sendclk ' sequence 1 Call T_send ' output bit 1 (bit2 pin17 5451) ' sequence 2 Call T_send ' output bit 2 (bit3 pin16 5451) ' sequence 3 Call T_send ' output bit 3 (bit4 pin15 5451) ' sequence 4 Call T_send ' output bit 4 (bit5 pin14 5451) ' sequence 5 Call T_send ' output bit 5 (bit6 pin13 5451) ' sequence 6 Call T_send ' output bit 6 (bit7 pin12 5451) ' sequence 7 Call T_send ' output bit 7 (bit8 pin11 5451) ' sequence 8 mov acc,{Bit32+1} ' fetch byte 1 of 4 Call Testbit0 ' output bit 0 (bit9 pin10 5451) Call Sendclk ' sequence 9 Call T_send ' output bit 1 (bit10 pin9 5451) ' sequence 10 Call T_send ' output bit 2 (bit11 pin8 5451) ' sequence 11 Call T_send ' output bit 3 (bit12 pin7 5451) ' sequence 12 Call T_send ' output bit 4 (bit13 pin6 5451) ' sequence 13 Call T_send ' output bit 5 (bit14 pin5 5451) ' sequence 14 Call T_send ' output bit 6 (bit15 pin4 5451) ' sequence 15 Call T_send ' output bit 7 (bit16 pin3 5451) ' sequence 16 mov acc,{Bit32+2} ' fetch byte 2 of 4 Call Testbit0 ' output bit 0 (bit17 pin2 5451) Call Sendclk ' sequence 17 Call T_send ' output bit 1 (bit18 pin40 5451) ' sequence 18 Call T_send ' output bit 2 (bit19 pin39 5451) ' sequence 19 Call T_send ' output bit 3 (bit20 pin38 5451) ' sequence 20 Call T_send ' output bit 4 (bit21 pin37 5451) ' sequence 21 Call T_send ' output bit 5 (bit22 pin36 5451) ' sequence 22 Call T_send ' output bit 6 (Bit32 pin35 5451) ' sequence 23 Call T_send ' output bit 7 (bit24 pin34 5451) ' sequence 24 mov acc,{Bit32+3} ' fetch byte 3 of 4 Call Testbit0 ' output bit 0 (bit25 pin33 5451) Call Sendclk ' sequence 25 Call T_send ' output bit 1 (bit26 pin32 5451) ' sequence 26 Call T_send ' output bit 2 (bit27 pin31 5451) ' sequence 27 Call T_send ' output bit 3 (bit28 pin30 5451) ' sequence 28 Call T_send ' output bit 4 (bit29 pin29 5451) ' sequence 29 Call T_send ' output bit 5 (bit30 pin28 5451) ' sequence 30 Call T_send ' output bit 6 (bit31 pin27 5451) ' sequence 31 Call T_send ' output bit 7 (bit32 pin26 5451) ' sequence 32 mov acc,{bit3} ' fetch byte 4 of 4 Call Testbit0 ' output bit 0 (bit33 pin25 5451) Call Sendclk ' sequence 33 Call T_send ' output bit 1 (bit34 pin24 5451) ' sequence 34 Call T_send ' output bit 2 (bit35 pin23 5451) ' sequence 35 Psda = 0 Call Sendclk ' sequence 36 Call Sendclk ' sequence 37 pop psw ' restore register with 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 ' save 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 ' NOTE: The variable X8 type byte is used ' ****************************************************************************** ' Sub Sinc5451 Psda = 0 ' set data signal to zero For X8 = 1 To 37 ' repeat 37 times Call Sendclk ' output CLK impulse Next X8 End Sub ' ' ************************** LEDs On / Off management ************************** ' This procedure allows to turn on and off the 4 LEDs on the KAD 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) Exit" Print Print "SELECT DESIDERED 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 End Select Loop Until Tstr = "5" ' exit if "5" is pressed End Sub ' ' ******************** Input and display an ASCII character ******************* ' * This procedure allowa to show an ASCII character on the display. * ' * Parameters: nothing * ' * Ingresso: nothing * ' * Uscita: nothing * ' ***************************************************************************** ' Sub Ins_car ' Input and display an ASCII char Print Print Do Input "Select one display (1...8) ? " , D Loop Until D < 9 ' exit if lower than 9 Print "Input an ASCII character : "; Do T = Inkey ' read a char from serial port Loop Until T <> 0 ' exit if received a char Print Chr(t) Select Case D Case 1 : C1 = T ' display character on DY4/1 Case 2 : C2 = T ' display character on DY4/2 Case 3 : C3 = T ' display character on DY3/1 Case 4 : C4 = T ' display character on DY3/2 Case 5 : C5 = T ' display character on DY2/1 Case 6 : C6 = T ' display character on DY2/2 Case 7 : C7 = T ' display character on DY1/1 Case 8 : C8 = T ' display character on DY1/2 End Select Call Press ' "Press a key..." message Call Att_key ' wait for a key 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 Decimal_point ' Insert decimal point Print Print " Decimal point management" Print " 0) Turn off all decimal points" Print " 1) Turn on decimal point on DY4/1" Print " 2) Turn on decimal point on DY4/2" Print " 3) Turn on decimal point on DY3/1" Print " 4) Turn on decimal point on DY3/2" Print " 5) Turn on decimal point on DY2/1" Print " 6) Turn on decimal point on DY2/2" Print " 7) Turn on decimal point on DY1/1" Print " 8) Turn on decimal point on DY1/2" Print " 9) Exit" Print Do Call Att_key ' wait for a key Call Conv_key ' convert key in string Select Case Tstr Case "0" : Dp1 = 0 ' turn off Dp, reset bit7 of C1 Dp2 = 0 ' turn off Dp, reset bit7 of C2 Dp3 = 0 ' turn off Dp, reset bit7 of C3 Dp4 = 0 ' turn off Dp, reset bit7 of C4 Dp5 = 0 ' turn off Dp, reset bit7 of C5 Dp6 = 0 ' turn off Dp, reset bit7 of C6 Dp7 = 0 ' turn off Dp, reset bit7 of C7 Dp8 = 0 ' turn off Dp, reset bit7 of C8 Case "1" : Dp1 = 1 ' turn on Dp 1 Case "2" : Dp2 = 1 ' turn on Dp 2 Case "3" : Dp3 = 1 ' turn on Dp 3 Case "4" : Dp4 = 1 ' turn on Dp 4 Case "5" : Dp5 = 1 ' turn on Dp 5 Case "6" : Dp6 = 1 ' turn on Dp 6 Case "7" : Dp7 = 1 ' turn on Dp 7 Case "8" : Dp8 = 1 ' turn on Dp 8 End Select Loop Until Tstr = "9" ' exit if "9" is pressed End Sub ' ' ***************** Display management demo ************************************ ' * This procedure shows the whole ASCII table sliding it from right to left * ' * character by character * ' * The non-printable characters are shown as a decimal point, also LEDs are * ' * turned on. * ' * Parameters: * ' * Input : nothing * ' * Output : nothing * ' ****************************************************************************** ' Sub Demo ' Display management demo Call Press ' "Press a key..." message Do For D = 32 To 127 C8 = D Led1 = 0 ' turn off Led 1 Led2 = 1 ' turn on Led 2 Led3 = 0 ' turn off Led 3 Led4 = 1 ' turn on Led 4 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 Waitms 100 ' delay T = Inkey ' read char from serial port If T <> 0 Then ' a character is present Exit For ' exit from cycle For Else Call Ruota ' left shift the 8 displays End If Next D Loop Until T <> 0 ' exit if a key was pressed 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 ' ' ****************************************************************************** ' Messaggio: Data " MENU " , 0 ' ' ************* Table for conversion from ASCII to 14 segments ***************** Tab_16seg: ' cod. 00 01 02 03 04 05 06 07 Data &H0000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% ' cod. 08 09 0A 0B 0C 0D 0E 0F Data &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% ' cod. 10 11 12 13 14 15 16 17 Data &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% ' cod. 18 19 1A 1B 1C 1D 1E 1F Data &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% , &H4000% ' cod. 20 SP 21 ! 22 " 23 # 24 $ 25 % 26 & 27 ' Data &H0000% , &H0880% , &H0082% , &H4000% , &H266D% , &H4000% , &H4000% , &H0040% ' cod. 28 ( 29 ) 2A * 2B + 2C , 2D - 2E . 2F / Data &H0039% , &H000F% , &H3FC0% , &H2A80% , &H1000% , &H2200% , &H4000% , &H1100% ' cod. 30 0 31 1 32 2 33 3 34 4 35 5 36 6 37 7 Data &H113F% , &H0006% , &H221B% , &H220F% , &H2226% , &H222D% , &H223D% , &H0027% ' cod. 38 8 39 9 3A : 3B ; 3C < 3D = 3E > 3F ? Data &H223F% , &H222F% , &H4000% , &H4000% , &H0500% , &H2208% , &H1040% , &H0A23% ' cod. 40 @ 41 A 42 B 43 C 44 D 45 E 46 F 47 G Data &H02BB% , &H2237% , &H0A8F% , &H0039% , &H088F% , &H2039% , &H2031% , &H023D% ' cod. 48 H 49 I 4A J 4B K 4C L 4D M 4E N 4F O Data &H2236% , &H0889% , &H001E% , &H2530% , &H0038% , &H00B7% , &H0476% , &H003F% ' cod. 50 P 51 Q 52 R 53 S 54 T 55 U 56 V 57 W Data &H2233% , &H043F% , &H2633% , &H222D% , &H0881% , &H003E% , &H1130% , &H083E% ' cod. 58 X 59 Y 5A Z 5B [ 5C \ 5D ] 5E ^ 5F - Data &H1540% , &H0940% , &H1109% , &H0039% , &H0440% , &H000F% , &H0102% , &H2200% ' cod. 60 ` 61 a 62 b 63 c 64 d 65 e 66 f 67 g Data &H0100% , &H2237% , &H223C% , &H2218% , &H221E% , &H2039% , &H2231% , &H023D% ' cod. 68 h 69 i 6A j 6B k 6C l 6D m 6E n 6F o Data &H2234% , &H0800% , &H001E% , &H2530% , &H0880% , &H2A14% , &H2A04% , &H221C% ' cod. 70 p 71 q 72 r 73 s 74 t 75 u 76 v 77 w Data &H2233% , &H2227% , &H0A00% , &H222D% , &H2038% , &H001C% , &H1010% , &H081C% ' cod. 78 x 79 y 7A z 7B { 7C | 7D } 7E ~ 7F Data &H1540% , &H1140% , &H1109% , &H4000% , &H0880% , &H4000% , &H4000% , &H4000% ' ****************************************************************************** '