$crystal = 1000000 $regfile = "m16def.dat" If Pin D.0 = 0 Then Waitms 10 If Pin D.0 = 1 Then Goto Down Else Up : If Pin D.0 = 1 Waitms 10 If Pin D.0 = 0 Goto Up Else Down P0 : X = 00000001 Up 0 : Port A = X Rotate X , Left , 1 Wait 1 Call Key If X1 = 1 Then Goto Up 0 Else Return End If If Pin D.1 = 0 Then Waitms 10 If Pin D.1 = 1 Then Goto Down Else Up : If Pin D.1 = 1 Waitms 10 If Pin D.1 = 0 Goto Up Else Down P1 : X = 10000000 Up 1 : Port A = X Rotate X , Right , 1 Wait 1 Call Key If X1 = 1 Then Goto Up 1 Else Return End If If Pin D.2 = 0 Then Waitms 10 If Pin D.2 = 1 Then Goto Down Else Up : If Pin D.2 = 1 Waitms 10 If Pin D.2 = 0 Goto Up Else Down P2 : X = 10101010 Up 2 : Port A = X Rotate X , Left , 1 Wait 1 Call Key If X1 = 3 Then Goto Up 2 Else Return End If X = 1 Do Call Key If X1 = 1 Then Call P0 Else If X1 = 2 Then Call P1 Else Call P2 End If Loop Key : If Pin D.0 = 0 Then X1 = 1 Else If Pin D.1 = 0 Then X1 = 2 Else If Pin D.2 = 0 Then X1 = 3 End If Return