红外线发射与接收源程序

红外线发射与接收源程序,做智能小车必备啊。。

none.gif

红外线发射与接收一例:
 
  1. include<p=16f877.inc>        
  2.  
  3. ;歌林电子制作实验室www.nbglin.com
  4. ;TEL:0574-88464538  email:nbglin@126.com
  5. ;------------------
  6. STATUS  equ     0X03
  7. PORTA   equ     0x05
  8. PORTB   equ     0x06
  9. W       equ     0x00
  10. F       equ     0x01
  11. Z       equ     0x02
  12. C       equ     0x00
  13. ;------------------
  14. n55ks   equ     0x0C            ;
  15. nchks   equ     0x0D            ;
  16. avgIR   equ     0x0E            ;
  17. nsamp   equ     0x0F            ;
  18. tdetect equ     0x10            ;
  19. ;------------------------------------
  20. org     0x000
  21. goto    start
  22. org     0x004
  23. start
  24.  
  25. movlw   b'00000001'
  26. tris    PORTA           ; RA0 红外输入
  27. movlw   b'00000000'
  28. tris    PORTB           ;RB0 红外输出
  29. ; 2us in goto at end of loop
  30. blip call doblip ; +6.248ms = 6.250ms total
  31. call seeblip ; 6.250ms total
  32. call seeblip ; 6.250ms total
  33. call seeblip ; 6.250ms total
  34. call seeblip ; 6.250ms total
  35. call seeblip ; 6.250ms total
  36. call seeblip ; 6.250ms total
  37. call seeblip ; 6.250ms total
  38. nop
  39. nop
  40. call doblip
  41. call seeblip
  42. call seeblip
  43. call seeblip
  44. call seeblip
  45. call seeblip
  46. call seeblip
  47. call seeblip
  48. goto blip ;
  49.  
  50. ;============ 产生 55.5kHz锯形波(346*18us=6.228ms)======
  51. doblip                        
  52. movlw   0xFF
  53. movwf   n55ks           
  54. osc     nop                  
  55. call    make55k      ;RB0 红外输出   
  56. decfsz  n55ks,F      
  57. goto    osc   
  58. ;--------------
  59. morblip                       ;6253us DELAY
  60. movlw   0x5B
  61. movwf   n55ks      
  62. oscmore call    make55k      ;RB0 红外输出   
  63. nop                  
  64. decfsz  n55ks,F      
  65. goto    oscmore  
  66. ;-------------   
  67. call delay8u
  68. nop
  69. nop
  70. nop
  71. nop
  72. nop
  73. bcf     PORTB,2 ; RB2 LED指示
  74. return                 
  75.  
  76. ;---------------------------
  77. make55k bsf     PORTB,0 ;RB0 红外输出
  78. call    delay8u      
  79. bcf     PORTB,0  
  80. return                  
  81. delay8u nop                 
  82. nop                    
  83. nop                 
  84. nop                  
  85. return   
  86.               
  87. ;========= 6.250ms ===================
  88. seeblip                        
  89. clrf    avgIR         
  90. movlw   0xF9
  91. movwf   nchks      
  92. chk     call    chkIR           ;//
  93. decfsz  nchks,F      
  94. goto    chk  
  95.          
  96. movf    avgIR,W        ;
  97. sublw   0X78           
  98. btfss   STATUS,C         
  99. goto    detectd                                       
  100. bcf     PORTB,0 ;RB0 红外输出 OFF
  101. goto    chkdone         
  102. detectd bsf     PORTB,0   
  103. nop                    
  104. chkdone                        
  105. call    delay8u      
  106. nop
  107. nop
  108. nop
  109. nop
  110. return   
  111.               
  112. ;========================
  113. chkIR                        
  114. clrf    nsamp   
  115. btfss   PORTA,0
  116. incf    nsamp,F      
  117. btfss   PORTA,0 ; RA0 红外输入
  118. incf    nsamp,F      
  119. btfss   PORTA,0  ; RA0 红外输入计数值存到nsamp
  120. incf    nsamp,F      
  121. btfss   PORTA,0
  122. incf    nsamp,F      
  123. btfss   PORTA,0
  124. incf    nsamp,F      
  125. btfss   PORTA,0 ;共六次  nsamp》5,avgIR增一
  126. incf    nsamp,F         
  127. nop                     
  128. movf    nsamp,W         
  129. sublw   0X04        
  130. btfss   STATUS,C      
  131. incf    avgIR,F      
  132. return
  133.                
  134. ;============================
  135. end
复制代码


 

文件到原文下载,原文出自:https://bbs.usoftchina.com/thread-208673-1-1.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值