PIC Vietnam

Go Back   PIC Vietnam > Mua bán & Trao đổi > Trao đổi ngoài luồng

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

Trao đổi ngoài luồng Các loại vi điều khiển khác, tản mạn của các anh chàng và cô nàng kỹ thuật ...

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 09-12-2010, 02:33 AM   #10
toan86
Nhập môn đệ tử
 
Tham gia ngày: Nov 2010
Bài gửi: 4
:
#include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)



/* TIMER0 configuration */
#define TIMER1_CONFIG T1_INTERNAL | T1_DIV_BY_1

/* Interrupt rate: */
/* 4/20000000*65536*1 = 13.1 ms */
/* */
/* Start: 3.0 ms (ignored) */
/* "1": 1.8 ms (9000) */
/* "0": 1.2 ms (6000) */

#define ONE_MIN 8000
#define ONE_MAX 10000
#define ZERO_MIN 5000
#define ZERO_MAX 7000

//#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() {output_bit(PIN_A5, 0);
if (irdone) return;
irframes[ircount++] = get_timer0();
if (ircount >= 13)
irdone = TRUE;
set_timer0(0);
enable_interrupts(INT_TIMER1);
}


#int_timer1
void timer_isr() {
disable_interrupts(INT_TIMER1);
}


#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(0x00);
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);

output_bit(PIN_A5, 1);
//lcd_init();
//output_bit(PIN_C2, 0);
delay_ms(100);

//lcd_putc("\fWaiting...");


setup_timer_1(TIMER1_CONFIG);
setup_timer_2(T2_DISABLED, 255, 1);
ext_int_edge(0, L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
delay_ms(100);
start_ir();
while(TRUE) {

if (irdone) {
ok = decode_ir(addr, cmd);
printf("%u", cmd);
printf("%u", addr);
if (!ok){
printf("1111");}
else
output_bit(PIN_A5, 0);
delay_ms(50);
output_bit(PIN_A5, 1);
start_ir();
}
}
}
cao thủ nào cho mình hỏi là code này thì port nào nhận tín hiệu vào và mình muốn xuất ra port thí phải so sánh với giá trị
Mã lệnh điều khiển TV SONY
Phím Mã lệnh
1 0H
2 1H
3 2H
4 3H
5 4H
6 5H
7 6H
8 7H
9 8H
10 9H
và xuất ra điều khiển relay
xin cảm ơn!
toan86 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


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

Similar Threads
Ðề tài Người gửi Chuyên mục Trả lời Bài mới
Moi bat dau hoc PIC va vi dieu khien thi hoc nhu the nao hut.edu.vn Cơ bản về vi điều khiển và PIC 21 27-11-2010 04:23 PM
Tim mua mach dieu khien Microstep cho Bipolar step Vo Hoang SOn Tìm mua sản phẩm 3 12-10-2008 11:03 PM
Bac nao kinh nghiem dieu khien toc do dong co khong dong bo ba pha xin giup dum hanhluckyly Cơ cấu chấp hành (Actuator) 5 15-08-2008 05:31 PM
dieu khien adc trong pic16f77a smile Cơ bản về vi điều khiển và PIC 2 15-01-2007 02:00 PM
Tim mua mach dieu khien DC/AC SERVO Driver Vo Hoang SOn Tìm mua sản phẩm 0 13-08-2005 11:40 AM


Múi giờ GMT. Hiện tại là 11:37 PM.


Đượ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