View Single Post
Old 15-11-2011, 12:19 AM   #1
josdoaitran
Nhập môn đệ tử
 
Tham gia ngày: Jan 2011
Bài gửi: 1
:
[Xin giúp]Đo nhiệt độ hiển thị lên máy tính [píc16f877-ds18b20- gui Matlab]

Mình đã cố gắng thực hiện đề tài nhưng gặp khó khăn lớn ở phần giao tiếp máy tính qua Matlab- cái này mình chưa làm bao giờ và cũng chẳng biết lấy câu lệnh nào để get và hiển thị dữ liệu lên GUI của matlab.

Phẩn đo và hiển thị lên 5 con led 7 đoạn với code dưới mình đã làm thành công.

Nay bạn nào đã từng làm gui Matlab - rx232 xin giúp mình với.

Do mình nhận đề tài hiển thị dùng Matlab nên mong các bạn giúp đỡ , và đây cũng là yếu điểm của mình. Bạn nào làm thành công xin chia sẽ cho mình với về phần Gui hiển thị giá trị nhiệt độ.

Mình đã dùng mạch FT232 mua ở Thiên Minh về gắn mạch chung gnd, TX-PIC với Rx của FT 232, Tx-PIC với Tx của FT 232. và cũng viết thử nhưng chưa thành công.

Trích:
#include <16f877a.h>
#use delay(clock=20M)
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, NOPUT
#use rs232(baud=9600,parity=n,xmit=pin_c6,rcv=pin_c7)
#define DS PIN_A3
int8 led1,led2;
int8 const seg7[10] ={0xC0,0x8F9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x 90};
int8 const char9[10] ={'a','b','c','d','e','f','g','h','j','k'};
void reset()
{
output_low(DS);
delay_us( 500 );
output_float(DS);
delay_us( 500 );
output_float(DS);
}
void write(int data)
{
int count;
for (count=0; count<8; ++count)
{
output_low(DS);
delay_us( 2 );
output_bit(DS, shift_right(&data,1,0));
delay_us( 60 );
output_float(DS);
delay_us( 2 );
}
}
unsigned read()
{
int count, data;
for (count=0; count<8; ++count)
{
output_low(DS);
delay_us( 2 );
output_float(DS);
delay_us( 8 );
shift_right(&data,1,input(DS));
delay_us( 120 );
}
return( data );
}
unsigned int CHUYEN(float data)
{
data = data* 0.625;
return(data);
}


void DS18B20()
{
int8 byte2,led1,led2,byte1,dec,decimal,led3,i,j,busy=0;
int16 data;
unsigned char nhiet_do,so_le;

reset();
write(0xCC);
write(0x44);
while (busy == 0)
busy = read();
reset();
write(0xCC);
write(0xBE);
byte1 = read();
byte2 = read();
data=make16(byte2,byte1);

data=data>>4;
data=data&0x0ff;
led2=data/10;
led1=data%10;
decimal=byte1&0x0f;
dec=CHUYEN(decimal);

putc(char9[led2]);
putc(char9[led1]);
putc(char9[dec]);


for(i=0;i<20;i++)
{
for(J=0;J<50;J++)
{
output_low(pin_d0);
output_b(seg7[led2]);
delay_ms(1);
output_high(pin_d0);


output_low(pin_d1);
output_b(seg7[led1]);
output_low(pin_b7);
delay_ms(1);
output_high(pin_d1);

output_low(pin_d2);
output_b(seg7[dec]);
delay_ms(1);
output_high(pin_d2);

output_low(pin_d3);
output_b(0b10011100);// hien thi do
delay_ms(1);
output_high(pin_d3);

output_low(pin_d4);
output_b(0b11000110);// hien thi c
delay_ms(1);
output_high(pin_d4);
}
}

}
void main()
{
SET_TRIS_A(0b00001000);
SET_TRIS_B(0);
OUTPUT_A(0XFF);
OUTPUT_LOW(PIN_A0);
while (1)
{

DS18B20();

}
}
josdoaitran vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn