avatar_Peter

Sensor INA226

Begonnen von Peter, 15.01.2021, 20:24:42 CET

Vorheriges Thema - Nächstes Thema

Peter

Hallo
Hier ein Programm zum auslesen des INA226.
Ausgelesen wird die Spannung und der Strom. Diese
wird dann auf ein LCD ausgegeben.

program ina226

'VBUS muss an Plus von der Spannung des Verbrauchers.
'Nicht an plus von dem Modul.

DIM text1 , text2, text3 as Word
DIM aus1, aus2 as String [6]

dim LCD_RS as sbit at RB4_bit
    LCD_EN as sbit at RB5_bit
    LCD_D4 as sbit at RB0_bit
    LCD_D5 as sbit at RB1_bit
    LCD_D6 as sbit at RB2_bit
    LCD_D7 as sbit at RB3_bit

dim LCD_RS_Direction as sbit at TRISB4_bit
    LCD_EN_Direction as sbit at TRISB5_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit


main:
ANSELB = 0


I2C1_Init (100000)
delay_ms(100)

LCD_Init ()
LCD_CMD(_LCD_CLEAR)
LCD_CMD(_LCD_CURSOR_OFF)
'LCD_Out (1,1,"Peter")

I2C1_Start ()
I2C1_WR (0x80)
I2C1_WR (0)
I2C1_WR (0x44)
I2C1_WR (0x27)
I2C1_Stop
delay_ms(20)
I2C1_Start
I2C1_WR (0x80)
I2C1_WR (0x05)
I2C1_WR (0x08)
I2C1_WR (0x00)
I2C1_Stop
delay_ms(300)

While True
I2C1_Start
I2C1_WR (0x80)
I2C1_WR (0x02)           'Spannung
I2C1_Stop

delay_ms (10)
I2C1_Start
I2C1_WR (0x81)
text1 = I2C1_rd (0x01)
text2 = I2C1_rd (0x01)
I2C1_Stop

text3 =((text1 <<8)+text2)/10*125/100

wordtostr (text3,aus1)
LCD_Out(1,1,aus1)
'----------------------------
I2C1_Start
I2C1_WR (0x80)
I2C1_WR (0x04)          'Strom
I2C1_Stop

delay_ms (10)
I2C1_Start
I2C1_WR (0x81)
text1 = I2C1_rd (0x01)
text2 = I2C1_rd (0x01)
I2C1_Stop

text3 =((text1 <<8)+text2)/10*25/10

wordtostr (text3,aus1)
LCD_Out(2,1,aus1)

delay_ms(800)


Wend

end.


Schnellantwort

Achtung: In diesem Thema wurde seit 120 Tagen nichts mehr geschrieben.
Wenn Sie nicht absolut sicher sind, dass Sie hier antworten möchten, starten Sie ein neues Thema.

Name:
Tastenkürzel: Alt+S Beitrag schreiben oder Alt+P für Vorschau

Similar topics (1)