'-------------------------------------------------------------- ' (c) 1997,1998 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 Inc Count P1 = 1 For A = 1 To 8 Rotate P1 , Left 'rotate bits left Next 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