2016-06-03 3 views
0

안녕하세요!easyPic v7 마이크로 컨트롤러와 초음파 센서 hc-sr04 인터페이스 방법

사람 카운터를 만들기 위해 PIC18F45K22 칩과 함께 microicroller easyPic v7과 초음파 센서를 연결하는 방법에 대한 아이디어가있는 사람이 있습니까?

// Lcd module connections 
sbit LCD_RS at LATB4_bit; 
sbit LCD_EN at LATB5_bit; 
sbit LCD_D4 at LATB0_bit; 
sbit LCD_D5 at LATB1_bit; 
sbit LCD_D6 at LATB2_bit; 
sbit LCD_D7 at LATB3_bit; 

sbit LCD_RS_Direction at TRISB4_bit; 
sbit LCD_EN_Direction at TRISB5_bit; 
sbit LCD_D4_Direction at TRISB0_bit; 
sbit LCD_D5_Direction at TRISB1_bit; 
sbit LCD_D6_Direction at TRISB2_bit; 
sbit LCD_D7_Direction at TRISB3_bit; 

void main() 
{ 
    int a; 
    Lcd_Init(); 
    Lcd_Cmd(_LCD_CLEAR); 
    Lcd_Cmd(_LCD_CURSOR_OFF); 

    Lcd_Out(1,5,"ITCE444"); 
    Lcd_Out(2,3,"Term Project"); 

    Delay_ms(3000); 
    Lcd_Cmd(_LCD_CLEAR); 

    TRISA.RA0 = 0; //RB0 as Input PIN (TRG) 
    TRISA.RA4 = 0; //RB4 as Input PIN (ECHO) 

    while(1) 
    { 
    if(PORTA.RA4==1 && PORTA.RA0==1) 
    { 
     a = a + 1; 
     Lcd_Cmd(_LCD_CLEAR); 
     Lcd_Out(1,1,"Person in: "); 
     Lcd_Out(1,12,a); 
     Lcd_Out(1,15,"Person"); 
    } 
    else 
    { 
     a = a - 1; 
     Lcd_Cmd(_LCD_CLEAR); 
     Lcd_Out(1,1,"Person out: "); 
     Lcd_Out(1,13,a); 
    } 
    Delay_ms(400); 
    } 
} 

감사와 관련하여 ..

+0

어떤 도움을주세요 .... –

답변

0

코드 :

내가 유용한 코드를 발견하고 내가 편집을 시도하지만 여전히 작동하지 않습니다 ... 여기

내 코드입니다 위에 게시 한 내용이 100 % 잘못되었습니다. Here is 코드가 어떻게 보이게되어 있습니다.

HC-SR04은 초음파 거리 센서입니다. 센서와 장애물 사이의 거리를 측정합니다. 거리 정보를 사용하여 카운터를 만들 수는 있지만 스킬 셋보다 조금 위의 것 같습니다.

그래서 세 가지 옵션이

  1. 센서까지의 거리 독서를 얻기 위해 그림 마이크로 컨트롤러를 사용하고 타이머 코드 를 많이 쓰는 알아보세요.

  2. Arduino로 전환하고 내장 라이브러리를 사용하여 거리를 가져옵니다.

  3. 하드웨어를 변경하십시오. 사람 카운터를 만들기 위해 초음파 센서 (또는 그 문제에 대해서는 마이크로 컨트롤러)가 필요하지 않습니다. 나는 당신이 간단하게 적외선 led 쌍을 사용하여 사람이 그들을 걸을 때 펄스를주는 간단한 회로를 만들 것을 제안합니다.

0

덕분에 당신이 씨 하산 나딤 회신, 나는 코드에 대한 업데이 트를 가지고 있고 그것을 구현하는 경우는 거의 작동합니다.

는 살펴보고 어떻게 생각하는지 말해 :

// LCD module connections 
sbit LCD_RS at LATB4_bit; 
sbit LCD_EN at LATB5_bit; 
sbit LCD_D4 at LATB0_bit; 
sbit LCD_D5 at LATB1_bit; 
sbit LCD_D6 at LATB2_bit; 
sbit LCD_D7 at LATB3_bit; 
sbit LCD_RS_Direction at TRISB4_bit; 
sbit LCD_EN_Direction at TRISB5_bit; 
sbit LCD_D4_Direction at TRISB0_bit; 
sbit LCD_D5_Direction at TRISB1_bit; 
sbit LCD_D6_Direction at TRISB2_bit; 
sbit LCD_D7_Direction at TRISB3_bit; 
// End LCD module connections 

// Ultrasonic module connection 
sbit Ultrasonic at RD0_bit; 
sbit Ultrasonic_Direction at TRISD0_bit; 
// End of Ultrasonic module connections 

#define Pole_Height 200 

void main() 
{ 
    unsigned long Tm; 
    unsigned char Tl, Th; 
    unsigned int h, Person_Height,dist; 

    char Txt[7]; 

    int cont =0 ; 

    ANSELB = 0; 
    ANSELD = 0; 

    Lcd_Init(); 
    Lcd_Cmd(_LCD_CURSOR_OFF); 
    Lcd_Out(2,3,"Term Project"); 
    Lcd_Out(1,5,"ITCE444"); 
    Delay_Ms(2000);T0CON = 0x00; 

    for(;;) 
    { 
     Ultrasonic_Direction = 0; 
     TMR0H = 0; 
     TMR0L = 0; 

     Ultrasonic = 0; 
     Delay_us(3); 
     Ultrasonic = 1; 
     Delay_us(10); 
     Ultrasonic = 0; 

     while(PORTD.RD5 == 0); 
     T0CON.TMR0ON = 1; 
     while(PORTD.RD5 == 1); 
     T0CON.TMR0ON = 0; 

     Tl = TMR0L; 
     Th = TMR0H; 
     Tm = Th*256 + Tl; 
     Tm = Tm/2; 
     Tm = 34 * Tm; 
     Tm = Tm/1000; 
     h = (unsigned int)Tm; 
     Person_Height= Pole_Height - h; 

     if (Person_Height > 168 && Person_Height < 196) 
     cont = cont + 1 ; 
     else if(Person_Height > 132 && Person_Height < 160 && cont>0) 
     cont = cont - 1 ; 

     IntToStr(cont, Txt); 

     Lcd_Cmd(_LCD_CLEAR); 
     Lcd_Out(1,1, "Person in"); 
     Lcd_Out(2,1, Txt); 
     Delay_Ms(1000); 
    } 
} 
관련 문제