PIC16F877超声波测距程序

利用PIC16F877里的CCP1加上超声波模块测试距离

/* using the CCP1 module and  

 * ultrasonic test distances 

 * writer:陈红远 

 * unit:  中国计量学院 

 * date:   2012/3/28       */ 

#include<pic.h> 

#include<stdio.h> 

#include"lcd1602.h" 

__CONFIG(0x3B31); 

 

#define uint  unsigned int 

#define uchar unsigned char 

 

#define delay_10us() asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop") 

 

const uchar number[]={'0','1','2','3','4','5','6','7','8','9','‐'};//显示采集数值数组 

const uchar table[]="The d:    cm"; 

bit flag; 

uint val;//get distence 

uchar ccpnum; 

void init_1602() 

 uchar num; 

  

void init() 

 uchar num; 

//the ports initiate 

 TRISB=0; 

 PORTB=0; 

 TRISC=0x04; 

 TRISD=0; 

 PORTD=0; 

 TRISE=0; 

 PORTE=0; 

 /*RE、RA5全为I/O 

  *RA3 IS Verf+ 

  *RA2 IS Verf‐ 

  *RA1/RA0 is AN */ 

 ADCON1=0x8d; //1000 1101 

//interruput initiate enable 

你可能喜欢

  • 中文资料
  • PIC单片机C语言编程实例
  • 单片机课程设计报告
  • 单片机串口通信程序
  • 无线模块
  • LCD12864

PIC16F877超声波测距程序相关文档

最新文档

返回顶部