PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

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

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 14-11-2013, 01:42 AM   #1
loveboom3012
Đệ tử 1 túi
 
Tham gia ngày: Jun 2011
Bài gửi: 18
:
giao tiếp i2c PIC16f887 và TC74

Mong mọi người giúp em với ạ, chạy mô phỏng chỉ hiễn thị mỗi gia trị 255 thôi , không hiểu tại sao luôn hix, file mô phỏng em đính kèm dưới ạ
Code:
#include <htc.h>
#include <stdio.h>
#include "lcd.h"
#include "i2c.h"

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS);

#define slave_add	0x90
#define write	0
#define read	1
void hienthilcd(unsigned int t)
{
	char tr,ch,dv;
	tr=t/100;
	ch=(t-tr*100)/10;
	dv=t-tr*100-ch*10;
	lcd_gotoxy(5,1);
	lcd_putc(tr+0x30);
	lcd_gotoxy(6,1);
	lcd_putc(ch+0x30);
	lcd_gotoxy(7,1);
	lcd_putc(dv+0x30);
}
void read_temp()
{
	unsigned int temp;
	//send start condition
	i2c_start();
	//send slave add mode write
	i2c_write((slave_add<<1)|write);
	i2c_write(0x00);
	//send restart condition
	i2c_stop();
	i2c_start();
	//begin read
 	i2c_write((slave_add<<1)|read);
	temp = i2c_read(0);
	i2c_stop();
	__delay_ms(100);
	hienthilcd(temp);
}

void main()
{
	unsigned int i;
	char t;
	lcd_init();
	i2c_init();
	while(1){
		read_temp();
		__delay_ms(100);
	}
	
}
File Kèm Theo
File Type: rar TC74.rar (31.5 KB, 6 lần tải)
loveboom3012 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


Múi giờ GMT. Hiện tại là 09:29 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