' ********************************************************************** ' ** Program name: S1DEB1.BAS - Version : 1.1 - 01 June 1999 ** ' ** Compiler : BASCOM LT, (IDE V.1.20, LIB V.1.27) ** ' ** Board : GPC(r) 553 ** ' ** 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 shows the hexadecimal code of a key pressed on the PC's ' keyboard on the (red) LEDs of port 4. ' To achieve the visualization of the lines, you should connect the CN5 ' connector of GPC(r) 553 board to the CN15 connector of DEB(r) 01 board by ' a 20-pin flat cable. ' ATTENTION! To address correctly the 80552 I/O lines you shuold select the ' 80552 register file. To do this, select tab Misc from the Options/Compiler ' menu, click in the Register file text box then select the file 80552.DAT. ' '************************ Compiler Directives ******************************* ' $romstart = &H8050 ' start address of machine code $ramstart = &HD000 ' start address of data area $ramsize = &H2800 ' 10k of data area $crystal = 22118400 ' clock of microcontroller $baud = 19200 ' RS-232 baud rate $large ' 16 bit addressing mode ' ' '************************** Variable declarations **************************** ' Dim Char As Byte ' Stores key code Dim T As Byte ' General purpose variable Dim Vbyte As Byte ' Value returned by the procedure ' If 16 then the key is not an hex digit ' Else the value is the value of ' the digit itself ' '************************** Procedure declarations **************************** ' Declare Sub Chartest(t As Byte) ' Decides whether then input parameter is ' an hex digit or not ' '***************************** Main Program ********************************** ' Waitms 1 ' Delay for signals settling Poke &H20 , 0 P4 = &HFF ' Red LEDs OFF Print " Demonstration program 1 for section 1 of DEB(r) 01 board" Print : Print " Shows on port 4 the value of the hex digit typed on PC." Print : Print " Running..." Print Do Print "Please type the hex digit: " ;' Asks the digit Char = 0 While Char = 0 Char = Inkey ' Reads the serial line Wend ' until a key is typed Print Chr(char) Call Chartest (char ) If Vbyte = 16 Then Print "Only chars from 0 to 9, from A to F and from a to f allowed." Else Vbyte = Not Vbyte ' Negates the key to pilot the LEDs in ' negative logic P4 = Vbyte ' Outputs the negated key End If Loop End ' '*************************** End of Main program ***************************** ' ' '******************************* Procedures ********************************** ' ' This procedure detects whether its input parameter is an hex digit or not, ' that is whether it is a character between 0 and 9, a and f, A and F or not. ' Sets Vbyte to 16 if it is not. ' Input parameters: ' T Byte Contains the key to be examined ' Output parameters: ' Vbyte Byte Whether the key is an hex digiti it contains its value, ' else it contains 16 Sub Chartest(t As Byte) Vbyte = 16 If T < 48 Then ' It is below "0", then it surely is not Exit Sub ' an hex digit End If If T > 57 Then ' It is greater than "9", checks if it is letter If T < 65 Then ' It is below "A" Exit Sub ' Not an hex digit End If If T > 70 Then ' It is above "F", could be lowercase If T < 97 Then ' It is below "a" Exit Sub ' Not an hex digit End If If T > 102 Then ' It is above "f" Exit Sub ' Not an hex digit Else ' Key from "a" to "f",value from 97 to 102 Vbyte = T - 87 ' Reduced to a field from 10 to 15 End If Else ' Key from "A" to "F",value from 65 to 70 Vbyte = T - 55 ' Reduced to a field from 10 to 15 End If Else ' Numeric key Vbyte = T - 48 ' Reduced to a field from 0 to 9 End If End Sub