˛ˇ › images › editorupload › ultrasonic distance m… · 5 . / ˇ 2b...

60
1 ! "#$ %& ’ () * " (+ , ("- , ./ 01

Upload: others

Post on 07-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

1

��

������������ ����������� ���������������������

��

���������� ����������!���"#�$�

��

�%�&�����'

� �()����*"� �(�+� ,����

���("-��,��./��0��1 �

�������������

Page 2: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

2

�������� ���������������������������������������������������������������������������������������������������������������������������� �

������������ �� �

������������������������������������������������������������������������������������������������������������������������������������������� ������������! �

���"���������� �������������������������������������������������������������������������������������������������������������������������������������������������# �

���$���%&�'(������������������������������������������������������������������������������������������ ���������������������������������������������������)� �

��*��+$,�-�(�����.��.��/���.��� �����������������������������������������������������������������������������������������������������������0 �

�����1�2*���*��+$,����������������������������������������������� ���������������������������������������������������������������������������������0 �

�.����3.���*�+$,��������������������������������������������������������������������������������������� ���������������������������������������������45 �

����6���*�+$,������� ���������������������������������������������������������������������������������������������������������������������������������45 �

���7���8�&��9�� ���$������������������������������������������������������������������������������������������������������� �����������������������44 �

��*��$������������������������������������������������������������������������������������������������������������������������� ����������������������������44 �

��������������������������� �

�:��6�.���;�'�<������������������������ �����������������������������������������������������������������������������������������������������������������4!� �

����/�� ���$���:��6�������������������������������������������������������������������������������������������� ����������������������������������=4 �

��6��>����?@��+���&�"(����A��������� �����������������������������������������������������������������������������������������������������== �

�:�������B����������������������������������������������������������������������������������������� ����������������������������������������������������=C �

@��+���:�������B��������������������������� �����������������������������������������������������������������������������������������������������������=!� �

D�� �&�.�3�@�����E6�:��:������������������ �������������������������������������������������������������������������������������������������=F �

���+������:��6��������� �����������������������������������������������������������������������������������������������������������������������=G �

��<�����;�������������������������������������������������������������������������������������������������������������� ������������������������������������=0�������������������H"6����������������������������������������������������������������������������������� ����������������������������������������������������������������C4��

�I��>�&.�J�9�����<��.�������K�L������������������������������������������������������������������������������������������������������� CC��

��M ��.�E(���D������H/6������������ ���������������������������������������������������������������������������������������������������C!�� �

��6��E9N��������/�K�3������������������������������������������������������������� ������������������������������������������������������������C#� �

��6���7+*��������/�K�3���������� ���������������������������������������������������������������������������������������������������������������#=� �

## �������������������������������������������������������������������������� Pic 16f873 �E �'�3�Pic���*����/�K�3�����

Page 3: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

3

��� ����� � ��� ���� �� ���� �� �� � �

� ��� �� ������ !" #$% ��

���

������������������� ������������������������������� ������������������������������� ������������������������������� �������������

Page 4: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

4

&�'(���) �* �+ ,-� ������������ ��������������������������

����� ����� ��� ��� ����� ������ ���� ��� ������������ �� ��� ���! ��� �"� �#� $�"� %&�

�'�(��)����� *���$�%&�+�%,������-��&��� ���40�-��&�������#� #�%&�.��������/,������#�

��"������"����0�1%$����2,����/����3��4�����"�����$�%&���������������� ��5��,�

���$�%&���6$7���8��9������"�����$�%&� +������8��"�������:�&�����/���'��4�����"

�����$�%&��;��<&�-��&��������$�%&������=��9�+��

$�"�%&��>?&�/��%��&��4����@,�������������+��

Page 5: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

5

.��/� �

���A��%&�'�(��4��������"�%( �������� +��2�B��4�����"� ����������#�C����������#�%�&�

�������CD&��&����"��B��/��%�&�����=��9�� &�% ������� &��"������E�% F��C����"�����

���"�52���&�$�� 8�"����� 9#��G����&�H�����������#�%�&��C������%&���C��������������&�)

���$� %&� ���! ��� )����� *��� ����� �� � ���� �!I� )�� ��� .��� J��� ���&� ��� C��$� K�L&

� MN�9F&��#�%,���0�#���)��� ���40 �K�&��"�4����#�%&�� �� ����%&�����/,������#�

��&������"�:�&�� #�%&������������������X=VT/2�4�����E������������:�&����.�����

C�( ��%&������������������;��<&�)���"�.�H�C�������+��

�����;��<&������DI�%,���&�� ;*�����=��9���,�%&��� ��&� ����9���:������� ����(� ��

��6�&���"�O�;,������%&�'�(���,��P&�#������6�&���,��P&�#����&��"�)���� Q9������� ����

����������;��<&������������.�����:�&��R�38,��DI��

��"����:7�:��,�%&�����$�%&����������"���&�C����3����������$�"��&��G�&������&��Q� S

��"�C��T�*�7�4���+��

��"���&�C����3����������$�"��&��G�&�������&��������"������������:7�:��,�%&�����$�%&

��"�C��T�*�7�4�����"+��

#�U��������C��������� ��������&��������"C��#����! ���:��,�%&�� +�� �������&�������

����V�,��"�CW�����X��"�������� ����%&�CW���4�����"����%I�&����"��#��/�S� #�%&�������

���� �� *���� � &������� CD&� �&����� �� +�%&� ��� ������ �� *�� YL�� � ���R�38,�)��5��,

C�( �+��

Page 6: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

6

�0 12 3���456� ���� ���"����:7��� #�%&��������������%���9�$����%��/���4����@,��#�����%6�� 6*��������)��

��9�%&�U�;,�%6�� 6*��.� ���+��

����� ��<&�4�EZX��[�#��� -��������� �"�4�"��O�;,��� ��/"�� KB��� ����%&�%����� /�� ��%L

$�"+��

�����4�"��%����#�:�/�&��������������"���>\,������H������V�3 ��+��#�%,�EZX��]���"�� �"

���9����! ���:��,�%&�%!� 3&�������H�������������4�"��^��

_ �������

_ `��

_ ��

_ ��

_ J��*����#�H

_ �&�

_ ����

_ �+++

�L�9�� aC� #�%&� ���! ��� �����H���� ��S� �&�������H�$� ���$���� !�������� "�� ��� �#� �

���D �9#��� ���%&����B�:7���� ������ ���4�"���������&�4�EZX�����&�%���9�$����%6�/��

Page 7: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

7

#�%&�U�;,�%6�� 6*����D*� �����"�����G�+�4��b"�:��,�%&����%6�� 6*����D*� ��������/&

���#�� "�� �������^��

_ �������� H���J��������

_ :��7�.�2 �

_ N�"��B�

_ N�"��E��

_ ��+++� �

� ��� )����� *�� �9�#� �"� ��$Ultrasonic�$�"� ���#� �����"�� +��� F&� �"� )���*�� *�

���� 4��� c���&� +� ��"� :�� �&� ��� ���<&� ���� ��D��#��40���&� �� S� �,� /,�����#�

������G����/,���+�=( ��:�S�%�����"��#��#��D��#��������"�%H��&���d������:�/�&

�dV�A&� ���&� :��#� ��9�� d��9�"� )�� :��� ��8�� ���F,� d:/3&� )�� e9E� :�/�&� =( �

��G����% F ��4�FLB���,�dU����� 8�"�%W���#����"�f���(����DI��D�����������! ��

��#����$�����g���/�����D���������D��6$�R�38,��DI�%!�#+

������ �� ���� )�� -��&�� ���� ��� ���! ��� �DI����� :�� �&� �#� �$� %H��X� h�b3&�

��#�� "�C��2,�% F ����g���% F ��� �������"��������� ��+����% F ����g������� �

���H����%��D��#��ij ���k� ��������������D 9�B��"�����"������ 6�&���#�/,������#��+

���;�N�"���#��B������� �����������������)��R�38,�H����52��:�� �&�K��&�)��e9E���

��#����! ����D7����+� 6�&���#�/,�����&�H������D��#�������#�% F �������� ������&�

�$���C������ ����������B�� �&�N�"�0�#�����9��U�*���"� +�l��"� �( ������ �&���9���X��"

��*� #��6�&�5��,�������:�/�&�����������m�X�'������avrC��������+��

Page 8: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

8

������I��U"�B�% F ��������n����DQ�W���������� ��:�"����&���F �����+�� �����*��

proximity Switches�����F �����/��%F������"��#��#� ����+���&���F ������:�"

���� ��I�� U"�B� % F �� ������ n��� �DQ�W��� �� ����� �� +� � ��� ��*��Proximity

Switches��"��#��#� ����%F������

��#����$������&������"�:�� �&����H���DQ�W���]������������F �����/�+��

�Sonar Proximity Switches����

��)��.������"��#�4���������"� #�%&�U9E�4���c���&���D�*���k�����"������H�� ������

7�l��o���������0P����0*��:�$�%&� K�L&�YL�� ��� C�I�)����Ff������ +/&�]�� ������

#�%&���#�%"����"�&�I����K��&�)��:�������p�q#�% F ����DL�<&�����#��������������H�+

�dYL�� )�� ���F,� d������ )�� ����� ����� :�Q9�� %F���� �����"��#� ��� �� �&� �����H� ���

�������B����! ������&�]�!,���)���������������&�3f�)�����������+��

��

Photoelectric Proximity Switches����

�����H����� I�����G �������%$��������� 6�&���6$7�=�+������"�����;�&������H����

�$�l�����������%���*7���S��� 9#��#��$�[b���+��

��&�/��`��R�38,��#�����/�������H�]���������%����]�+��

( �� �"� :�� �&� ���H� ]�� ���������"��#� ������� ��),�4���� �"�J��9$�U9E� d]�!,���=

rJ��k�6F���s��#����$������ ������+��

Inductive Proximity Switches����

���#� n��� C��� )�� ��� %��2*�� :���I� ���@,� k���� �"� �#� �����H� ]�� ���� �

��R�38,�Uq&������� ��������"��#������� #�%&+�4�FLB�R�38,�d% F �������$���Ff

Page 9: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

9

��$�� �6$������ �"�V��������$�� �"�R�38,�d���� &���Uq&�% F ����$�&�)�������"

:����� �/��� �����<&� ���� �"� �E��� :�/�&� R�38,� �� �/��� +����� V��� ���� �b38&� ��

��#����$��K����t������N�"�n�W����<��d������9E�.�X��"�:�� �&������H�+�52���DQ�W������

#�%&���#��/���4�FLB������"+��

Proximity Switches�Capacitive^���

�����u� 4����@,� �� :���� )�� �B��� ��� ��"� e��E� 4����@,� k���� �"� �

���$�� ����:�������+��

�d)�&����d�8�$� �&� #�%&�U9E�K��&��������d&�I����CE�����&�]����������"������H����

�X��������G����&�C�I��"�:�8��9,�'E�U�*���"����g���V�S ����������9E�.+��

�U9E� �� ��� � �"� ��� K��&� ��I��.� #� dYL��.� #� �"�:�� �&� �����H����������"��#� ��9I� ��

��#����$��e��E�'��I��J��9$+��

��' ������& �7 �� �� �89:; <= > ?@A�-� ����#���Z��� ���)�����:��,�%&�����D,�"��������! ������&�������H�%�#�� "��� ���)�����^��

� �������� !�"�#Contact�$���

_ �$�"�%&�m�$������"������H����������"��#���� 9D&�^

_ C�I����k�9,��������6$7

_ �%&���(���:7�p� 3&���/I����"�4�"���#�H���H��#�%������ 8�������������������

��$+

Page 10: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

10

� �8� � �� �89:� � B ?@AC���������D������������� ��"��#� ��� 9D&� 4�"��� �"� )��/� ��$�� ������6$7$�"� %&� �����H�� +���� %!� 3&� ]���

���9����$����������&��"�:��,�%&���9I����������I�&�����"��������I�C��������H�^��

_ %��2*���

_ .����>�

_ %���

_ )����� *��

_ ���

� E�� �89:?@A�#��������DDDD

�$�"�%&�����m�$��"������H�����%������"��#�^��

_ �v �������r)����� *������/�*s��

_ � �"�%�r���"���CCDs�

$�"�%&������������� ;&��"������H�������#+��

Page 11: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

11

�8�� �:F ?@AC�&�G�HIJ&�K � �L6 MD� � ��� ���� ������H� �D,�"�� ����� ��� ���! ��� ���&� ������H� ���,��#��� ��� %6�� +����H

�����������%���������)������ ����r� ���� s������� ��/��,�)���r����� s�U�68,

$�����+��

�����"����B��!��YL��U"�2&��6�,����������H�����%I���5�U"�2&�����#�%,����������*��

$�"�%&��*���!����������B����,�YL��)��+����H�p� 3&���D*&������,�%&���Ff������� ;*�

$�"�06E�"�+�*�,�%,��! &��� *��p� 3&�����YL������"��DI��&�������H�����.�H�� �����%&�

#+��

�%&� �D7���$�� ����F*�L&� �"����������@ &�4��! &���D*&�����$������:�8���D,��2&�����2&

���7���"�����&��2&�� �D"���2&�:��,+��

8�N �O�P�Q R���HS TU 456� �����b,���L��� 9$�����D9 ����������! ������"���/�*�V������������ ���������%H��X

��#��������U�;&�,������E����"��I�,��"�����$�%&�����������K��&����������������:7���

��$�%&������� ����"�'�N���L���d��I�5���$��� Q9����K��&��"�������%;��+�'E�4������

��9�%&��������E���=��#��"�'�B��)�,�&�,����X��"�C ����d����L����"�� ����I�,+��

Page 12: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

12

�9�� �456 VWC�� �89��X 456Y�-�D� �����'�(D��U"�B�)���*��"�C ����%,���H�������"�O�;,��������F &���D����������+�U&�$��D ��

���%��&���K8F8,���%��&��������d�&��+�%&�'�(��.�9F&���X��"��&������������d�D �����"���

��$� +����%6�����������9���%6� ���#� �#�����)���*��/�������@ &� �&�4E��%�����%,��H��&Z

��$�%&�KB������! ������&��,��9�"�%6� ��#�R�38,�����#����+��

�����&������������C ����)��1/I����,�CD&�d��� ��+�d�&������������e�B����/"��)��KB�����

�� $�D��d�&��%6$/����D���������������I�&�U68&�d�������������%&�:�8������� ����&�

���� ������������������&�%6���*��/�����&������&��+�� $�D����#�����'�(���������,�:��7

��$�%&�����������=��&���#�������� �����"�C�2 �&�k�9,�����&����� ��+�����d.�H������"

������@,���������"�k�9,�������"���&�������69&��&����� ���#���S�����%��#�%��D ,���"�+

q&�%�&��$�"�� $�����$��������������"��"��;���� 9#���&��� "�������� ���Q� S�dMZ

"���%&�:���I��&����� ���"����"���� �&��� d�����%&����B����"�:7��"�C�2 �&�k�9,�����#� +����

)�*�"� &�����J����"��$���*�,�%��&��������������"�U�����"��$������%��&�����������

��������:7����"��"�C�2 �&�k�9,�����&����� ��:�������B�d���"�����&���:7���I� �� �d���"

���"�����9���&����� ��%��&����>?&�'�I�dU�*�������"���$�%&��W��B�5�g��&���(� ������ #�%&

$�"��������������&����"�%��&����>?&�'�I����� 9#�����"�+�d� $A����������&��2&��#�����CD&

$�"�C#�:�6&N��% H��������������&����"���%FB������ ����"�%��&��+��

Page 13: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

13

� ��� ,��;E��� ���! ��� ���&�%6$/��%� D&�e�B�������/"�� ����#� �&��.�9F&������8 �� ^w�+

��� ��&�,x�+��/���%9����&��2&���&�������� �y�+�.�b,��������9�Pn5����"�k��H����&�

� �&���� %&� ���@,� �&�� ��� :�8�6�/��� h���� �#� K��&� ���� .� ���#� �&� +�d����&� ���� ��"� ��

���� %6$/�� %� D&� ����� ����� ��� �&�� ��� �� ���,� .�9F&� �� ��&�,� +���� ��� �� ���

�����7����%E� &�%6�/���.�6$�������������"��#������ ����U�68,�������9���/��������#�

�$�%&�+�����%6S�#��"�%����LB��� ������#��#�)S�#�%����%�L�B������ ��&�,����.�6$�

mm1����]� ,� d����� &�% ��� S��LB��������#�%��/"�YL�&�����)�����,�� ����d�����+

��&��2&� �� ��9� %&� C����� ��� �� ��&�,� ���&� �"� %6�� 6*�� k�9,� d5"��� ���� C��� �� ����� 6*�

� ��&�,�%6�� 6*���$�%&��������������k�9,�����e��X������+�������9�����&�%6�� 6*���&��2&

"���%&�=��#��&��=��/����"+��

��q#�H��"��G����&�%��&�����<&�����&��2&�������@,��#���� �������X������� ��&�,����&

,���� �,� $�"�� $���%6�� 6*������������%�N�"�H�.�H�:�9���������"��>������&��2&�4����@

��$�������I� d���&� ����:$�� D#� �"� �������X��"� ��� dK"� &������ +�d%������� S��"�:���

�:�� #� �*�,�5��,� �#���� ��&�,�p� 3&� ���&�%FB���:���N�&��� ������� ��� ������ ����

��:��9��������DI��#�� ������� Q9���������%&����B����! ������&�p� 3&��D7�%6�� 6*��h��

�$�%&�� $�����������B���"���$�%&����! ���+���/"��)�����%*�q&�%6� ��#�%6��� 6*��v ��&�

������� ��&�,��"�% ;&��&������������e�B��+��$�U�68,�V����)�����e�B����/"��������� �

����� �� ��&�,� )�� �#� +�/"�� U#� )�9E� ��� %9D&� U&�E� dV���� ���� %H��X���� �� +��� V���� '�I

�4�B��,�$�"�C6<&���"�V�����6 �����E����d�"�%F����%�&��t�����,�$�"�C#���"��� ��&�,

$�"� � $��� ��� ��6&� ���! ��� U9<,� +�������� �#� ��S���������f�%� D&�[�#�,�)������"� "

���p*�3&�C�� �"� MN�9F&�� &���� +e�B����/"�� �Q� S� d� $A�����������6"�p� 3&����������"�

Page 14: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

14

� ��"� ��� ��� F"�V����:��9� �/���� ��� ��:��#� /�9,� d�������%�9E� ���! ��� +�=$���)��0�

��$�%&�z�E���9�"�������! ������"��#��$���%&����V������b&���;6�����/���� ���% u�!H�+

�$�"�� $���N�"�%��&����������C#�%��&���'�I���"�=$��������� Q9��t����:$�V��������,

��9�������I���/"��%�&��+���"�%&���"�������:7���6�9E��#�%� 3�����,�$�"�C6<&���"��� Q9�

�������B�V�������+��

�.� ����J������)��� 6*����&������ *���"��� ��&�,�%6�� 6*���&��2&�U�;,�e�B����/"��������

���������� ���&7� ��:7���&�� �"�5;,�&�%*� �(��� �<!��)�� MN�9F&� �#��W��B� ���������"� �� *�

$�"�%&� d���� �&�� � ���=��9� +��� ��&�,� ���:7�K�f�)�� �#�.��F &��:� �,���U�� ��&�)�

#�%&�e2<&� ���������� d���%&�U�68,� +�%L����g� d�����%H��X�[�� &���X��"�U�� �Q� S

F"�,�:�� E��"�:� �,���U��%I������ *��:��"������ ��&�,�:��"�%L����g���,�%&��&��2&����%

���F&�%��&�����<&�)����r��,��q#�H40�����% ����I����s�%I������ *���#����X�d #�:��;I

$�"�� $����&���"�%L���L"���U��+� #�%���k��2&����X����.� ����������"�%6��� 6*����&���2"

�"��#����Y�<���E���� ���%I�����#���:�8�����e"�L&��������������&���&��+��

�:�&���S����%&�:�8��#��������&�d����%6��� 6*����D( ��&��%{F"�����#�������%����#

��$�������&���,����������.��F,��"��&����� ��+� #�%&�%���"�����&�����>�������W&��� S

%&�����2&�%�;B���, S��"����%��D��W��B�� #��+����� 9#��D�Z ������0/1��&��d$�"������% ���

�MN�9F&���#�����d��3"�����&����,�%&��#���$�%&�� !����,������"�����$�%&�� �����G�����"�>

��$�%&�'�(����,�#�c�"�)���"+��

�������������:�S�d ���e�B����/"��]����9��k�����"�%�9���&��e�B�������/"�������%���

����%��&��%�������������'�(��U&�$�K8F8,���%��&�����$�d%��&��� +����X� ���.� �������

����W������� ��m�X�k�����"�����G����&���9#��#� #�%&�J�����+��

Page 15: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

15

�Z�' � �� �[�\] > _̂-�

w+ 2 �� �����������)����� *7���� ���E

x+ 1 %��7��E LM833

y+ 1 %��7��E LM358

i+ 1 ��E�%��7ijww�

|+ 1 �%��7��Eij}~�

}+ 1 %��7��E PIC 16F873

�+ 1 ���,N�����E��j|�

�+ 1 ���,N�����E��j~�

~+ 3 ��� ��/��,��ExSA1015

wj+ 3 ��� ��/��,��ExS1815

ww+ 3 ��E�SEGMENT �l� 8&�7

wx+ 1 �.� ���#��EiMHz

wy+ 2 :�����EsxxP

wi+ 7 ��&��2&��Eyyj�C���

w|+ 1 �� &������ ���Ew������#��C

w}+ 6 ��E�&��2& 5.6 �C������#

w�+ 6 �:�����Ej�w���������6�&�

w�+ 3 �:�����Ewjjj��������6���

w~+ 1 ��Ewjj���������6�&�

xj+ 2 �������EwSS106 ��

��' � ��� �����] ` aS 456-� �

Page 16: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

16

� �

� ��� 4���� �"� ��� �� ���pack $�;�&� ��I�&� �/(&�+�C�� )�� )�� 4���� �"� ��� �� ��� ���

$�;�&���I�&+�� �����#�0�#���������������! ������&��ij$�;�&�/,������#�+

-���� ����� �: � �:b acd e'f�-��&���*�,�%�o��������&������� (A/D) ��DI�:7������ QD����%��7�����.� �(����"�T�*�7

�:��#����������;��<&�segment �����$����! ���/��������=��9��DI���.

Page 17: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

17

��������Y �8g�h

��:�/�&��"�������.� �������2,��DI�%��7������}j�����$����! ���U;����+ �

Page 18: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

18

���������Y �8gh

�����%&����B����! ������&�)����� *7�-��&���������6$7��DI�%��7����+ .

�Y �8gh����-��

*7�-��&�%��7�����5��,�dc���%��7����5��,��$����2,�)����� hold �%&����D����

��$+���$�%&��*� #��6�&�������d+]���Z���������;$�%E���"���&��������%��7�������6�9Ed

D ���+� #�%&��GHZ&�U6$�����#���L�9��%��7����+�������di���� NAND ���.��

Page 19: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

19

��� i� �j �klmn� ��:�/�&��"��� *����;q,��DI�%��7����|��D7����"��� *�����H������#�%,�FLB����b&��DI��*��

�����%&����B����! ������&��$�p��F,.

�� i� �j ��klmo��� �

Page 20: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

20

�� *����;q,��DI�%��7�����:�/�&��"�~��D7����"��� *�����H������#�%,�FLB����b&��DI��*��

�����%&����B����! ������&��$�p��F,

��� p qrst �ulun� ����+����"�%���7�:��#��������DI�%���7�������ij~}���A@,��"�~���*�� npn��� ��/��,����

]�����

����� �������B����! ������&���&�������+ #�%&�����������*� #���6�&������ ��/��,����+ �

Page 21: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

21

�� p qrst �umun� �]������� ��/��,���� pnp ���+�:��#��������DI�� 8�"��d�segment�led ����B����! ������&

�����%&.��

�Y �8gh��� ���������%��7����}���"��E�%! &����+���� ��:��#��������DI�%��7�������&��������

�� *7�����%&����B����! ������&�� �����9�B����)���+

Page 22: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

22

�vZ�w�vZ�w�vZ�w�vZ�w��������:���I��AH��DI���&�����D��� dc %&����B����! ������&����@ &�:���I���;E������+��� Q9�d

���%&�'�(��/����&�������/����AH�U9E+���"��#�N�"���D��#������%6�&������D���

���+ ���)�&����]�����/����N�% *�&���D���d+������ 8�"���N���F,��#�4��!,������"+�����

%6�&����]�����:��"���N� S��X����"��� D"���6�9E�N�"���D��#������. �% �*�� 6*����D���

���%! &����;q&��DI���������������"��#���A@,�K"� &����/����AH��DI�� 8�"+�'�� ����d

� #��B���D7�%! &����;q&��DI��"���"������"��D7�.�b,�.

��

� #��I�,��D����]���"���&�������+��&�%6�&��������*�� 6*��d���N�% *�&�:����]������

����� �������B����! ��+� #�%&��GHZ&��82�����#���L�9�+����d

���R38&�:�8*������H��"��D���.c �d�%6�&����:���������9m �% *��&�:���������9

����N E ���*�� 6*��:���������9���.

�' � �� ���� �Z �G��& ��� �x] ` aS 456 � � �� ������! ���)����� *7���� ��������������"��,�� �����&���$�%&�+�4�����"��,�� �����&���

"���%&�=��/���%6�� 6*��.�2 ��:��,���������$�U���C���"�����&+��

Page 23: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

23

�%! &�.� �&�,����;q&�.� �&�,����� �����6"��� *�180����������Z ����I����+�C�2 �&�:���I�����

���%I������ *���V��"� ��� ��H� ��� �����"� �� #�%&� ����J�"�:���� �"�%&� ���! ��� �,��

��$+��

��

��

&�G� �� �xHI ���Cy�K �z � �� �xy�K �z � �� �xy�K �z � �� �xy�K �z � �� �x{'{'{'{'|||| }}}} ~�~�~�~� ����DDDD� �� �,� ��$� %&� ������� ����� ��� �� �"� �#� %6����� *7� .� ���1000�� #� ���2,� �� *�� �"��"�

��$�%&����2,���H�&����%X�%,���9E�+�.�����H�&���100��F"���H�&�������"��"�10�%&��"��"�

��$�+��;q&���A@,�K; &�%�#���L"��$�%&����"���6"�%,���9E�� #����2,����"�%! &���+��#����&

�:7��#���$�%&�� �����G����k���"��� *��:�� E��"���A@,�K; &�)���"� ���%&���6"�:�&��������4.5�

�����%&�����$����2,�V�� &�:���I�.� �����/#�&��� *������*�+

Page 24: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

24

��

��� �"� %,���9E� � #����2,� ��� ���! ��� :�&��%! &� ������ �� *�� �� �;q&� ������ �� *�� %! &� )"

�$�%&��"��"� M�;��2,� +��� *������ �"�����"� "�%&�V�� &�:���I�.� ����%! &����;q&��DI�k���"

�$����2,�����&�������"���,�+�-�I�E��[I�&���$�%9����! ���k���"��� *�������#�%�&�

��$�%&�V�� &�:���I�.� ����+#�% B�����"�J���������$�%&����2,�V�� &�:���I�.� �����

�������"��#���$�%&����! �����A@,�K; &�)����I��"���A@,�K; &�������� #����2,��#�%�&�+��

Z���� g�� �x� �� ���$� %&� '�(�� % ������ )����� *7� .� ���� :��#� ��6$7� ��G &� �"� ������6$7� +���&� ���

��������#�����-�&�C�������6������$����! ���%6,�$��+��

��� *�DC�7�%&���"�������8��:�����"�������6$7�.� ����YL���"�e"�L&�+��

��$�%&����! ��� #�%&���#�N�"���D��#�������#�%�o���������E��"�%6,�$�����+��

Page 25: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

25

��

y�K �Z����� g{'| �� ���6$7� ����������������&�1%$����% 8��"�.� �����#��������&���&���� #�%&�� +�%I���

�����$���6$7�� #�����2&�������! ����"������6$7���&�+�)���"�� #����2,���&�:�&��������

��A@,� K; & ��$� %&� ���! ��� � #� ����2&� ��I� �"+� �

���%&�=��9����%! &����;q&���������"�Uf�!,��� #�%&����2,�� #����2,�+����2,����&���

����#�%����� #����%&�]�;$���"�%I����C#��������� *��)���"����%! &�)"+��

������ #��� ��/�� �D���%,���9E������ #����2,�%�#���X��"� +��;q&��������#�%�&������"� "

#�%&����2,� �"��"� �D���Uf�!,� ��$�%&� � 8�"�%! &����������%9#� ��2&� +�%I������ Q9�

��$�%&���A@,�K; &� �&r�+�H��&�]�;$���*�s��

��� #�%&����2,��"��"��D���Uf�!,���$�%! &����������� 9#��;q&��������#�%�&��U"�2&���

��$�%&��*���!��%I���r�+��&�KLB��*�Hs��

Page 26: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

26

����2,��"�� #�����2&�%�������&��X����"��#��S��������� #�����2&���6�9E��"�8&�U9E����

����4��! &�%,���9E�� #�+��2&������6"�%,���9E�� #����2,�:�� E��"���,�%9�� #���+��

��#� #�%&�U���.� ���������6$7��"����%! &��������"������6$7���&�%I����:�&��������

#��"�>�����;q&���������$�%&��E�"+

��

��

��H�&������-��&���9�B������� hold �$�%&����D����+���&�����9�B�������6�9E�%E���"

�Z��������"���;$ (flip flop) ]� D ���.��

Page 27: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

27

��

��

� ��� � 8�"� �$� mZ��� )����� *7� .� ���� ��&� �#� %�&�0.4�.� ���� %I���� ��$� %&� �*��

���%&��!��M�;��2,�YL���"������6$7�+�U����;q&��������"�������#��������I��������J��

��$�%&�+$�%&���� ����:���"��"�0*����#�%�&�����%&���#��"�������������� ����.� �������+

#�%9���6$7����"�O��3&��#����� ����.� ����+����X���"�� �������:����.� �����#�% B�

����%&�N�"��$���� ���������6$7�.� �����;q&��������� *������%&��������� �+��

Page 28: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

28

�&������% H��$�.�����.� �����$�pB� &�.�����:���$�%&��E�"��������������9�B�"�.� ����

���9�B�"� .� ���� :8� ��6$7� ��� ��#� ���� �� ��$� C#� :���� �"� %*����� 0*��� .�/� :�&�� �#

#�%&�������I+��

���A��%&��>��4�/�D(,�����"��"��#��������� 6�:������2&�+����������:����������2&��#�% B�

����\,�������6$7�]��$�:�&��������������� �����,�#�������������,�%9�����$�%&���(��

#+��

���H�%*�����0*��1������������������,���$�%&���������>�%��&�10�:��������$��69&�� &�

#�%&�� 8�"�%9#� �������6$7� +���H�������������� ��,�#������40��#���$�%&�� 9� ���

�#�U������������������"���,TL����IC1�% ���"������6$7�.� ����:������2&�� #�C�#����

��$�C#+��

�������)����� *7��#�����&30���&������ 9� ���20 �%&�%X��������� ����I�����

� #1.758#�%&�.�X����>�%��&�+

��

��� �z �P����y�����Y ��Z�&Z��> � �-� �

Page 29: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

29

�� �v� �Z �G��& ��� �x�$�� ` � � �-� �

������&�������y��E��Segment �����$����! ���������=��9��DI+���&��������segment���

���l� 8&�7�]����.

�����segment ���������;q&�l� 8&�����������+���������:$�%! &��"��#d � �a,b,c,d,e,f,g

���%&�:�8�����������*� #��6�&�5��,.��

Page 30: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

30

��

��

�[����� �x��-� �

Page 31: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

31

��

��� �x�Q� ��-� �

Page 32: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

32

��

Page 33: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

33

� �

Page 34: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

34

� : �P ��� �) ����� �x���������� �� �� +��� �

� �

Page 35: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

35

� ���Y � �� � ������� �� �� � >� � �� �����4��! &�p� 3&�����&�����4����E��+��I����!����&�����4����E���.�q&���X��"

�����% ��yyw�|m/s ���+���&�����4����E����ij�����% ����I���y||�|m/s ���+��E��

3&�����&�����4�� #�%&���F;,������L"������p�.

�����:�&���"�%9�2 �&��L"����E��d�E���.�&����"��I�,��"+���&���������E���.�q&���X��"

�����% ����I����!�yyw�|m/s ���+��������,��&����������d2m $�"+�����8��"�V�� H���"

im ��$�%&+���� ���"�-�&��8��"�:�&��4&�����"� "��$�%&�V��H������L"����������. ��

��

�0 �89�� ���Y � �� � ������� ����� � � >� � �-� ���

Speed of sound (m/sec) Temperature (C)��

325.5��-10��

331.5 0

337.5 10

343.5 20

349.5 30

X=V*T

X=V*T, T=4/331.5, T=0.01206

Page 36: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

36

355.5 40

361.5 50

��

�: � ��: �Y ��.�Eb acd e'f �� ¡-�� �

������������������������������������������������������

������������������Ultrasonic Range Meter

����������������������������������Device : PIC16F873

����������������������������������Author : Seiichi Inoue

������������������������������������������������������

��������list p=pic16f873

��������include p16f873.inc

���������config _hs_osc & _wdt_off & _pwrte_on & _lvp_off

��������errorlevel -302 ;Suppress bank warning

�������������������Label Definition����������������������

��������cblock h'20�

s_count ;Send-out pulse count adr

s_adj ;Adjustment data address

Page 37: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

37

s_adj_count ;Rotate value save adr

s_digit ;Digit cont work address

g_time1 ;Guard timer address 1

g_time2 ;Guard timer address 2

p_countl ;Propagation L cnt adr

p_counth ;Propagation H cnt adr

digit_cnt ;Digit counter head adr

disp_ha ;Digit head address

disp_u ;1st digit address

disp_t ;10th digit address

disp_h ;100th digit address

seg7_ha ;7 segLED table head adr

seg70 ;Pattern 0 set adr

seg71 ;Pattern 1 set adr

seg72 ;Pattern 2 set adr

seg73 ;Pattern 3 set adr

seg74 ;Pattern 4 set adr

seg75 ;Pattern 5 set adr

seg76 ;Pattern 6 set adr

seg77 ;Pattern 7 set adr

seg78 ;Pattern 8 set adr

seg79 ;Pattern 9 set adr

seg7a ;Pattern A set adr

seg7b ;Pattern B set adr

��������endc

Page 38: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

38

ra1 equ h'01' ;RA1 port designation

ra2 equ h'02' ;RA2 port designation

ra3 equ h'03' ;RA3 port designation

ra5 equ h'05' ;RA5 port designation

ccp1 equ h'02' ;CCP1(RC2) designation

seg7_0 equ b'01000000' ;-gfedcba Pattern 0

seg7_1 equ b'01111001' ; Pattern 1

seg7_2 equ b'00100100' ; Pattern 2

seg7_3 equ b'00110000' ; Pattern 3

seg7_4 equ b'00011001' ; Pattern 4

seg7_5 equ b'00010010' ; Pattern 5

seg7_6 equ b'00000010' ; Pattern 6

seg7_7 equ b'01111000' ; Pattern 7

seg7_8 equ b'00000000' ; Pattern 8

seg7_9 equ b'00010000' ; Pattern 9

seg7_a equ b'01111111' ; Detect error

seg7_b equ b'00100011' ; Illegal int

�������������������Program Start�������������������������

��������org 0 ;Reset Vector

��������goto init

��������org 4 ;Interrupt Vector

��������goto int

Page 39: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

39

�������������������Initial Process�����������������������

init

�����Port initialization

��������bsf status,rp0 ;Change to Bank1

��������movlw b'00000001' ;AN0 to input mode

��������movwf trisa ;Set TRISA register

��������clrf trisb ;RB port to output mode

��������movlw b'00000100' ;RC2/CCP1 to input mode

��������movwf trisc ;Set TRISC register

�����Ultrasonic sending period initialization (Timer0s

��������movlw b'11010111' ;T0CS=0,PSA=0,PS=1:256

��������movwf option_reg ;Set OPTION_REG register

��������bcf status,rp0 ;Change to Bank0

��������clrf tmr0 ;Clear TMR0 register

�����Capture mode initialization (Timer1s

��������movlw b'00000001' ;Pre=1:1 TMR1=Int TMR1=ON

��������movwf t1con ;Set T1CON register

��������clrf ccp1con ;CCP1 off

�����A/D converter initialization

��������movlw b'01000001' ;ADCS=01 CHS=AN0 ADON=ON

Page 40: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

40

��������movwf adcon0 ;Set ADCON0 register

��������bsf status,rp0 ;Change to Bank1

��������movlw b'00001110' ;ADFM=0 PCFG=1110

��������movwf adcon1 ;Set ADCON1 register

��������bcf status,rp0 ;Change to Bank0

�����Display initialization (Timer2s

��������movlw disp_u ;Set digit head address

��������movwf disp_ha ;Save digit head sddress

��������movlw h'0a' ;"Detect error" data

��������movwf disp_u ;Set 1st digit

��������movwf disp_t ;Set 10th digit

��������movwf disp_h ;Set 100th digit

��������movlw d'3' ;Digit counter

��������movwf digit_cnt ;Set digit counter

��������movlw seg70 ;Set 7seg head address

��������movwf seg7_ha ;Save 7seg head address

��������movlw seg7_0 ;Set 7segment pattern 0

��������movwf seg70 ;Save pattern 0

��������movlw seg7_1 ;Set 7segment pattern 1

��������movwf seg71 ;Save pattern 1

��������movlw seg7_2 ;Set 7segment pattern 2

��������movwf seg72 ;Save pattern 2

��������movlw seg7_3 ;Set 7segment pattern 3

��������movwf seg73 ;Save pattern 3

��������movlw seg7_4 ;Set 7segment pattern 4

Page 41: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

41

��������movwf seg74 ;Save pattern 4

��������movlw seg7_5 ;Set 7segment pattern 5

��������movwf seg75 ;Save pattern 5

��������movlw seg7_6 ;Set 7segment pattern 6

��������movwf seg76 ;Save pattern 6

��������movlw seg7_7 ;Set 7segment pattern 7

��������movwf seg77 ;Save pattern 7

��������movlw seg7_8 ;Set 7segment pattern 8

��������movwf seg78 ;Save pattern 8

��������movlw seg7_9 ;Set 7segment pattern 9

��������movwf seg79 ;Save pattern 9

��������movlw seg7_a ;Set 7segment pattern A

��������movwf seg7a ;Save pattern A

��������movlw seg7_b ;Set 7segment pattern B

��������movwf seg7b ;Save pattern B

��������movlw b'00011110' ;OPS=1:4,T2=ON,EPS=1:16

��������movwf t2con ;Set T2CON register

��������bsf status,rp0 ;Change to Bank1

��������movlw d'157' ;157x64=10048usec

��������movwf pr2 ;Set PR2 register

��������bsf pie1,tmr2ie ;TMR2IE=ON

��������bcf status,rp0 ;Change to Bank0

�����Interruption control

��������movlw b'11100000' ;GIE=ON,PEIE=ON,T0IE=ON

Page 42: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

42

��������movwf intcon ;Set INTCON register

wait

��������goto $ ;Interruption wait

������������������Interruption Process�������������������

int

��������movfw pir1 ;Read PIR1 register

��������btfsc pir1,ccp1if ;Capture occurred��

��������goto capture ;Yes. "Capture�

��������btfsc pir1,tmr2if ;TMR2 time out��

��������goto led_cont ;Yes. "LED display�

��������movfw intcon ;Read INTCON register

��������btfsc intcon,t0if ;TMR0 time out��

��������goto send ;Yes. "Pulse send�

������������������Illegal interruption�������������������

illegal

��������movlw h'0b' ;Set Illegal disp digit

��������addwf seg7_ha,w ;Seg7 H.Adr + digit

��������movwf fsr ;Set FSR register

��������movfw indf ;Read seg7 data

��������movwf portb ;Write LED data

��������bcf porta,ra1 ;RA1=ON

��������bcf porta,ra2 ;RA2=ON

��������bcf porta,ra3 ;RA3=ON

Page 43: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

43

��������goto $ ;Stop

���������������END of Interruption Process���������������

int_end

��������retfie

������������������Pulse send-out Process�����������������

send

��������bcf intcon,t0if ;Clear TMR0 int flag

��������clrf tmr0 ;Timer0 clear

�����Received Pulse detection check

��������movfw portc ;Read PORTC register

��������btfsc portc,ccp1 ;Detected��

��������goto detect_off ;Yes. Detected

��������movlw h'0a' ;"Detect error" data

��������movwf disp_u ;Set 1st digit

��������movwf disp_t ;Set 10th digit

��������movwf disp_h ;Set 100th digit

�����Receive pulse detector off

detect_off

��������bcf porta,ra5 ;Set detector OFF

Page 44: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

44

�����Capture start

��������clrf tmr1h ;Clear TMR1H register

��������clrf tmr1l ;Clear TMR1L register

��������clrf ccpr1h ;Clear CCPR1H register

��������clrf ccpr1l ;Clear CCPR1L register

��������movlw b'00000101' ;CCP1M=0101(Captures

��������movwf ccp1con ;Set CCP1CON register

��������bsf status,rp0 ;Change to Bank1

��������bsf pie1,ccp1ie ;CCP1 interruptin enable

��������bcf status,rp0 ;Change to Bank0

��������bcf pir1,ccp1if ;Clear CCP1 int flag

�����ijKHz pulse send ( 0.5 msecs�

��������movlw d'20' ;Send-out pulse count

��������movwf s_count ;Set count

s_loop

��������call pulse ;Call pulse send sub

��������decfsz s_count,f ;End��

��������goto s_loop ;No. Continue

�����Get adjustment data

��������bsf adcon0,go ;Start A/D convert

ad_check

��������btfsc adcon0,go ;A/D convert end��

��������goto ad_check ;No. Again

Page 45: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

45

��������movfw adresh ;Read ADRESH register

��������movwf s_adj ;Save converted data

��������movlw d'5' ;Set rotate value

��������movwf s_adj_count ;Save rotate value

ad_rotate

��������rrf s_adj,f ;Rotate right 1 bit

��������decfsz s_adj_count,f ;End��

��������goto ad_rotate ;No. Continue

��������movfw s_adj ;Read rotated value

��������andlw b'00000111' ;Pick-up 3 bits

��������addlw d'54' ;(0 to 7) + 54 = 54 to 61

��������movwf s_adj ;Save adjustment data

�����Capture guard timer ( 1 milisecounds�

��������movlw d'2' ;Set loop counter1

��������movwf g_time1 ;Save loop counter1

g_loop1 movlw d'124' ;Set loop counter2

��������movwf g_time2 ;Save loop counter2

g_loop2 nop ;Time adjust

��������decfsz g_time2,f ;g_time2 - 1 = 0��

��������goto g_loop2 ;No. Continue

��������decfsz g_time1,f ;g_time1 - 1 = 0��

��������goto g_loop1 ;No. Continue

�����Receive pulse detector on

Page 46: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

46

��������bsf porta,ra5 ;Set detector ON

��������goto int_end

������������������Pulse send-out Process�����������������

pulse

��������movlw b'00010000' ;RC4=ON

��������movwf portc ;Set PORTC register

��������call t12us ;Call 12usec timer

��������clrf portc ;RC4=OFF

��������goto $+1

��������goto $+1

��������nop

��������return

������������������wx�microseconds timer������������������

t12us

��������goto $+1

��������goto $+1

��������goto $+1

��������goto $+1

��������nop

��������return

���������������������Capture Process���������������������

Page 47: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

47

capture

��������bcf pir1,ccp1if ;Clear CCP1 int flag

��������clrf p_countl ;Clear L count

��������clrf p_counth ;Clear H count

��������clrf ccp1con ;CCP1 off

division

��������movfw s_adj ;Read adjustment data

��������subwf ccpr1l,f ;Capture - adjust

��������btfsc status,z ;Result = 0��

��������goto division2 ;Yes. "R = 0�

��������btfsc status,c ;Result < 0��

��������goto division1 ;No. "R > 0�

��������goto division3 ;Yes."R < 0�

division1 ;( R > 0s�

��������movlw d'1' ;Set increment value

��������addwf p_countl,f ;Increment L count

��������btfss status,c ;Overflow��

��������goto division ;No. Continue

��������incf p_counth,f ;Increment H count

��������goto division ;Jump next

division2 ;( R = 0s�

��������movfw ccpr1h ;Read CCPR1H

Page 48: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

48

��������btfss status,z ;CCPR1H = 0��

��������goto division1 ;No. Next

��������movlw d'1' ;Set increment value

��������addwf p_countl,f ;Increment L count

��������btfss status,c ;Overflow��

��������goto digit_set ;Jump to digit set

��������incf p_counth,f ;Increment H count

��������goto digit_set ;Jump to digit set

division3 ;( R < 0s�

��������movfw ccpr1h ;Read CCPR1H

��������btfss status,z ;CCPR1H = 0��

��������goto division4 ;No. Borrow process

��������goto digit_set ;Jump to digit set

division4

��������decf ccpr1h,f ;CCPR1H - 1

��������movlw d'255' ;Borrow value

��������addwf ccpr1l,f ;CCPR1L + 255

��������incf ccpr1l,f ;CCPR1L + 1

��������goto division1 ;Next

�������������������Digit Set Process���������������������

digit_set

��������clrf disp_u ;Clear 1st digit

��������clrf disp_t ;Clear 10th digit

Page 49: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

49

��������clrf disp_h ;Clear 100th digit

�����wjjth digit

digit_h

��������movlw d'100' ;Divide value

��������subwf p_countl,f ;Digit - divide

��������btfsc status,z ;Result = 0��

��������goto digit_h2 ;Yes. "R = 0�

��������btfsc status,c ;Result < 0��

��������goto digit_h1 ;No. "R > 0�

��������goto digit_h3 ;Yes."R < 0�

digit_h1 ;( R > 0s�

��������incf disp_h,f ;Increment 100th count

��������goto digit_h ;Jump next

digit_h2 ;( R = 0s�

��������movfw p_counth ;Read H counter

��������btfss status,z ;H counter = 0��

��������goto digit_h1 ;No. Next

��������incf disp_h,f ;Increment 100th count

��������goto digit_t ;Jump to 10th digit pro

digit_h3 ;( R < 0�s

��������movfw p_counth ;Read H counter

Page 50: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

50

��������btfss status,z ;H counter = 0��

��������goto digit_h4 ;No. Borrow process

��������movlw d'100' ;Divide value

��������addwf p_countl,f ;Return over sub value

��������goto digit_t ;Jump to 10th digit pro

digit_h4

��������decf p_counth,f ;H counter - 1

��������movlw d'255' ;Borrow value

��������addwf p_countl,f ;L counter + 255

��������incf p_countl,f ;L counter + 1

��������goto digit_h1 ;Next

�����wjth digit

digit_t

�����Range over check

��������movfw disp_h ;Read 100th digit

��������sublw d'9' ;9 - (100th digits

��������btfsc status,z ;Result = 0��

��������goto digit_t0 ;Yes. "R = 0�

��������btfsc status,c ;Result < 0��

��������goto digit_t0 ;No. "R > 0�

��������movlw h'0a' ;"Detect error" data

��������movwf disp_u ;Set 1st digit

Page 51: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

51

��������movwf disp_t ;Set 10th digit

��������movwf disp_h ;Set 100th digit

��������goto int_end

digit_t0

��������movlw d'10' ;Divide value

��������subwf p_countl,f ;Digit - divide

��������btfsc status,z ;Result = 0��

��������goto digit_t1 ;Yes. "R = 0�

��������btfsc status,c ;Result < 0��

��������goto digit_t1 ;No. "R > 0�

��������goto digit_t2 ;Yes."R < 0�

digit_t1 ;( R >= 0s�

��������incf disp_t,f ;Increment 10th count

��������goto digit_t ;Jump next

digit_t2 ;( R < 0s�

��������movlw d'10' ;Divide value

��������addwf p_countl,f ;Return over sub value

��������goto digit_u ;Jump to 1st digit pro

�����wst digit

digit_u

��������movfw p_countl ;Read propagetion counter

Page 52: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

52

��������movwf disp_u ;Save 1st count

��������goto int_end

�������������������LED display control�������������������

led_cont

��������bcf pir1,tmr2if ;Clear TMR2 int flag

��������movfw digit_cnt ;Read digit counter

��������movwf s_digit ;Save digit counter

��������decfsz s_digit,f ;1st digit��

��������goto d_check1 ;No. Next

��������bsf porta,ra1 ;RA1=OFF

��������bsf porta,ra2 ;RA2=OFF

��������bcf porta,ra3 ;RA3=ON

��������goto c_digit ;Jump to digit cont

d_check1���

��������decfsz s_digit,f ;10th digit��

��������goto d_check2 ;No. 100th digit

��������bsf porta,ra1 ;RA1=OFF

��������bcf porta,ra2 ;RA2=ON

��������bsf porta,ra3 ;RA3=OFF

��������goto c_digit ;Jump to digit cont

d_check2

��������bcf porta,ra1 ;RA1=ON

��������bsf porta,ra2 ;RA2=OFF

Page 53: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

53

��������bsf porta,ra3 ;RA3=OFF

c_digit

��������decf digit_cnt,w ;Digit count - 1

��������addwf disp_ha,w ;Digit H.Adr + count

��������movwf fsr ;Set FSR register

��������movfw indf ;Read digit

��������addwf seg7_ha,w ;Seg7 H.Adr + digit

��������movwf fsr ;Set FSR register

��������movfw indf ;Read seg7 data

��������movwf portb ;Write LED data

��������decfsz digit_cnt,f ;Digit count - 1

��������goto int_end ;Jump to interrupt end

��������movlw d'3' ;Initial value

��������movwf digit_cnt ;Set initial value

��������goto int_end ;Jump to interrupt end

������������������������������������������������������

�������������END of Ultrasonic Range Meter

������������������������������������������������������

��������end

Page 54: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

54

�: � ��: �¢ �.�Eb acd e' ?£f-�� �

�������������D1

������������������������

�����������������D7308100831281010130CE

�������������������F0083160E309F0083128D

���������A30A9000A30AA00AB00AC000330A800A7

���������E30AD004030AE007930AF002430B0002B

������������B1001930B2001230B3000230B400B9

�����������B5000030B6001030B7007F30B800EF

������������B9001E30920083169D3092008C14FC

�����������E0308B0043280C080C1996288C183A

��������EF280B080B1956280B302D078400000899

����A0008600851005118511542809000B11810166

Page 55: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

55

����B000070807195F280A30AA00AB00AC008512B8

����C0008F018E01960195010530970083160C155E

����D00083120C111430A0008820A00B6C281F156F

����E0001F1970281E08A1000530A200A10CA20B48

����F000762821080739363EA1000230A4007C3062

�������A5000000A50B8128A40B7F288516552883

���������������������D288E28000008006D

�������������������������������C11A60119

�������A7019701210895020319A7280318A128F0

�������B0280130A607031C9A28A70A9A28160887

���������DA1280130A607031CB928A70AB92846

����������DB428B9289603FF309507950A91

�������A128AA01AB01AC016430A6020319C5286D

����������C328CA28AC0ABC282708031DC328A3

�������AC0AD5282708031DD0286430A607D52827

���A000A703FF30A607A60AC3282C08093C031999

���B000E0280318E0280A30AA00AB00AC0055285C

Page 56: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

56

���C0000A30A6020319E7280318E728E928AB0A32

���D000D5280A30A607EC282608AA0055288C1036

���E0002808A300A30BF8288514051585110129FB

���F000A30BFE2885140511851501298510051509

����������������������������D0784000008AD

��C0210008600A80B55280330A8005528D4

������E00723FFF

��������FF� �

�89: � �:b acd e'f����y�x�Y 1 ���¤ 3/�� ������ �

CPU %� ������&���RISC'(����)*

RISC�^REDUCE INSTRUCTION SYSTEM COMPUTER

w_����UB�H��"��D7���F,����������N�"�4��� ������I���E���]��������4��� ����������

�$�%&���I�����/����3����L"+

x_�4��� ������#����I��:�&�AUR �����%���������J���4��� ���/I��"�����U6�����$�&�)�

��&��"+

y_��,���!����"�lZ#���(&����<&20MHZ����+

Page 57: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

57

i_��G��H�����uFLASH$�"�%&����"���#��8��� +� ��H����% F�ijjj:��,�%&��&��"��L��

��$�+

|_���G��HFLASH ��e��X����% ���"PROGRAMMER ��&����$���E2PROM ����I��������

�$�"�%&�� $����:����U"�B��&��"+

}_�:�/�&RAM�:7�%����i�4�;>�)�"�wx�����% ��"+� ����G��H��$���%���������� ��I��+

&��e��X����C���k��7�e��X����C���$����A�&������� ��I� ���%�������U"�B�:�8+

�.�q&���^ ������������������portb,tmr0=mov portb,01�mov�

$�"�%&�� 9#�������'����"��;���G��H�����$�.�@$��C(H�����,��S��9����� ���'����+

�_���"���,�%&���A@,�K; &x��,�|�|��*��$�"+

�_������WDT�AD��������#������*��#�A/D�4��b"����U�;,�U9E���,�%&��������"�wj���"�

���'�(�+

~_��$��,18pin�4��b"DIP�

wj_�lZ#��������q#�H20MHZ$�;�&+

ww_%������G��H����� $����:������"���/�����"�BFLASH�

wx_����� $����:������"�:����&�������"�B��G��HE2PROM�wy_�����wy����������_

%I���r(I/O�q#�H�:����%����,��#xj����:���I�P&��%��&�+

wi_���������4�����"��� �&��#�% �"��8�����9$��9��,�)�������(watch dog)WD����! ��

��$+

w|_% �"��8��4�����"��&��"��G��H����"����#�)�������

���"�% �"��8�����9$����������)����$�]��$��!�����J��9$���(&����"�����%��D���2&

��8�&�� !��/������Z�������:���"��#���&�:�8����]�f�&������Z�+

Page 58: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

58

���"�Zq&timer 2s�+�0�#����"2Hz��9���(�����7�:��,�%&�+��"4�:�&��J��9$���"�2s �������"

��$�%&+

F=2Hz=> T=0.5s

�+!��,

PORTA^

w_������}���������+

x_����������x��,�wj��#�����T�*�7�����������y�4���������D7���,�e���}������������,�

�4���a��������B�+

y_����9$����������i�|�:�� E��"�Vref�KI�&��� *�����"�A/D����%&���6"�+

i_������}�������������������&�lZ#����������9$�&�����9��,��#�%�&��C� #�%&�.�9E�����+

|_���������$�%&����! ���.�����%I�������������"�+

PORTB�

w_�%������/�������&���"����"������������������'���,����4���������������������,���PIC�

�$�%&����! ���r�e��X����4��� ��PGD �e��X����lZ#��PGC�]��$���g7�'ZE�����"���

��"��&��"PIC���PGM��"��&��"�4��� ������#�:��#���������"�������������PIC�%&����! ���

�$+

x_����"�'�N��� *�PROGRAM�:��#�PIC���H�wy�% ���"�%&�'�� ����������#������*��

PGM��� *��wy $��"�� $����*��

y_�����RB0 �'���"�INT��! ���:���"�����!B��.�9E�����"��#�$�"�%&�/�����$�%&��+

�����!B��:$�.�F��4������ RB4 �, RB7��!B��[I�&��D7�����% �Ff�����@,����������

��$�%&�r+�p��F,����"���9���L"�:7���"��#(������#��<!�

Page 59: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

59

PORTC�

w_�4��������$�"�%&���"�+

x_��9��,���,�;����%I����w����������w|���$�%&����u��+��9��,����w��"����9$��������$

��$�%&�.�9E��������������lZ#+

y_��9��,���,Z���������w��*�H�����9��,�:��"�.�F������SLEEP������e��X����w}�%&�.�9E��

���$�+��*�H����lZ#�:�� E��"���,�%&�% F�SLEEP��$����! ���+

�����BOOT LOADER^

���I��"PROGRAM�U&�#�:��#PIC���%6S�#����&���"�� "������F"�����������6�&�����

���������&��"���2"�.�����4����e��XPICC� #�%&������+

������������^

w_�����w��:��6 ���*�H����.�����4����lZ#�rSCL����"IIC��SCK ���"SPIs

x_������xy������������SPI ,������%I������������IICrSDI ����"SPI ��SDA����"�IICs

y_�����xiI����:�&/9��.�����4���������%

i_���������x|��x}:��6 �7��*�H����"�

rCK �:��6 ��lZ#����"����������������������������

USRT�DT�:��6 ����������"���������������������

USRT�� �TRANSMIT :��6 �7�.��������"

��RECEIVE :��6 �7�����������"�������������s

�e��X������� PIC"�� SLAVE �����w~������'����"���D��� ���%��"�.�b,��WR � RD ���

�������#��$�%&�'�(�

���������:�� E��"�(CHIP ENABLE ) CE

Page 60: ˛ˇ › images › EditorUpload › Ultrasonic Distance M… · 5 . / ˇ 2b 4˛˚˙ˇ"˛ˇˆ˙ ˝ˇ#c ˛ ˇ#% & + a %&’ ( 4˛˚˙ ˇ"%( ˇˆ˙ ˝ ˜ cd& &" b / % & ˘ = 9 &% &ˇ"˛

60

��

����