' -------------------------------------------------------------------------- ' dio51mon.bas, written for the Bascom8051 BASIC compiler. ' Monitor program for the Industrologic DIO51 Single Board Computer ' and other 8051 family microcontrollers with serial port hardware. ' ' Industrologic, Inc. www.industrologic.com '--------------------------------------------------------------------------- $large 'use long calls $regfile = "89c51rd.dat" 'specifies registers $baud = 9600 'baud rate $crystal = 22118400 'crystal frequency in HZ, 11059270 'crystal frequency in MHz Dim A As Byte Dim C As Byte Dim Cb As Bit Dim Cmd As String * 6 Dim Cmd5 As String * 5 Dim Cmd3 As String * 3 Dim Cmd2 As String * 2 While 1 = 1 'loop forever Print Print Print "Industrologic, Inc. DIO51 Monitor Program" 'print logon message Print Print "Function: Commands: Responses:" Print "Read Port P0 P1 P2 hh" Print "Write Port P0=hh P1=hh P2=hh" Print "Read Bit I0 I1 T0 T1 b" Print "Write Bit I0=b I1=b T0=b T1=b" Print "Read All/Test R Displays inputs" Print "Write All/Test W Cycles outputs" Print Print "hh=2 character hex value 00 to FF" Print "b=1 character bit value 0 or 1" Print "All commands followed by the Enter key" Print Do 'until just the Enter key is pressed Input "DIO51>" , Cmd 'get a command Cmd = Ucase(cmd) 'to make command parsinf easier Cmd3 = Left(cmd , 3) 'look at just left 3 characters Cmd5 = Left(cmd , 5) 'look at just left 5 characters If Cmd = "P0" And Len(cmd) = 2 Then 'if a read P0 command Printhex P0 'display it End If If Cmd = "P1" And Len(cmd) = 2 Then 'if a read P1 command Printhex P1 'display it End If If Cmd = "P2" And Len(cmd) = 2 Then 'if a read P2 command Printhex P2 'display it End If If Cmd = "I0" And Len(cmd) = 2 Then 'if a read INT0 command Print P3.2 'display it End If If Cmd = "I1" And Len(cmd) = 2 Then 'if a read INT1 command Print P3.3 'display it End If If Cmd = "T0" And Len(cmd) = 2 Then 'if a read T0 command Print P3.4 'display it End If If Cmd = "T1" And Len(cmd) = 2 Then 'if a read T1 command Print P3.5 'display it End If If Cmd3 = "P0=" And Len(cmd) = 5 Then 'if a set P0 command A = Hexval(mid(cmd , 4 , 2)) 'get value from next 2 characters P0 = A 'send value to port End If If Cmd3 = "P1=" And Len(cmd) = 5 Then 'if a set P1 command A = Hexval(mid(cmd , 4 , 2)) 'get value from next 2 characters P1 = A 'send value to port End If If Cmd3 = "P2=" And Len(cmd) = 5 Then 'if a set P2 command A = Hexval(mid(cmd , 4 , 2)) 'get value from next 2 characters P2 = A 'send value to port End If If Cmd5 = "INT0=" And Len(cmd) = 6 Then 'if a set INT0 command A = Val(mid(cmd , 4 , 1)) 'get value from next character If A = 1 Then Set P3.2 'send value to port If A = 0 Then Reset P3.2 'send value to port End If If Cmd5 = "INT1=" And Len(cmd) = 6 Then 'if a set INT1 command A = Val(mid(cmd , 4 , 1)) 'get value from next character If A = 1 Then Set P3.3 'send value to port If A = 0 Then Reset P3.3 'send value to port End If If Cmd3 = "T0=" And Len(cmd) = 4 Then 'if a set T0 command A = Val(mid(cmd , 4 , 1)) 'get value from next character If A = 1 Then Set P3.4 'send value to port If A = 0 Then Reset P3.4 'send value to port End If If Cmd3 = "T1=" And Len(cmd) = 4 Then 'if a set T1 command A = Val(mid(cmd , 4 , 1)) 'get value from next character If A = 1 Then Set P3.5 'send value to port If A = 0 Then Reset P3.5 'send value to port End If If Cmd = "R" And Len(cmd) = 1 Then 'if a read/test command A = 0 ' make sure A is cleared While A = 0 'while no key pressed Print "P0="; Printhex P0; Print ", P1="; Printhex P1; Print ", P2="; Printhex P2; Print ", INT0="; Print P3.2; Print ", INT1="; Print P3.3; Print ", T0="; Print P3.4; Print ", T1="; Print P3.5 Waitms 100 'delay in milliseconds A = Inkey() 'see if a key was pressed Wend End If If Cmd = "W" And Len(cmd) = 1 Then 'if a write/test command A = 0 'make sure A is cleared C = 1 'initial port/bit output value While A = 0 'while no key pressed Print "Output value="; Printhex C; Print " hex" P0 = C 'set port values P1 = C P2 = C Cb = C.0 'use lowest order bit of the value P3.2 = Cb 'use this value to set bits P3.3 = Cb P3.4 = Cb P3.5 = Cb Rotate C , Left , 1 Waitms 100 'delay in milliseconds A = Inkey() 'see if a key was pressed Wend P0 = 255 'return ports and bits to initial values P1 = 255 P2 = 255 Set P3.2 Set P3.3 Set P3.4 Set P3.5 End If Loop Until Len(cmd) = 0 'exit loop back to menu if Enter key only Wend End