久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: 數(shù)碼管超聲波 [打印本頁]

作者: Cindy20    時間: 2022-6-8 16:53
標題: 數(shù)碼管超聲波
#include <pic.h>
#include <stdio.h>
__CONFIG(0x3b32);               
#define trig        RB0
#define echo        RB1
void clrscn(void);                                                        // prototypes
void cursor(char pos);
void print(char *p);
void setup(void);
unsigned int get_srf04(void);
char s[21];                                                                                // buffer used to hold text to print
void main(void)
{
unsigned int range;
        setup();                                                                                // sets up the PIC16F877 I2C port
clrscn();                                                                        // clears the LCD03 disply
cursor(2);                                                                        // sets cursor to 1st row of LCD03
sprintf(s,"SRF04 Ranger Test");                // text, printed into our buffer
print(s);                                                                        // send it to the LCD03
while(1) {                                                                        // loop forever
range = get_srf04();                                        // get range from srf04 (round trip flight time in 0.8uS units)
cursor(24);                                                                // sets cursor to 2nd row of LCD03
sprintf(s,"Range = %dcm  ", range/72);        // convert to cm
print(s);                                                                // send it to the LCD03       
                cursor(44);                                                                // sets cursor to 3rd row of LCD03
                sprintf(s,"Range = %dinch  ", range/185);        // convert to inches
                print(s);                                                                // send it to the LCD03       
                TMR1H = 0;                                                                // 52mS delay - this is so that the SRF04 ranging is not too rapid
                TMR1L = 0;                                                                // and the previous pulse has faded away before we start the next one
                T1CON = 0x21;                                                        // 1:4 prescale and running
                TMR1IF = 0;
                while(!TMR1IF);                                                // wait for delay time
                TMR1ON = 0;                                                                // stop timer       
        }
}
unsigned int get_srf04(void)
{
        TMR1H = 0xff;                                                // prepare timer for 10uS pulse
        TMR1L = -14;
        T1CON = 0x21;                                                // 1:4 prescale and running
        TMR1IF = 0;       
        trig = 1;                                                        // start trigger pulse
        while(!TMR1IF);                                        // wait 10uS
        trig = 0;                                                        // end trigger pulse
        TMR1ON = 0;                                                        // stop timer
        TMR1H = 0;                                                        // prepare timer to measure echo pulse
        TMR1L = 0;
        T1CON = 0x20;                                                // 1:4 prescale but not running yet
        TMR1IF = 0;
        while(!echo && !TMR1IF);                // wait for echo pulse to start (go high)
        TMR1ON = 1;                                                        // start timer to measure pulse
        while(echo && !TMR1IF);                        // wait for echo pulse to stop (go low)
        TMR1ON = 0;                                                        // stop timer
        return (TMR1H<<8)+TMR1L;                // TMR1H:TMR1L contains flight time of the pulse in 0.8uS units
}
void clrscn(void)
{
        SEN = 1;                                                                // send start bit
        while(SEN);                                                        // and wait for it to clear
        SSPIF = 0;
        SSPBUF = 0xc6;                                                // LCD02 I2C address
        while(!SSPIF);                                                // wait for interrupt
        SSPIF = 0;                                                        // then clear it.
        SSPBUF = 0;                                                        // address of register to write to
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
        SSPBUF = 12;                                                // clear screen
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
        SSPBUF = 4;                                                        // cursor off
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
        PEN = 1;                                                                // send stop bit
        while(PEN);                                                        //
}
void cursor(char pos)
{
        SEN = 1;                                                                // send start bit
        while(SEN);                                                        // and wait for it to clear
        SSPIF = 0;
        SSPBUF = 0xc6;                                                // LCD02 I2C address
        while(!SSPIF);                                                // wait for interrupt
        SSPIF = 0;                                                        // then clear it.
        SSPBUF = 0;                                                        // address of register to write to
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
        SSPBUF = 2;                                                        // set cursor
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
        SSPBUF = pos;                                                //  
        while(!SSPIF);                                                //
        SSPIF = 0;                                                        //
                PEN = 1;                                                                // send stop bit
        while(PEN);                                                        //
}
        void print(char *p)
{
        SEN = 1;                                                                // send start bit
        while(SEN);                                                        // and wait for it to clear
        SSPIF = 0;
        SSPBUF = 0xc6;                                // LCD02 I2C address
        while(!SSPIF);                                // wait for interrupt
        SSPIF = 0;                                        // then clear it.
        SSPBUF = 0;                                        // address of register to write to
        while(!SSPIF);                                //
        SSPIF = 0;                                        //
        while(*p) {
                SSPBUF = *p++;                        // write the data
                while(!SSPIF);                        //
                SSPIF = 0;                                //
        }
        PEN = 1;                                        // send stop bit
        while(PEN);                                        //
}
void setup(void)
{
unsigned long x;
        TRISB = 0xfe;                                // RB0 (trig) is output
        PORTB = 0xfe;                                // and starts low
        TRISC = 0xff;
        PORTC = 0xff;
        SSPSTAT = 0x80;
        SSPCON = 0x38;
        SSPCON2 = 0x00;
        SSPADD = 50;                                // SCL = 91khz with 20Mhz Osc
        for(x=0; x<300000L; x++);                // wait for LCD03 to initialise               
}

5717-數(shù)碼管超聲波--普通--OK.7z

13.09 MB, 下載次數(shù): 11, 下載積分: 黑幣 -5


作者: tplin    時間: 2022-11-30 10:07
是全套文件嗎?





歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 久久91av| 狠狠色综合久久丁香婷婷 | 第四色播日韩第一页 | 国产精品成人一区二区三区 | 国产高清在线 | 亚洲精品一二三区 | 欧美 日韩 国产 成人 在线 91 | 精久久久| 91人人澡人人爽 | 一级黄色日本片 | 亚洲午夜视频在线观看 | 亚洲一区二区三区视频 | 亚洲欧美在线视频 | 天天色官网 | 免费a国产 | 日韩中文一区二区三区 | 男人天堂网址 | 日批免费观看 | 天天干狠狠干 | 久久久av | 欧美性一区二区三区 | 欧美视频一区二区三区 | 日韩在线不卡 | 看毛片网站 | 日韩精品一区二区三区在线观看 | 国内精品视频在线 | 国产在线看片 | 久久久久久久久久久久91 | 99热视| 欧美日韩在线一区二区 | 欧美亚洲国产一区 | 成人av免费| 日韩三级在线 | 在线看av网址 | 欧美日韩福利视频 | av中文在线 | 久久久久久亚洲精品 | 一本综合久久 | 亚洲综合婷婷 | 在线欧美 | 精品久久国产 |