Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SH1106 brightness settings - how to change?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
hueppi114

Bascom Member



Joined: 28 Jun 2015
Posts: 5

blank.gif
PostPosted: Tue Jan 14, 2020 8:14 pm    Post subject: SH1106 brightness settings - how to change? Reply with quote

Dear all,
I recieved some SH1106 few days ago, and I would like to dim it a little bit, but it doesn´t work.
I tried to adjust the settings in the .lib file, as I did successfully in a .lib file for SSD1306, but brightness is always on the maximum level.
I have a .lib file from bascomforum.de, it works properly except of brightness settings.

here an extract of the library of the SH1106:

; slave address, CO|DC|ctrl, data
;CO-continuation bit, if 0 next data will be normal data
;ctrl-if 0, data is a command, if 1 data is normal data stored in GDRAM

_lcd_init_data:
.db &HAE, &H00 ; SETDISPLAYCLOCKDIV , ratio 0x80
.db &H10, &H40 ; SETMULTIPLEX , 1f 128x32
.db &H81, &HCF ; SETDISPLAYOFFSET , 00
.db &HA1, &HC8 ; SETSTARTLINE , CHARGEPUMP
.db &HA6, &HA8 ; vccstate 14 , MEMORYMODE
.DB &H3F, &HD3 ; A0 upside down SEGREMAP
.db &H00, &HD5 ; COMSCANDEC , SETCOMPINS
.db &H80, &HD9 ; 02 128x32 12 , SETCONTRAST
.db &HF1, &HDA ; constrast value 255, SETPRECHARGE,
.db &H12, &HDB ; vccstate f1 , SETVCOMDETECT
.db &H40, &H20 ; &H40 , DISPLAYALLON_RESUME
.db &H02, &H8D ; NORMALDISPLAY
.db &H14, &HA4
.db &HA6, &HAF

I adjusted the contrast value to different levels like 50, 10 (written in hex), but brightness is always the maximum.
As said, it works in the .lib file for SSD1306 and SSD1306 displays. The library for SSD1306 is embedded in my bascom 2.0.8.2,
but, as library for SH1106 is not in, I transfered it manually into lib folder.
Does somebody have an idea?
Thanks in advance
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Jan 15, 2020 11:09 am    Post subject: Reply with quote

according the datasheet, the contrast is set with &H81 followed by the value.
the table you post has wrong remarks : .db &H81, &HCF ; SETDISPLAYOFFSET , 00
i think the CF is what you want to change.

you can also use lcdcmd and lcddata

like this :

lcdcmd &H81
lcddata 0-255 value for contrast

_________________
Mark
Back to top
View user's profile Visit poster's website
hueppi114

Bascom Member



Joined: 28 Jun 2015
Posts: 5

blank.gif
PostPosted: Wed Jan 15, 2020 7:03 pm    Post subject: Reply with quote

Thank you!
it works to change it in the library file.

But when I want to write it as a commane

lcdcmd &H81
lcddata 50

I get the remark "label not found (LCD_CONTROL).
Is that a library? I cannot find in the Lib-folder in Bascom

regards
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Jan 15, 2020 8:12 pm    Post subject: Reply with quote

this is a graphic lcd. so i was wrong, it must be : GLCDCMD and GLCDDATA
but the lib must support it. the labels _gwrite_cmd and _gwrite_data must be present.
for example from glcdssd1306 :

_gwrite_cmd:
#IF _XMEGA
rcall _XM_i2c_start
#ELSE
call _i2c_start
#ENDIF
ldi r17,&H78 ; command address
#IF _XMEGA
rcall _XM_i2c_write ; write slave address
#ELSE
call _i2c_write ; write slave address
#ENDIF
mov r17,r24 ; command address
Rjmp _Gwrite_DataMisc ; same code
_gwrite_data:
ldi r17,&H78 ; data write

_________________
Mark
Back to top
View user's profile Visit poster's website
hueppi114

Bascom Member



Joined: 28 Jun 2015
Posts: 5

blank.gif
PostPosted: Sat Jan 18, 2020 11:23 am    Post subject: Reply with quote

thank you,
the library I have for the SH1106 has this informations like this

_gwrite_cmd:
call _i2c_start
ldi r17,&H78
call _i2c_write ; write slave address
ldi r17,&H00 ; command mode
call _i2c_write
mov r17,r24 ; command address
Rjmp _Gwrite_DataMisc ; same code
_gwrite_data:
ldi r17,&H78 ;write slave address data write
call _i2c_start
call _i2c_write ; write data mode
ldi r17,&H40
call _i2c_write
mov r17,r24 ; data
_gwrite_datamisc:
call _i2c_write ; write Data
jmp _i2c_stop


but I still can not change brightness in the programm, only if I change the library at the start of the program.


When I wrte somewhere in the programm

GLCDCMD &H81

GLCDDATA 50 (for example),

brightness doesn´t change
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sun Jan 19, 2020 11:30 am    Post subject: Reply with quote

i guess that is because how this interface works.
both the glcdcmd and data are isolated transactions but the chip needs 2.

the problem is that the command must be followed by a data byte without i2cstop/start.

so lets look how the table send command does this :
- send i2cstart
- send each byte from the table and the first byte is the slave address
- i2cstop

so the solution is simple :
use I2CSEND
just send to the slave address &H78 the following bytes : &H78,&H81, your contrsat
and i2cSEND will do the rest

_________________
Mark
Back to top
View user's profile Visit poster's website
hueppi114

Bascom Member



Joined: 28 Jun 2015
Posts: 5

blank.gif
PostPosted: Sun Jan 19, 2020 9:40 pm    Post subject: Reply with quote

Hello,

I tried to send the bytes like this, to go to maximum brightness, for example:

I2cstart
I2Csend &H78 , &H81 , &HFF
I2Cstop

but I recieve a remark that there is an invalid data type &H81, but this is the adress to change the brightness.
Did I send it in a wrong way? There are no further details in Bascom-AVR-help
best regards
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Jan 20, 2020 9:51 am    Post subject: Reply with quote

you best read the help one more time because the way you want to send multiple bytes is not ok.
there is an example that send multiple bytes using an array.
but you could store there data in a WORD too and send that.

from the help:
Code:
For A = 1 To 10
 Ax(a) = A                                                 'Fill dataspace
Next
Bytes = 10
I2csend Slave , Ax(1) , Bytes


so you would have code like :
ax(1)=&H81 : ax(2)= value
I2csend &H78 , Ax(1) , 2
 

_________________
Mark
Back to top
View user's profile Visit poster's website
hueppi114

Bascom Member



Joined: 28 Jun 2015
Posts: 5

blank.gif
PostPosted: Mon Jan 20, 2020 10:47 pm    Post subject: Reply with quote

I tried to define the both bytes for config register and brightness as follows:

Dim Testarray(2) as word
Testarray(1) = &H81 'Config register for brightness
Testarray(2) = 250 'value for brightness

and to send to the display:
I2cstart
I2csend &H78 , Testarray(1) , 2
I2cstop

but brightness doesn´t change. What can be wrong?
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Tue Jan 21, 2020 11:19 am    Post subject: Reply with quote

hueppi114 wrote:
I tried to define the both bytes...

Dim Testarray(2) as word


Byte vs. Word

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Tue Jan 21, 2020 11:20 am    Post subject: Reply with quote

hueppi114 wrote:
I tried to define the both bytes...

Dim Testarray(2) as word


Byte != Word

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 21, 2020 12:22 pm    Post subject: Reply with quote

you should not use both i2cstart, i2csend and i2cstop !
just the i2csend !
please read the help to understand i2csend and the difference between i2cstart ,i2cwbyte etc.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum