Đ tài chỉ t o ra m chăđi u khi năc ăb n v i tính năđịnhăch aăcaoănênăh ng
92 phát tri nătrongăt ngălaiăc aăđ tài là:
- Tìm cách thu gọnăch ngătrìnhăn păđ viăđi u khi n sử ĺănhanhăh n,ăthayăth moduleăBluetoothăcóăđ năđịnh cao h năđ vi c truy n nh n d li u chính xác vƠănhanhăh n.
- Hoàn thi n mô hình, d n d n ti n t i vi c ng d ng l păđặt thi t bị lên xe v iăđ năđịnh cao.
- Trang bị thêm các thi t bị lọc nhi u cho viăđi u khi n cǜngănh ămoduleăđ đ m b o vi c thu, nh n và xử lý tín hi u là t iă uănh t.
- Thôngăquaăđ tài này có th tìm hi u và ng d ngălênăcácăc ăc u thi t bị khác trên ô tô nhằm thi t l p h th ng m ng không dây trên ô tô, có th sử d ng sóng Bluetooth hay các lo iăsóngăkhácănh ăWifi,ă3G.
93
TÀI LI U THAM KH O
[1].http://www.dts.com/corporate/management/fred-kitson.aspx [2].http://www.ci.dearborn-heights.mi.us/
[3].http://patent.ipexl.com/U2S/20050237166ZZDASHZZA1.html [4].http://www.freepatentsonline.com/y2004/0203370.html
[5].http://123doc.vn/document/63242-toyota-dao-tao-ky-thuat-vien-o-to-chuan- doan-dien-21-p3.htm.
[6].http://hoiquandientu.com/read.php?488.
[7].http://tbthinghiem.wordpress.com/2012/03/28/d%E1%BB%99ng-c%C6%A1- di%E1%BB%87n-m%E1%BB%99t-chi%E1%BB%81u/.
[8].http://doc.edu.vn/tai-lieu/luan-van-tim-hieu-ve-cong-nghe-bluetooth-va-viet- ung-dung-minh-hoa-5984/.
[9].http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ve d=0CCsQFjAA&url=http%3A%2F%2Finside.vaa.edu.vn%2Ftien-
ich%2Fdoc_view%2F316-
truyensong.raw%3Ftmpl%3Dcomponent&ei=W99HUpPnBsaOiAf18YGoCQ&usg
=AFQjCNFAIOdn8XrKvx4-rQRfyXz-
W7G4Pg&sig2=RU2DM4ccOf7z_gsvU_9U3w&bvm=bv.53217764,d.aGc
http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=
0CDoQFjAB&url=http%3A%2F%2Fdlib.ptit.edu.vn%2Fbitstream%2F123456789
%2F367%2F1%2FTruyen%2520song%2520va%2520anten.PDF&ei=jeBHUpe_M YLqiAeBRw&usg=AFQjCNEiI5Sd-
fgAvASb1S5ICVPBgb_UeQ&sig2=2fReLziLeA40EVw-7C4fdw [10].http://www.rasmicro.com/Bluetooth/EGBT-045MS-
046S%20Bluetooth%20Module%20Manual%20rev%201r0.pdf
http://www.usconverters.com/downloads/bluetooth-module-btm5-datasheet.pdf [11].https://www.sparkfun.com/datasheets/BreakoutBoards/0712.pdf.
[12].PGS.TSăĐ VĔNăDǛNG, Hệ thống điện thân xe và điều khiển tự động trên
94 ôtô, TP.HCM, 2007.
[13].Giáo trình kỹ thuật điện, tr ngăĐHăS ăPh m Kỹ Thu t Tp.HCM.
[14].Nguy năĐìnhăPh́, Vi xử lý 2, Đ i họcăS ăPh m Kỹ Thu t TP.HCM, 2007.
[15].Tr ngăVĕnăTám, Giáo trình linh kiện điện tử, Đ i học C năTh ,ă2003.
[16].PhD.ROBERT MORROW, Bluetooth operation and use, McGraw – Hill companies, 2002.
[17].Wireless Networking Technology, Steve Rackley.Elsevier,2007.
[18].Houda Labiod, Hossam Afifi, Costantino De San tis. WI-FITM, BLUETOOTHTM, ZIGBEETM AND WIMAXTM. Springer.2007.
95
PH L C
1. L pătrìnhăđi u khi năch ngătrìnhăph́tăMASTER (ECU).
Ch ngătrìnhănƠyăsẽđ c n p vào PIC nằm trong m chăđi u khi n chính công t c chính.
/*
- Khoi tao bluetooth - Ghep doi 2 module
- Khi co mot trong cac nut nhan(Up, Down, Lock) duoc nhan thi 1 byte du lieu se duoc truyen di.trong byte du lieu truyen di gom co
+ Bit 0: trang thai 1 la dieu khien cua di len, 0 la dung lai + Bit 1: trang thai 1 la dieu khien cua chay xuong, 0 la dung lai
+ Bit 2: Trang thai Lock, trang thai 1 cac nut nhan o slave mat tac dung + Bit 3: trang thai dieu khien
- Khi co loi ket tay say ra thi slave gui lai mot tin hieu de cho master hien thi.
Byte slave gui lai su dung Bit 0, trang thai 1 la co loi(co vat bi ket), 0 la da hoan thanh auto nang(ha).
*/
#include <16F877A.h>
#device *=16
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=7372800)
#use
rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define PIN_KEY PIN_B0 // dieu khien chan KEY cua bluetooth
96
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=7372800)
#use
rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define PIN_KEY PIN_B0 // dieu khien chan KEY cua bluetooth
#define Button_Up PIN_A0 // dieu khien cua kinh di len
#define Button_Down PIN_A1 // dieu khien cua kinh di xuong
#define Button_Auto PIN_A2 // tu dong dieu khien trong 1 lan nhan
#define Button_Lock PIN_A3 // dieu khien khoa cua, khong cho cac nut nhan o slave hoat dong.
#define IG PIN_A5
#define LED_Warning PIN_A4
#define power PIN_B5 unsigned char dem = 1;
#define LED_LockStatus PIN_E0 // the hien trang thai coi co khoa hay khong int8 bytesend=0; // Byte lenh gui cho slave
short BitTempButton=1;// bit nho trang thai gui lenh, khi =1 chua gui lenh, short BitTempAuto1=0,BitTempAuto2=1;// nho trang thai cua nut nhan auto, khi auto2 =1 la da co nhan nut auto.
short Bit_TempLock = 0;
char temp = 0;
short BitTempWarning = 1;// bit hien thi cho led bao ket, neu ket thi = 0;
const char ControlUp = 1,ControlDown= 2, Stop = 0;
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=7372800)
#use
rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define PIN_KEY PIN_B0 // dieu khien chan KEY cua bluetooth
#define Button_Up PIN_A0 // dieu khien cua kinh di len
#define Button_Down PIN_A1 // dieu khien cua kinh di xuong
#define Button_Auto PIN_A2 // tu dong dieu khien trong 1 lan nhan
#define Button_Lock PIN_A3 // dieu khien khoa cua, khong cho cac nut nhan o slave hoat dong.
#define IG PIN_A5
#define LED_Warning PIN_A4
97
#define power PIN_B5 unsigned char dem = 1;
#define LED_LockStatus PIN_E0 // the hien trang thai coi co khoa hay khong int8 bytesend=0; // Byte lenh gui cho slave
short BitTempButton=1;// bit nho trang thai gui lenh, khi =1 chua gui lenh, short BitTempAuto1=0,BitTempAuto2=1;// nho trang thai cua nut nhan auto, khi auto2 =1 la da co nhan nut auto.
short Bit_TempLock = 0;
char temp = 0;
short BitTempWarning = 1;// bit hien thi cho led bao ket, neu ket thi = 0;
const char ControlUp = 1,ControlDown= 2, Stop = 0;
//!// ham kiem tra xem nut nhan auto co nhan khong, neu nhan thi set bit nho BitTemp_Auto
Void FButtonAuto_Check(void) {
if(input(Button_Auto) ==0) // Neu nut nhan che do auto duoc nhan {
delay_ms(10);
BitTempAuto1 = 1;
} else {
if(BitTempAuto1==1) BitTempAuto2 = 1; // bat auto2 else BitTempAuto2 = 0;
} }
// ham gui 1 lenh dieu khien khi nut nhan duoc nhan void FSendCommand(unsigned char command) {
98
if(BitTempButton ==1) // chi cho gui 1 lan khi nhan nut {
bytesend = (bytesend&0b00000100)|command;// giu lai trang thai Lock va auto neu co
putc(bytesend);
BitTempButton=0;
} }
#INT_TIMER1
void ISR_TIMER1(void) {
set_timer1(7936); // sau 250ms thi ngat dem++;
}
#int_RDA
void RDA_isr(void) {
temp = getc();
if(temp== 0xAA) {
output_high(LED_Warning); // bat den bao ket.
BitTempWarning = 0;
} else {
output_low(LED_Warning); // tat den bao ket.
BitTempWarning = 1;
} }
void main() {
port_b_pullups(false);
set_tris_a(0b11001111);
set_tris_b(0b11111110);
set_tris_c(0b10111111);
99 set_tris_d(0xFF);
set_tris_e(0);
delay_ms(300);
//! output_low(power);
output_low(PIN_KEY);
output_low(LED_LockStatus);
output_low(LED_Warning); // tat LED bao ket setup_timer_0(T0_INTERNAL|T0_DIV_256);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
// khoi tao bluetooth delay_ms(1000);
printf("AT+INIT\r\n"); // gui lenh khoi tao module BlueTooth delay_ms(500);
printf("AT+CLASS=0\r\n"); //
delay_ms(500);
printf("AT+INQM=1,9,48\r\n");
delay_ms(500);
printf("AT+INQ\r\n");
delay_ms(8000);
printf("AT+LINK=12,6,149159\r\n");
short bit_TempLock2=1;// de khi nhan nut lock thi trang thai thay doi 1 lan BitTempWarning = 1;
//! output_low(LED_Warning);
//! delay_ms(500);
//! output_high(LED_Warning);
while(true) {
100 if(input(IG)==1) // Neu bat chia khoa {
output_high(power);
dem = 1;
// Nut Lock co cap cao nhat, Neu 3 nut nhan cung luc thi chi co nut lock duoc quen thuc hien
if(input(Button_Lock) ==1) // Neu nut Lock duoc nhan {
delay_ms(30);
if(Bit_TempLock2 == 1) {
Bit_TempLock = ~Bit_TempLock;// khi khoi tao bang 0 if(Bit_TempLock == 1)
{
BitTempAuto2 = 1;
FSendCommand(0b00000100|ControlUp); // gui lenh khoa cac nut o slave
output_high(LED_LockStatus);
} else }
else {
bytesend = 0;
FSendCommand(0); // gui lenh khong khoa cac nut o slave output_low(LED_LockStatus);
}
Bit_TempLock2 = 0;
}
101 }
else if(input(Button_Up) ==0) // Neu nut nang kieng duoc nhan {
if(BitTempWarning == 1) // neu den bao ket tat {
delay_ms(30); // chong doi nut nhan
FButtonAuto_Check(); // kiem tra nut auto co nhan khong // neu nhan cho bit nho auto len 1
FSendCommand(ControlUp); // gui lenh dieu khien nang kieng }
}
else if(input(Button_Down)==0) // nguoc lai neu nut ha kieng duoc nhan
{
delay_ms(30); // chong doi nut nhan
FButtonAuto_Check(); // kiem tra nut auto co nhan khong FSendCommand(ControlDown);
}
else // khong co nut nao nhan {
delay_ms(30);
if(BitTempAuto2==1) // Neu co che do auto {
BitTempAuto1 = 0;
} else {
BitTempButton = 1;
FSendCommand(Stop);
102 BitTempAuto2 = 1;
}
BitTempButton =1;
Bit_TempLock2 = 1;
} }else {
if(dem>=40) // 40*250ms = 10000ms = 10s {
FSendCommand(ControlUp);
dem = 1;
delay_ms(500);
output_low(power);
//! sleep();
} }
} // End of main while }
2. L pătrìnhăđi u khi năch ngătrìnhăthuăSLAVEă(ECU).
Ch ngătrìnhănƠyăsẽđ c n p vào PIC nằm trong m chăđi u khi n chính cửa s .
/* */
#include <16F877a.h>
#device *=16
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
103
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=7372800)
#use
rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1) // huong nhin tu cac OPTO tro len cac FET
// trang thai 0 la dieu khien, 1 la tat
#define Pin_Enable PIN_D5 // cho dong co hoat dong
#define Pin_Direct PIN_B0 // dieu khien huong dong co
#define ButtonUp PIN_C2
#define ButtonDown PIN_C3
#define ButtonAuto PIN_C5
#define LocateTop PIN_D0
#define LocateBot PIN_D1
const char ControlUp = 1,ControlDown= 2, Stop = 0;
char Control_State=0; // gia tri dieu khien dong co tu master short BitLock=0; // Bit dieu khien khoa cua master //!short Bit_TempLock = 0; //
char temp2 =0,i =0; // gia tri tam thoi trong chuong trinh chinh va bien dem.
short BitTemp = 0; // de cho de lay 1 lan khi dieu khien dong co tranh dong so cap khi doc cam bien
unsigned long adc;
char temp3 =0;
//!unsigned char dem=1;
//!// su dung 2 bit cuoi cua byte de dieu khien dong co
104
//!// Bit 0, trang thai 1 dieu khien dong co chay thuan, tt 0 dung dong co.
//!// Bit 1, trang thai 1 dieu khien dong co chay nghich, tt 0 dung dong co void MotorControl(char control)
{
switch(control) {
case ControlUp: // dieu khien dong co chay thuan if(input(LocateTop) ==1) // kieng chua len toi vi tri tren {
if(input_state(Pin_Direct)) {
output_low(Pin_Enable);
delay_us(3); // Thoi gian FET ngat output_low(Pin_Direct);
delay_ms(20); // delay de bao ve tiep diem relay BitTemp = 0;
}
output_high(Pin_Enable);
if(BitTemp == 0) {
{
delay_ms(70); // thoi gian de bo qua dong khoi dong BitTemp = 1;
} }
else // kieng da len toi vi tri tren {
//! Bit_TempLock = 0;
105 BitTemp = 0;
output_low(Pin_Enable); // Ngat dien cung cap dong co delay_us(3); // Thoi gian FET ngat
output_low(Pin_Direct);
Control_State = 0;
temp2 = 0;
} break;
case ControlDown: // dieu khien dong co chay nghich BitTemp = 0;
if(input(LocateBot) ==1) // kieng chua xuong toi vi tri duoi {
if(!input_state(Pin_Direct)) {
output_low(Pin_Enable);
delay_us(3); // Thoi gian FET ngat output_high(Pin_Direct);
delay_ms(20);
}
output_high(Pin_Enable);
} else // kieng da xuong toi vi tri duoi, ngat dien dong co {
output_low(Pin_Enable); // Ngat dien cung cap dong co delay_us(3);
output_low(Pin_Direct);
Control_State = 0;
temp2 = 0;
}
106 break;
case stop:
temp2 = 0;
output_low(Pin_Enable);
delay_us(3); // Thoi gian FET ngat output_low(Pin_Direct);
BitTemp = 0 Control_State = 0;
break;
} }
#int_RDA
void RDA_isr(void) {
char CTemp; // gia tri tam thoi trong chuong trinh ngat CTemp =getc();
Control_State =CTemp&3; // chi lay 2 bit cuoi de dieu khien dong co temp3 = Control_State;
temp2 = Control_State;
// Neu master khong dieu khien thi cho phep cac nut nhan o slave dieu khien // hoac master khoa thi slave khong dieu khien duoc
BitLock = bit_test(Ctemp,2); // bit 2 la bit Lock if(Control_State == stop)
{
temp2 = 0;
output_low(Pin_Enable);
delay_us(3);
output_low(Pin_Direct); // dung dong co
// Neu master dang dieu khien thi khong cho slave dieu khien
107 BitTemp = 0;
} }
void main() {
port_b_pullups(false);
output_low(Pin_Enable);
output_low(Pin_Direct); // dung dong co set_tris_a(0b11111111);
set_tris_b(0x11111110);
set_tris_c(0b10111111);
set_tris_d(0x11111111);
setup_timer_0(T0_INTERNAL|T0_DIV_256);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_adc(ADC_CLOCK_DIV_16);
SETUP_ADC_PORTS(AN0);
set_adc_channel(0);
delay_us(30);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(true)
/*******************************************************************
********/
label:
/*******************************************************************
********/
// Phan dieu khien dong co.
// neu master dang dieu khien hoac dang khoa thi khong quet nut nhan
108 if(Control_State != 0)
{
// neu master dieu khien nang va kieng chua len toi vi tri top thi cho dieu khien nang
if(Control_State == ControlUp) {
MotorControl(ControlUp);
}
else if(Control_State == ControlDown) {
MotorControl(ControlDown);
} }
else // neu master khong dieu khien {
// Nut nhan nang kieng bi tac dong, Neu trong luc bi tac dong ma da len // toi diem cao nhat cua cua kieng thi khong cho nang kieng.
if(BitLock == 0) // master dang ko khoa {
//! Bit_TempLock = 1;
if(temp2 == ControlUp)
{ MotorControl(ControlUp);
}
else if(input(ButtonUp) == 0 ) {
MotorControl(ControlUp);
}
// khong nhan duoc Down khi da xuong toi vi tri duoi else if(input(ButtonDown) == 0 )
109 {
MotorControl(ControlDown);
} else {
MotorControl(Stop);
} }
}// End of ControlValue
/***************************** Kiem tra ket***************************/
set_adc_channel(0);
delay_us(23);
adc = read_adc();
if(adc >=650) {
// dao chieu dong co (XOR) trong thoi gian 400 ms roi dung dong co putchar(0xAA); // bao ket
MotorControl(ControlDown);
delay_ms(400); // Motor quay nguoc lai 50mm temp3 = Control_State;
MotorControl(Stop);
Control_State = 0;
i=0;
// neu dung dong co trong 20s ma khong co tin hieu dieu khien tu mater thi // tu dong tiep tuc dieu khien dong co theo trang thai truoc
while(i<=105) // delay 10s {
i++;
delay_ms(100);
110
if(Control_State != 0) // dang cho gia tri dieu khien ha kieng tu master {
//Co dieu khien tu master
MotorConTrol(Control_State); // dieu khien theo gia tri master putc(0x55);//bao khong ket ve master
goto label;
//! Break; // thoat khoi vong lap while }
else if(input(ButtonDown) ==0) {
MotorControl(ControlDown);
putc(0x55); // bao khong ket ve master Control_State = 0;
goto label;
//! Break; // thoat khoi vong lap while }
else if(i>=100) {
if(temp3 == 0) // Neu ko co auto {
putc(0x55); // bao khong ket ve master Break;
} else {
MotorConTrol(ControlUp);
temp2 = ControlUp;
putc(0x55);
break;
111 }
//! Break; // thoat khoi vong lap while }
} // End of while //! label:
} // End If
}// End of Main while }