📄 port.bas
字号:
'--------------------------------------------------------------
' (c) 1997-2000 MCS Electronics
'--------------------------------------------------------------
' file: PORT.BAS
' demo: P1 and P3
'--------------------------------------------------------------
Dim A As Byte , Count As Byte
A = P1 'get inputvalue of port 1
Print A 'print it
P1 = 10 'set port1 to 10
P1 = P1 And 2
Set P1.0 'set bit 0 of port 1 to 1
Bitwait P1.0 , Set 'wait until bit is set(1)
'now lets test the simulator(see website for more details)
'connect P1 of the simulator to P1 of your target system
Count = 0
Do
Incr Count
P1 = 1
For A = 1 To 8
clr c 'clear carry
Rotate P1 , Left 'rotate bits left
Next
'the following 2 lines do the same as the previous loop
P1 = 1
Rotate P1 , Left , 2
Loop Until Count = 10
Print "Ready"
'note that the 8051 port pins are quasi bidirectional ports.
'when you want to use a pin as an input it must be set high first
'you can do this by writing ones to the port:
'p1 =&B00001111 'this will set p1.0,p1.1,p1.2 and p1.3 to use as inputs.
'of course be setting a pin high you can also drive a buffer with it.
'the AT89C2051 can provide 20mA which is enough to drive a LED!(in series with a resistor of course)
'In the example above the highest port pins can't be used as input because they are set low
'So : when you want to use a pin as an input set it high first!
'At start up all pins are set high by hardware
End
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -