PIC Vietnam

Go Back   PIC Vietnam > Robotics > Cảm biến

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Cảm biến Camera, siêu âm, hồng ngoại, gyro, la bàn...

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 08-03-2009, 03:32 PM   #1
danghh
Nhập môn đệ tử
 
Tham gia ngày: Feb 2009
Bài gửi: 1
:
Question Thu phát hồng ngoại bằng Remote control

Chào các bạn, mình hiện tại đang làm một hệ thống thu phát hồng ngoại trong đó bộ phát là 1 cái điều khiển từ xa (mua ở chợ trời), bộ thu là con thu hồng ngoại 3 chân, thường thì mấy hãng Sony, NEC, vv... người ta có sẵn code của remote control, nhưng cái này mua ở chợ (ghi là LG) nên mình không rõ là làm thế nào để có thể nhận biết được nút nào đang được bấm và mã của nó là gì, mong được các bạn giúp đỡ ^^

P/S: mình dùng PIC18F4550 thì tín hiệu của mạch thu hồng ngoại gắn thẳng vào USART có đúng không ^^
danghh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 09-03-2009, 05:06 AM   #2
vietanh
Đệ tử 1 túi
 
Tham gia ngày: Dec 2005
Bài gửi: 20
:
đây là đoan mã ma tui kiếm được trên diễn đàn của ccs của thằng người nhật nichika lasuko ADINOMOTO dùng thử coi, dịnh chế lại làm dk robot bằng tay chắc cũng ok
Code:
/******************************************************************/ 
/*               EM LA NGUOI NHAT CHUA VO   HAI CON   MUON YEU 3 CO VIET NAM                                             */ 
/*      Infrared Receiver for SONY 12-bit protocol (SIRC)         */ 
/*                                                                */ 
/*  Compiler:     CCS PCH 3.242                                   */ 
/*  Processor:    PIC18F452 @ 32MHz                               */ 
/*  IR Sensor:    TSOP1738                                        */ 
/*  Circuit:      Standard from TSOP1738 Datasheet, OUT to RB0    */                                          
/*                Requires LCD on port D, LED+resistor on RC2     */ 
/*                LED blinks when a command is recognised.        */ 
/*  Author:       Aurelian Nichita     nicksubzero@yahoo.com      */ 
/*  Based on:     http://www.xs4all.nl/~sbp/knowledge/ir/sirc.htm */ 
/*                                                                */ 
/******************************************************************/ 
 
#define CLKSPEED 32000000 
#include <18F452.h> 
#fuses H4,NOPROTECT,NOOSCSEN,BROWNOUT,BORV45,NOWDT,WDT128,PUT,NOSTVREN,NODEBUG,NOLVP,WRT,NOCPB,WRTB,WRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB 
#use delay(clock=CLKSPEED) 
#use fast_io(A) 
#use fast_io(B) 
#use fast_io(C) 
#use fast_io(D) 
#use fast_io(E) 
#ignore_warnings none 
 
#zero_ram 
 
/* TIMER0 configuration */ 
#define TIMER0_CONFIG   RTCC_INTERNAL | RTCC_DIV_1 
 
/* Interrupt rate:                     */ 
/* 4/32000000*65536*1 = 8.192 ms       */ 
/*                                     */ 
/*     Start: 3.0 ms (ignored)         */ 
/*     "1":   1.8 ms (14400)           */ 
/*     "0":   1.2 ms  (9600)           */ 
 
#define ONE_MIN  13400 
#define ONE_MAX  15400 
#define ZERO_MIN 8600 
#define ZERO_MAX 10600 
 
#include "lcd.c" 
 
 
/* irframes[0] (start) will be garbage, ignore it...  */ 
int16 irframes[13]; 
int8 ircount = 0; 
int1 irdone = FALSE; 
 
 
#int_ext 
void ext_isr() { 
  if (irdone) return; 
  irframes[ircount++] = get_timer0(); 
  if (ircount >= 13) 
    irdone = TRUE; 
  set_timer0(0); 
  enable_interrupts(INT_TIMER0); 
} 
 
 
#int_timer0 
void timer0_isr() { 
  disable_interrupts(INT_TIMER0); 
} 
 
 
#separate 
int1 decode_ir(int8 &addr, int8 &cmd) { 
  int8 i; 
  int8 mask; 
  int8 bits[13]; 
 
  addr = 0; 
  cmd = 0; 
 
  for (i=1; i<=12; i++) { 
    if ((ONE_MIN <= irframes[i]) && (irframes[i] <= ONE_MAX)) 
      bits[i] = 0x01; 
    else 
      if ((ZERO_MIN <= irframes[i]) && (irframes[i] <= ZERO_MAX)) 
        bits[i] = 0x00; 
      else        // Error 
        return FALSE; 
  } 
 
  mask = 0x01; 
  for (i=1; i<=7; i++) { 
    if (bits[i]) 
      cmd = cmd | mask; 
    mask <<= 1; 
  } 
 
  mask = 0x01; 
  for (i=8; i<=12; i++) { 
    if (bits[i]) 
      addr = addr | mask; 
    mask <<= 1; 
  } 
 
  return TRUE; 
} 
 
 
void start_ir() { 
  memset(irframes, 0x00, sizeof(irframes)); 
  ircount = 0; 
  irdone = FALSE; 
} 
 
 
void main() { 
  int8 addr, cmd; 
  int1 ok; 
 
  delay_ms(100); 
  setup_adc_ports(NO_ANALOGS); 
  setup_adc(ADC_OFF); 
  set_tris_a(0b11111111); 
  set_tris_b(0b11111111); 
  set_tris_c(0b11111011);  // PIN_C2 used for the LED 
  set_tris_d(0b00000000);  // LCD 
  set_tris_e(0b11111111); 
  setup_spi(FALSE);  
  setup_wdt(WDT_OFF); 
 
  lcd_init(); 
  output_bit(PIN_C2, 0); 
  delay_ms(100); 
 
  lcd_putc("\fWaiting..."); 
 
  setup_timer_0(TIMER0_CONFIG); 
  setup_timer_1(T1_DISABLED); 
  setup_timer_2(T2_DISABLED, 255, 1); 
  setup_timer_3(T3_DISABLED | T3_DIV_BY_1); 
  ext_int_edge(0, L_TO_H); 
  enable_interrupts(INT_EXT); 
  enable_interrupts(GLOBAL); 
 
  start_ir(); 
#ignore_warnings 203 
  while(TRUE) { 
#ignore_warnings NONE 
    if (irdone) { 
      ok = decode_ir(addr, cmd); 
      printf(lcd_putc, "\fCmd  %3u\nAddr %3u", cmd, addr); 
      if (!ok) 
        lcd_putc("  ERROR"); 
      else 
        output_bit(PIN_C2, 1); 
      delay_ms(50); 
      output_bit(PIN_C2, 0); 
      start_ir(); 
    } 
  } 
}

thay đổi nội dung bởi: namqn, 09-03-2009 lúc 05:57 AM. Lý do: định dạng code
vietanh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 13-05-2013, 12:37 PM   #3
loctip
Nhập môn đệ tử
 
Tham gia ngày: Aug 2011
Bài gửi: 2
:
Interrupt rate

/* Interrupt rate: */
/* 4/32000000*65536*1 = 8.192 ms */
/* */
/* Start: 3.0 ms (ignored) */
/* "1": 1.8 ms (14400) */
/* "0": 1.2 ms (9600) */



HƯỚNG DẪN MÌNH CÁCH TÍNH CÁI NÀY ĐI....
loctip vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 15-05-2013, 04:19 PM   #4
nhansam
Nhập môn đệ tử
 
Tham gia ngày: May 2013
Bài gửi: 1
:
Trích:
Nguyên văn bởi loctip View Post
/* Interrupt rate: */
/* 4/32000000*65536*1 = 8.192 ms */
/* */
/* Start: 3.0 ms (ignored) */
/* "1": 1.8 ms (14400) */
/* "0": 1.2 ms (9600) */



HƯỚNG DẪN MÌNH CÁCH TÍNH CÁI NÀY ĐI....

Cùng câu hỏi với bạn này ! Chì với bạn ơi ! Thanks







_________________________
Kiến thức về nhan sam nên biết !
nhansam vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 12:19 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam