loveboom3012
14-11-2013, 01:42 AM
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 ạ
#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);
}
}
#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);
}
}