🇩🇪
program ina219
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 (0x19)
I2C1_WR (0x9F)
I2C1_Stop
delay_ms(20)
I2C1_Start
I2C1_WR (0x80)
I2C1_WR (0x05)
I2C1_WR (0x10)
I2C1_WR (0x7E)
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)/2
wordtostr (text3,aus1)
LCD_Out(1,1,aus1)
'----------------------------
I2C1_Start
I2C1_WR (0x80)
I2C1_WR (0x01) '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)
wordtostr (text3,aus1)
LCD_Out(2,1,aus1)
delay_ms(800)
Wend
end.
Zitat von: Peter in 03.07.2022, 19:37:51 CESTNochwas. Anscheinend willst du 31KHz als Takt haben.
program Blink_31
' Testprog. für 31 kHz
' PIC18F14K22 / PIC18F24K22
' an OSC2 kann die Oszillatorfrequenz/4 gemessen werden,
' bei 31kHz sind das 7,75kHz +-Toleranz
' Declarations section
' Main program
main:
' Voreinstellungen:
OSCCON = 0x02 'Umschalten auf LFINTOSC mit 31 kHz
TRISA = 0
TRISB = 0
TRISC = 0
while TRUE
PORTC = 0
delay_ms(1000)
PORTC = 255
delay_ms(1000)
wend
end.