www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 單片機 > 單片機
[導讀]//////////////////////////////////////////////////////////////////////////////////// PIC16F877 + DYP-ME007 + LCD03 example// Written October 2008 , using HITECH PIC16 compiler//// Note - assumes a 20M

//////////////////////////////////////////////////////////////////////////////////// PIC16F877 + DYP-ME007 + LCD03 example// Written October 2008 , using HITECH PIC16 compiler//// Note - assumes a 20MHz crystal, which is 5MHz timer clock// A 1:4 prescaler is used to give a 1.25MHz timer count (0.8uS per tick)//// This code is Freeware - Use it for any purpose you like./////////////////////////////////////////////////////////////////////////////////#include #include __CONFIG(0x3b32);#define trig RB0#define echo RB1void clrscn(void); // prototypesvoid cursor(char pos);void print(char *p);void setup(void);unsigned int get_srf04(void);char s[21]; // buffer used to hold text to printvoid main(void){unsigned int range;setup(); // sets up the PIC16F877 I2C portclrscn(); // clears the LCD03 displycursor(2); // sets cursor to 1st row of LCD03sprintf(s,"SRF04 Ranger Test"); // text, printed into our bufferprint(s); // send it to the LCD03while(1) { // loop foreverrange = get_srf04(); // get range from srf04 (round trip flight time in 0.8uS units)cursor(24); // sets cursor to 2nd row of LCD03sprintf(s,"Range = ?m ", range/72); // convert to cmprint(s); // send it to the LCD03cursor(44); // sets cursor to 3rd row of LCD03sprintf(s,"Range = %dinch ", range/185); // convert to inchesprint(s); // send it to the LCD03TMR1H = 0; // 52mS delay - this is so that the SRF04 ranging is not too rapidTMR1L = 0; // and the previous pulse has faded away before we start the next oneT1CON = 0x21; // 1:4 prescale and runningTMR1IF = 0;while(!TMR1IF); // wait for delay timeTMR1ON = 0; // stop timer}}unsigned int get_srf04(void){TMR1H = 0xff; // prepare timer for 10uS pulseTMR1L = -14;T1CON = 0x21; // 1:4 prescale and runningTMR1IF = 0;trig = 1; // start trigger pulsewhile(!TMR1IF); // wait 10uStrig = 0; // end trigger pulseTMR1ON = 0; // stop timerTMR1H = 0; // prepare timer to measure echo pulseTMR1L = 0;T1CON = 0x20; // 1:4 prescale but not running yetTMR1IF = 0;while(!echo && !TMR1IF); // wait for echo pulse to start (go high)TMR1ON = 1; // start timer to measure pulsewhile(echo && !TMR1IF); // wait for echo pulse to stop (go low)TMR1ON = 0; // stop timerreturn (TMR1H<<8)+TMR1L; // TMR1H:TMR1L contains flight time of the pulse in 0.8uS units}void clrscn(void){SEN = 1; // send start bitwhile(SEN); // and wait for it to clearSSPIF = 0;SSPBUF = 0xc6; // LCD02 I2C addresswhile(!SSPIF); // wait for interruptSSPIF = 0; // then clear it.SSPBUF = 0; // address of register to write towhile(!SSPIF); //SSPIF = 0; //SSPBUF = 12; // clear screenwhile(!SSPIF); //SSPIF = 0; //SSPBUF = 4; // cursor offwhile(!SSPIF); //SSPIF = 0; //PEN = 1; // send stop bitwhile(PEN); //}void cursor(char pos){SEN = 1; // send start bitwhile(SEN); // and wait for it to clearSSPIF = 0;SSPBUF = 0xc6; // LCD02 I2C addresswhile(!SSPIF); // wait for interruptSSPIF = 0; // then clear it.SSPBUF = 0; // address of register to write towhile(!SSPIF); //SSPIF = 0; //SSPBUF = 2; // set cursorwhile(!SSPIF); //SSPIF = 0; //SSPBUF = pos; // while(!SSPIF); //SSPIF = 0; //PEN = 1; // send stop bitwhile(PEN); //}void print(char *p){SEN = 1; // send start bitwhile(SEN); // and wait for it to clearSSPIF = 0;SSPBUF = 0xc6; // LCD02 I2C addresswhile(!SSPIF); // wait for interruptSSPIF = 0; // then clear it.SSPBUF = 0; // address of register to write towhile(!SSPIF); //SSPIF = 0; //while(*p) {SSPBUF = *p++; // write the datawhile(!SSPIF); //SSPIF = 0; //}PEN = 1; // send stop bitwhile(PEN); //}void setup(void){unsigned long x;TRISB = 0xfe; // RB0 (trig) is outputPORTB = 0xfe; // and starts lowTRISC = 0xff;PORTC = 0xff;SSPSTAT = 0x80;SSPCON = 0x38;SSPCON2 = 0x00;SSPADD = 50; // SCL = 91khz with 20Mhz Oscfor(x=0; x<300000L; x++); // wait for LCD03 to initialise}

本站聲明: 本文章由作者或相關機構(gòu)授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關鍵字: 驅(qū)動電源

在工業(yè)自動化蓬勃發(fā)展的當下,工業(yè)電機作為核心動力設備,其驅(qū)動電源的性能直接關系到整個系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動勢抑制與過流保護是驅(qū)動電源設計中至關重要的兩個環(huán)節(jié),集成化方案的設計成為提升電機驅(qū)動性能的關鍵。

關鍵字: 工業(yè)電機 驅(qū)動電源

LED 驅(qū)動電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個照明設備的使用壽命。然而,在實際應用中,LED 驅(qū)動電源易損壞的問題卻十分常見,不僅增加了維護成本,還影響了用戶體驗。要解決這一問題,需從設計、生...

關鍵字: 驅(qū)動電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動電源的公式,電感內(nèi)電流波動大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關鍵字: LED 設計 驅(qū)動電源

電動汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動汽車的核心技術之一是電機驅(qū)動控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機驅(qū)動系統(tǒng)中的關鍵元件,其性能直接影響到電動汽車的動力性能和...

關鍵字: 電動汽車 新能源 驅(qū)動電源

在現(xiàn)代城市建設中,街道及停車場照明作為基礎設施的重要組成部分,其質(zhì)量和效率直接關系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進步,高亮度白光發(fā)光二極管(LED)因其獨特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關鍵字: 發(fā)光二極管 驅(qū)動電源 LED

LED通用照明設計工程師會遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關鍵字: LED 驅(qū)動電源 功率因數(shù)校正

在LED照明技術日益普及的今天,LED驅(qū)動電源的電磁干擾(EMI)問題成為了一個不可忽視的挑戰(zhàn)。電磁干擾不僅會影響LED燈具的正常工作,還可能對周圍電子設備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關鍵字: LED照明技術 電磁干擾 驅(qū)動電源

開關電源具有效率高的特性,而且開關電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機重量也有所下降,所以,現(xiàn)在的LED驅(qū)動電源

關鍵字: LED 驅(qū)動電源 開關電源

LED驅(qū)動電源是把電源供應轉(zhuǎn)換為特定的電壓電流以驅(qū)動LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關鍵字: LED 隧道燈 驅(qū)動電源
關閉