penggunaan i2c pada pic 16f877a dan ditampilkan pada lcd....

agamanshor

New member
assalamualaikum agan"..
semoga dalam keadaan sehat semua,,
amin
mohon bantuannya ne agan"
ane sedang mencoba menampilkan data sensor ke lcd dengan I2C,,,
namun data dari scl dan sdanya tidak tampil di lcd,,,
mohon bantuaannya ya gan
berikut program yang saya buat..

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

void write_dtsenseh(unsigned short address,unsigned short w_data)
{
  I2C1_Start(); // issue I2C start signal
  I2C1_Wr(0xE0); // send byte via I2C (device address + W)
  I2C1_Wr(address); // send byte (address of dt_sense location)
  I2C1_Stop();
}
unsigned char read_dtsenseh(unsigned short address)
{
  unsigned char temp3,temp4;
  unsigned int nilai;
  I2C1_Start();
  I2C1_Wr(0xE0);
  I2C1_Wr(address);
  I2C1_Repeated_Start();
  I2C1_Wr(0xE1);
  temp3=I2C1_Rd(1);
  temp4=I2C1_Rd(0);
  I2C1_Stop();
  nilai = (unsigned int)temp3*256 + temp4;
  return nilai;
}
int hmi;
unsigned char ch;
void main(void)
{
  I2C1_Init(100000);        // initialize I2C communication
  TRISC=0xFF;
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);              // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_out(1,1,"humidity") ;
  while (1)
{
  hmi = read_dtsenseh(0);
  Lcd_out(2, 1, hmi);
 
  ch = hmi / 1000;
  Lcd_Chr(2,5,0x30+ch); // Write result in ASCII format
  ch = (hmi / 100) % 10; // Extract hundres of millivolts
  Lcd_Chr_CP(0x30+ch); // Write result in ASCII format
  ch = (hmi / 10) % 10; // Extract tens of millivolts
  Lcd_Chr_CP(0x30+ch); // Write result in ASCII format
  ch = hmi % 10; // Extract digits for millivolts
  Lcd_Chr_CP(0x30+ch);
  Lcd_Chr_CP('.');
  delay_ms(1000);
  }

}
 

Welcome to EDABoard.com

Sponsor

Back
Top