⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comport.bas

📁 82 sample programs written in BASCOM-8051 for 8051 developement
💻 BAS
字号:
' --------------------------------------------------------------------------
'                comport.bas  (c) 1999-2002 MCS Electronics
'Special thanks to Eddie McMullen who supplied the basic inp/out routines
'---------------------------------------------------------------------------
$crystal = 18432000
Dim A As Byte , A1 As String * 1 , S As String * 16 , I As Byte , Dum As Byte
'Note that this example expects a MAX 232 level inverter for the serial communication

'A software comport is named after the pin you use
'For example, P3.0 will be "COM3.0:"  (so there is no P)
'For software comports, you must provide the baud rate
'So for 9600 baud, the device name is "COM3.0:9600"
'When you want to use the pin for sending, you must open the device for OUTPUT
'When you want to use the pin for receiving, you must open the device for INPUT

'At this time only variables can be send and received with the PUT and GET statements.
'In the feature PRINT etc. will support these software comports.
'New is support for PRINTBIN and INPUTBIN

'$timeout
'unmark the line abobove to get the timeout option

Open "com3.1:19200" For Output As #1      'p3.1 is normally used for tx so testing is easy
Open "com3.0:19200" For Input As #2       'p3.0 is normally used for RX so testing is easy


S = "test this"                           'assign string
Dum = Len(s)                              'get length of string
For I = 1 To Dum                          'for all characters from left to right
  A1 = Mid(s , I , 1)                                         'get character
  A = Asc(a1)
  Put #1 , A                              'write it to comport
Next

Do
  Get #2 , A                                                  'get character from comport
 ' Get #2 , A Timeout = 1000                                   'get character from comport
 'unmark the line above to get the timeout option
  Put #1 , A                              'write it back
  'Print A                                 'use normal channel
Loop

'now PRINTBIN & INPUTBIN are supported
Printbin #1 , A
Inputbin #2 , A


Close #1                                                      ' finally close device
Close #2
End

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -