اطلاعیه

Collapse
No announcement yet.

راه اندازی ماژول SRF04 به وسیله LPC1768

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    راه اندازی ماژول SRF04 به وسیله LPC1768

    /************************************************** ***************************
    * hc-srf04.c: main C entry file for NXP LPC17xx Family Microprocessors
    *
    * Copyright(C) 2015, NXP Semiconductor
    * All rights reserved.
    *
    * meysam.amz@gmail.com
    *
    *
    ************************************************** ****************************/
    #include "lpc17xx.h"
    #include <stdio.h>

    #define LCD_LPC1768
    #define LCD_PORT_1
    #define LCD_RS 4
    #define LCD_RW 8
    #define LCD_E 9
    #define LCD_DB4 10
    #define LCD_DB5 14
    #define LCD_DB6 15
    #define LCD_DB7 16
    #include "lcd.h"

    #define CPU 72000000 // 72MHZ
    #define ECHO PORT0.1
    #define TRIG PORT0.0

    uint32_t S,dim;

    void Delay (uint32_t Time)
    {
    uint32_t i;

    i = 0;
    while (Time--) {
    for (i = 0; i < 5000; i++);
    }
    }


    volatile int T_Counter;
    float T= 0.0;
    float d= 0.0;
    char str[32];

    extern volatile uint32_t match_counter1;

    /************************************************** ****************************
    ** Main Function main()
    ************************************************** ****************************/
    int main (void)
    {

    SystemInit();;
    lcd_init();
    lcd_clear();
    lcd_gotoxy(1,1);
    lcd_putsf("HC-SRF04."
    //************************************************** ***
    // timer
    //************************************************** ***
    LPC_SC->PCONP |= 1<<22;
    LPC_TIM2->TCR = 0x02;
    LPC_TIM2->CTCR = 0;
    LPC_TIM2->MR0 = 10000000;
    LPC_TIM2->MCR = 2;
    LPC_TIM2->TC = 0x0;
    LPC_TIM2->PR = 0;
    //LPC_TIM2->TCR = 0x01;
    NVIC_EnableIRQ(TIMER2_IRQn);

    LPC_GPIO0->FIODIR = 1<<0;

    while ( 1 )
    {
    Delay(200);
    T_Counter = 0;
    LPC_GPIO0->FIOSET = 1<<0;
    Delay(10);
    LPC_GPIO0->FIOCLR = 1<<0;

    while(((LPC_GPIO0->FIOPIN>>1)&1) == 0);

    LPC_TIM2->TC = 0x0;
    LPC_TIM2->TCR = 0x01;

    while(((LPC_GPIO0->FIOPIN>>1)&1) == 1);
    S = LPC_TIM2->TC;
    LPC_TIM2->TCR = 0x02;
    T = 0;
    d = 0;

    T = (float)T_Counter*(100000.0/18000.0) + (float)S/18000.0;
    d = (float)T*340.0/2.0;

    lcd_gotoxy(1,1);
    sprintf(str,"T = %2.3f ms",T);
    lcd_putsf(str);
    lcd_gotoxy(2,1);
    sprintf(str,"d = %2.2f mm ",d);

    }
    }



    void __irq TIMER2_IRQHandler(void)
    {
    LPC_TIM2->IR = 0x02;
    T_Counter++;
    return;

    }

    /************************************************** ****************************
    ** End Of File
    ************************************************** ****************************/

    #2
    پاسخ : راه اندازی ماژول SRF04 به وسیله LPC1768

    سلام،
    نمونه مثال کامل و تست شده خودم با دقت خوب، تقدیم شما در لینک زیر

    http://**************/showthread.php?708-%D8%B1%D8%A7%D9%87-%D8%A7%D9%86%D8%AF%D8%A7%D8%B2%DB%8C-%D9%85%D8%A7%DA%98%D9%88%D9%84-%D9%81%D8%A7%D8%B5%D9%84%D9%87-%D8%B3%D9%86%D8%AC-%D8%A2%D9%84%D8%AA%D8%B1%D8%A7%D8%B3%D9%88%D9%86%D B%8C%DA%A9-sr-04&p=1237&posted=1#post1237

    دیدگاه


      #3
      پاسخ : راه اندازی ماژول SRF04 به وسیله LPC1768

      نوشته اصلی توسط meyssamam
      /************************************************** ***************************
      * hc-srf04.c: main C entry file for NXP LPC17xx Family Microprocessors
      *
      * Copyright(C) 2015, NXP Semiconductor
      * All rights reserved.
      *
      * meysam.amz@gmail.com
      *
      *
      ************************************************** ****************************/
      #include "lpc17xx.h"
      #include <stdio.h>

      #define LCD_LPC1768
      #define LCD_PORT_1
      #define LCD_RS 4
      #define LCD_RW 8
      #define LCD_E 9
      #define LCD_DB4 10
      #define LCD_DB5 14
      #define LCD_DB6 15
      #define LCD_DB7 16
      #include "lcd.h"

      #define CPU 72000000 // 72MHZ
      #define ECHO PORT0.1
      #define TRIG PORT0.0

      uint32_t S,dim;

      void Delay (uint32_t Time)
      {
      uint32_t i;

      i = 0;
      while (Time--) {
      for (i = 0; i < 5000; i++);
      }
      }


      volatile int T_Counter;
      float T= 0.0;
      float d= 0.0;
      char str[32];

      extern volatile uint32_t match_counter1;

      /************************************************** ****************************
      ** Main Function main()
      ************************************************** ****************************/
      int main (void)
      {

      SystemInit();;
      lcd_init();
      lcd_clear();
      lcd_gotoxy(1,1);
      lcd_putsf("HC-SRF04."
      //************************************************** ***
      // timer
      //************************************************** ***
      LPC_SC->PCONP |= 1<<22;
      LPC_TIM2->TCR = 0x02;
      LPC_TIM2->CTCR = 0;
      LPC_TIM2->MR0 = 10000000;
      LPC_TIM2->MCR = 2;
      LPC_TIM2->TC = 0x0;
      LPC_TIM2->PR = 0;
      //LPC_TIM2->TCR = 0x01;
      NVIC_EnableIRQ(TIMER2_IRQn);

      LPC_GPIO0->FIODIR = 1<<0;

      while ( 1 )
      {
      Delay(200);
      T_Counter = 0;
      LPC_GPIO0->FIOSET = 1<<0;
      Delay(10);
      LPC_GPIO0->FIOCLR = 1<<0;

      while(((LPC_GPIO0->FIOPIN>>1)&1) == 0);

      LPC_TIM2->TC = 0x0;
      LPC_TIM2->TCR = 0x01;

      while(((LPC_GPIO0->FIOPIN>>1)&1) == 1);
      S = LPC_TIM2->TC;
      LPC_TIM2->TCR = 0x02;
      T = 0;
      d = 0;

      T = (float)T_Counter*(100000.0/18000.0) + (float)S/18000.0;
      d = (float)T*340.0/2.0;

      lcd_gotoxy(1,1);
      sprintf(str,"T = %2.3f ms",T);
      lcd_putsf(str);
      lcd_gotoxy(2,1);
      sprintf(str,"d = %2.2f mm ",d);

      }
      }



      void __irq TIMER2_IRQHandler(void)
      {
      LPC_TIM2->IR = 0x02;
      T_Counter++;
      return;

      }

      /************************************************** ****************************
      ** End Of File
      ************************************************** ****************************/
      لطفا فایل پروژه تونو پلود کنید
      کتابخونه lcd اون چیه؟
      معیار واقعی بودن تصمیم، آن است که دست به عمل بزنیم.

      دیدگاه


        #4
        پاسخ : راه اندازی ماژول SRF04 به وسیله LPC1768

        :nerd:
        اینم فایل پروژه

        http://s6.picofile.com/file/8212751500/srf04.zip.html

        دیدگاه

        لطفا صبر کنید...
        X