View Single Post
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