Khi photointerrupter được kết nối với bộ điều khiển chính, vi điều khiển PIC ra khỏi ổ cắm 18-pin và bật sức mạnh. Từ từ xoay lốp xe bằng tay. LED sẽ được vào khi một phần mờ đục của đĩa mã hóa giữa các bộ ngắt quang học. Khi đi qua một lỗ trong đĩa, đèn LED sẽ được tắt. Chương trình tiếp theo sẽ kiểm tra kết nối của thiết bị để vi điều khiển PIC 16F84. | Chapter 7 Turtletron Build Your Own Robotic Turtle FIGURE Optical encoder disk centered between the interrupter. FIGURE Interrupter interface board mounted to robot base. 331 Amphibionics FIGURE Wiring diagram to connect interface board to main controller. When the photointerrupter is connected to the main controller take the PIC microcontroller out of the 18-pin socket and turn on the power. Slowly rotate the tire by hand. The LED will be on when an opaque section of the encoder disk is between the optical interrupter. When it comes across a hole in the disk the LED will be off. The next program will test the connection of the device to the PIC 16F84 microcontroller. Compile listed in Program and then program the PIC 16F84 with the file listed in Program . Place the PIC in the 18-pin socket and then turn on the power. When you rotate the tire and encoder disk by hand the PIC will produce a sound each time a hole is encountered. The program stays in a tight loop until the transistor changes state again otherwise the PIC would continuously produce the tone sequence while the disk was on the same hole. This method will be used when counting the number of times the transistor switches from one state to another or an event is being triggered. If a counter is being incremented this method ensures that only one count will occur during a state transition. 332 Chapter 7 Turtletron Build Your Own Robotic Turtle Name Compiler PicBasic Pro - MicroEngineering Labs Notes Program to test the optical interrupter photodarlington switch PROGRAM program listing PortA set as outputs. trisa 00000000 PortB set as outputs. pin 0 input. trisb 00000001 initialize variables switch VAR enable_right forward_right reverse_right enable_left reverse_left forward_left piezo control VAR VAR VAR VAR VAR VAR VAR VAR BYTE temp VAR BYTE low .