' ********************************************************************** ' ** Program name: KAD08au1.BAS - Version : 1.2 - 06 February 2001 ** ' ** Compiler : BASCOM AVR (IDE V. 1.11.5.0, LIB V. 1.11.5.0) ** ' ** 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: Graziano GAIBA ** ' ********************************************************************** ' ' 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. ' ' ++++++********** 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 ad zitck clock ' frequence 5.5296MHz. '*********************** 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 N As Byte ' general purpose variable ' ' ************************************************************************ ' * Following variables are essntial for interrupt, they can be changed * ' * in any moment. * ' ************************************************************************ ' 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 Cifh As Byte ' digit on DY4 and DY3 Dim Cifl As Byte ' digit on DY2 and DY1 Dim Cifra As Byte ' General purpose ' ****************************************************************************** ' '************************** 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 Send5451 ' Communicates to M5451 the ' status of the outputs, through ' a 32+3 bits variable Declare Sub Ruota ' rotates left the displays Declare Function Conv14 (byval Cifra As Byte) As Word ' converts a number from 0 to 127 ' in 14 segments (see ASCII code) Declare Sub Conv_bit (byval Cifh As Byte , Byval Cifl 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 ' ' ******************** 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 Timer0 = Ric ' reload starting value Start Timer0 ' restart timer0 Select Case Disp ' according to selected display Case 0 : Call Conv_bit(c1 , C5) ' prepare bit for DY4/1 and DY2/1 Incr Disp ' switch to next display match Case 1 : Call Conv_bit(c2 , C6) ' prepare bit for DY4/2 and DY2/2 Incr Disp ' switch to next display match Case 2 : Call Conv_bit(c3 , C7) ' prepare bit for DY3/1 and DY1/1 Incr Disp ' switch to next display match Case Is => 3 : Call Conv_bit(c4 , C8) ' prepare bit for DY3/2 and DY1/2 Disp = 0 ' switch back to DY4/1 and DY2/1 End Select Call Send5451 ' send informations to M5451 IC1 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 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 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 ' ' *********************** 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 (byval Cifh As Byte , Byval Cifl As Byte) ' converts 2 digits for 5451 IC1 Local Tmp32 As Long Local Digit_0 As Word , Digit_1 As Word Bit32 = 0 Digit_0 = Conv14(cifh) ' converts a character in 14 segments ' low byte a,b,c,d,e,f,g,h for DY4 and DY3 ' high byte j,k,l,m,n,p,dp for DY4 and DY3 If Cifh > 127 Then ' is character > 127 ? ' turn on decimal point Digit_0 = Digit_0 Or &H4000 ' bit 14 = 1 End If Digit_1 = Conv14(cifl) ' converts a character in 14 segments ' byte 2 b,c,d,e,f,g,h,j for DY2 and DY1 ' 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 If Digit_1.0 = 1 Then ' if bit 0 ON Digit_0 = Digit_0 Or &H8000 ' set bit 15 to 1 End If Digit_1 = Digit_1 And &HFFFE ' clear bit 0 Shift Digit_1 , Right ' shift right onr bit If Cifl > 127 Then ' is character > 127 ? ' turn on decimal point Digit_1 = Digit_1 Or &H2000 ' bit 13 = 1 End If Digit_1 = Digit_1 Or &HC000 ' keep DY3 and DY1 OFF 'Assemble the 32 bits value of bit32 Bit32 = Digit_0 ' Low Word of bit 32 Tmp32 = Digit_1 ' High Word of bit 32 Shift Tmp32 , Left , 16 ' Shift word to more significant Bit32 = Bit32 + Tmp32 ' Merge the two word Bit3 = 3 ' 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 ' which display match? Case 0 : Bit3.1 = 0 ' DY2/1 and DY4/1 ON If Led4 = 1 Then ' if LED4 to be ON 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 to be ON 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 to be ON 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 to be ON Bit3.2 = 1 ' turn ON LED1 End If End Select End Sub ' ' ********* 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) * ' * * ' ********************************************************************** ' Function Conv14(byval Cifra As Byte) As Word ' Converts a number from 0 to 127 ' in 14 segments code Local Bit8 As Byte Bit8 = Cifra And &H7F ' mask values greater than 127 Conv14 = Lookup(bit8 , Tab_16seg) ' read from table ASCII character ' matched to the number End Function ' ' ************* 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 ' Communicates to M5451 IC1 the ' outputs status, through the ' content of a 32+3 bit variable. Local I As Byte Call Sinc5451 ' Synchronize the sequence Psda = 1 ' start Call Sendclk ' start the sequence For I = 1 To 32 Call Testbit0 ' send bits from 0 to 31 Call Sendclk ' sequences from 1 to 32 Shift Bit32 , Right ' pins from 2 to 40 of 5451 ' connected to segments and dp Next I Bit32 = Bit3 ' Save bit3 to send it For I = 1 To 3 Call Testbit0 ' send bits from 32 to 34 Call Sendclk ' sequences from 33 to 35 Shift Bit32 , Right ' pins from 23 to 25 of 5451 Next I Psda = 0 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 = Bit32.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 Sinc5451 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 ' ' ****************************************************************************** ' 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% ' ****************************************************************************** '