Angeblich soll dieser Code funktionieren, kannst Du ja mal ausprobieren.
$regfile = "m8def.dat"$crystal = 1000000 ' 1MHz (You can use any clock).$hwstack = 32$swstack = 16$framesize = 40Declare Sub SetContrast5V4bit(Byval Contrast_value As Byte)Dim Lcd_contrast As ByteConfig Lcdpin = Pin , Db4 = PortC.0 , Db5 = PortC.1 , Db6 = PortC.2 , Db7 = PortC.3 , E = PortC.4 , Rs = PortC.5Config Lcd = 16 * 2 , Chipset = Dogm162v5Cursor Off NoblinkClsLCD "Contrast 0-63"Waitms 2000For Lcd_contrast = 0 to 63 Call SetContrast5V4bit(Lcd_contrast) ' You can also use a constant, example, Call SetContrast5V4bit(10) Cls LCD "Contrast: " ; Lcd_contrast Waitms 2000Next Lcd_contrastDo !nopLoopEnd' =============================================Sub SetContrast5V4bit(Byval Contrast_value As Byte) ' This subroutine will set the contrast of an LCD module EA DOGM162. ' The LCD module MUST be connected to 5V and use the 4-bit mode. ' This code works with the pins specified in "Config Lcdpin". If you ' change the pins in "Config Lcdpin", this code will still work because ' we use the Bascom internal routine to send the command to the LCD. ' The LCD contrast is a value between 0 and 63. The value passed to ' this subroutine is a byte. If the passed value is greater than 63, ' the passed value will be limited to 63. Note also that it is very ' likely that only a limited range of the 64 possible values will ' produce a valid contrast setting on the LCD, so your main program ' will have to limit the used minimum and maximum values. ' ' Do not use this subroutine if the LCD is connected to 3.3V! ' This code disables the internal voltage booster which must be used ' when the LCD is connected to 3.3V. Local Ins_P_I_Contr_set As Byte Local Ins_Contr_Set As Byte If Contrast_value > 63 Then Contrast_value = 63 ' We limit the value to 63 Endif ' The 6 bits of the contrast value are sent to the Sitronix ' ST7036 controller chip with two distinct instructions. ' First the passed contrast value will be mapped into two bytes. ' The upper nibble of the byte is used to define the instruction. ' The lower nibble of the byte is used for the parameters of the ' instruction. The contrast value will be mapped into the lower ' nibble of these two bytes. '========================================== ' Map C3, C2, C1, C0 into the instruction "Contrast Set". Ins_Contr_Set = Contrast_value ' Clear the upper nibble, keep C3, C2, C1 and C0 into the lower nibble. Ins_Contr_Set = Ins_Contr_Set AND &B00001111 'Clear upper nibble ' Add the value C3, C2, C1 and C0 to the instruction value. Ins_Contr_Set = Ins_Contr_Set + &B01110000 '========================================== ' Map C5 and C4 into the instruction "Power/ICON control/Contrast Set". Ins_P_I_Contr_set = Contrast_value 'Shift Right four times, so that C5 C4 will go in position Bit1 and Bit0. 'Bit7, Bit6, Bit5, Bit4, Bit3, Bit2 will be 0 after the shift operations. Shift Ins_P_I_Contr_set , Right , 4 ' Add the value C5 and C4 to the instruction value. Ins_P_I_Contr_set = Ins_P_I_Contr_set + &B01010000 ' ^---- 0=ICON Off ' ^--- 0=Booster Off (5V)! '========================================== ' Now we send 4 instructions to the LCD '========================================== _temp1 = &B00101001 'Instruction "Function Set" select instruction table 1 '-------------^------------ = DL (Interface 8/4 bits). 0=4-bit interface. '--------------^----------- = N (Number of lines). 1=two lines. Must be 1 '---------------^---------- = DH (Double height font). 1=DH. Must be 0 '----------------^--------- = IS2 (Instruction table select). Must be 0 '-----------------^-------- = IS1 (Instruction table select). Must be 1 !rCall _Lcd_control ' Send the instruction to the LCD '========================================== _temp1 = Ins_Contr_Set ' Instruction "Contrast Set" !rCall _Lcd_control ' Send the instruction to the LCD '========================================== _temp1 = Ins_P_I_Contr_set ' Instruction "Power/ICON/Contrast Set" !rCall _Lcd_control ' Send the instruction to the LCD '========================================== _temp1 = &B00101000 'Instruction "Function Set" select instruction table 0 '-------------^------------ = DL (Interface 8/4 bits). 0=4-bit interface. '--------------^----------- = N (Number of lines). 1=two lines. Must be 1 '---------------^---------- = DH (Double height font). 1=DH. Must be 0 '----------------^--------- = IS2 (Instruction table select). Must be 0 '-----------------^-------- = IS1 (Instruction table select). Must be 0 !rCall _Lcd_control ' Send the instruction to the LCD '==========================================End Sub' -------