' ********************************************************************** ' ** Program name: KAD08_1.BAS - Version : 1.1 - 19 April 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 manages a sliding alphanumeric message on eight 14-segments ' displays, installed on KAD 08 board, through 2 TTL signals driveb by a ' microcontroller of family 51. ' The master board is K51-AVR which must be connected to KAD 08 as follows: ' K51-AVR KAD 08 ' L1 (pin4 CN6) ----> SC (pin2 CN1 KAD08) ' L2 (pin5 CN6) ----> SD (pin1 CN1 KAD08) ' Supply both the boards. ' ' Before compiling in menu Option/Compiler/Misc set Byte End(Hex) = 70. ' '*********************************************************************** ' '********************* Compiler Directives ***************************** ' $regfile = "REG51.DAT" ' list of CPU registers $romstart = &H0 ' code start address $crystal = 11059200 ' CPU clock frequence $baud = 19200 ' 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.3 ' line L1 of CN6 on K51-AVR that ' drives Clock signal. Psda Alias P3.4 ' line L2 of CN6 on K51-AVR that ' drives Data signal. 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 Lung As Byte ' stores length of a string Dim Tstr As String * 1 ' one-char generic use string Dim Stringa As String * 35 ' 35 chars 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 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 Stringa = " TEL.+39051892052 www.GriFo.com" ' initialize a string Call Iniz ' variables initializations etc. Lung = Len(stringa) ' calculte string length Do 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 ' visualize a RAM message For N = 1 To Lung ' repeat "Lung" times Tstr = Mid(stringa , N , 1) ' fetch a character from string C8 = Asc(tstr) ' get ASCII code of character Waitms 150 ' delay Call Ruota ' left shift of the 8 displays Next N 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 intperrupt updates the other two ones until all * ' * 8 displays are updated in four passages * ' ************************************************************************** ' 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 ' switch back to 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} ' prelevo il byte 3 di 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 ' ****************************************************************************** ' Sub Sinc5451 Psda = 0 ' set data signal to zero For X = 1 To 37 ' repeat 37 times Call Sendclk ' output CLK impulse Next X End Sub ' ' ****************************************************************************** ' Messaggio: Data " GriFo ITALIAN TECHNOLOGY" , 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% ' ****************************************************************************** '