Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

XMEGA-A3BU Xplained board contrast adjustment

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Jerry

Bascom Member



Joined: 25 May 2004
Posts: 40
Location: New York

usa.gif
PostPosted: Tue Nov 26, 2019 9:23 pm    Post subject: XMEGA-A3BU Xplained board contrast adjustment Reply with quote

Did some searching and didn't see anything so figured I'd post here.
A simple example showing how to adjust the display contrast on the development board XMEGA-A3BU.

Here is the code; I attached the relevant files as a download. Hope it helps someone. Very Happy
Code:
'*****************************************
' XPLAINED XMEGA-A3BU Development board. *
' Example for contrast adjustment of the *
' LCD display.                           *
' Jerry J. 11/26/19                      *
'*****************************************
'The display is made by Newhaven Displays Inc. Part number NHD-C12832A1Z-FSW-FBW-3V3

$regfile = "XM256A3BUDEF.DAT"                               'regfile for the pre-built XMEGA board
$crystal = 32000000                                         '32MHz
$hwstack = 64
$swstack = 40
$framesize = 80
$lib "glcdeadogm128x3.lib"                                  ' Library for the XPLAINED XMEGA-A3BU Display

'Set up the oscillator
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

'Set up the ports for the onboard LED's.
Config Portr.0 = Output
Led0 Alias Portr.0                                          'LED 0
Config Portr.1 = Output
Led1 Alias Portr.1                                          'LED 1

'set up the backlight for the display
Config Porte.4 = Output
Display_backlight Alias Porte.4

'Configure the library used to drive the display
Config Graphlcd = 128x64eadogm , Cs1 = Portf.3 , A0 = Portd.0 , Si = Portd.3 , Sclk = Portd.1 , Rst = Porta.3

'Set up TCD1 for 1mS periodic interrupts
'The 32MHz clock will be divided by 64, resulting in 2MHz. The timer tics will be at a 500 kHz rate, so 2uS ticks.
'config timer for normal mode timer mode
Config Tcd1 = Normal , Prescale = 64                        'Ticks of 32 mHz / 64 = 2MHz

'timer load value to generate 1 msec intterupts
Const Timertics = 500                                       'trigger interrupt every 1 msec

Tcd1_per = Timertics                                        'Period register 500 counts from to overflow in 1 millisecond
On Tcd1_cca My_isr                                          'On interrupt go to interrupt service routine My_isr
Enable Tcd1_cca , Med                                       'Enable interrupt
Enable Interrupts                                           'global interrupts on.

'specify the font
Setfont Font8x8

'Set up pushbuttons on the right side of the board used to change the contrast
Sw1 Alias Pinf.1                                            'will increase contrast when pushed
Sw2 Alias Pinf.2                                            'will decrease contrast when pushed
Dim Tmr_w1 As Word                                          'Word variable used for timer interrupt

'After the LCD is placed in command mode (Reg_sel=0) you must follow with the contrast value to write to the volume register.
'The value to write should be between 20 and 40, reference XMEGA-A3BU hardware guide.
'Data order is, MSB 1st clocked on rising edge.
'The optimum value is 30, the higher the value the weaker the contrast.

Dim Glcd_vol_cmd As Byte : Glcd_vol_cmd = &B10000001        '129 decimal is volume command register selected.
Dim Mycontrast As Byte : Mycontrast = 20                    'Minimum is 20, maximum is 50 based on experimentation.
Display_sel Alias Portf.3                                   'Display select line 0=select.
Reg_sel Alias Portd.0                                       '0=cmd mode,1=data mode
So Alias Portd.3                                            'Serial output
Myclk Alias Portd.1                                         'Serial clock

Config Submode = New
'^^^^^^SUBS in HERE^^^^^^^^^^^^^^^^^^^^^^^^^
'The display controller chip is
'write contrast value to the volume control register
Sub Write_contrast(setval As Byte)
     Reset Reg_sel                                          '0=command, 1=display data, place chip in command mode
     Reset Display_sel                                      '0=chip selected
     Shiftout So , Myclk , Glcd_vol_cmd , 1                 'MSB 1st on rising clock edge, select command mode
     Shiftout So , Myclk , Setval , 1                       'Shift out command data
     Set Display_sel                                        'Release display selected
     Lcdat 3 , 1 , "CONTRAST = " ; Mycontrast               'show contrast value on screen
End Sub
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Set Display_backlight                                       'turn on display backlight
Cls                                                         'clear display screen.
Mycontrast = 30                                             'Set startup contrast value
Call Write_contrast(mycontrast)                             'write optimum contrast
Lcdat 1 , 1 , "BASCOM AVR"                                  'put text on the display

'Adjust contrast main loop
Do
  If Tmr_w1 = 0 Then
     If Sw1 = 0 Then
        Incr Mycontrast
        If Mycontrast > 50 Then Mycontrast = 20             'let it wrap around
        Toggle Led0                                         'show incrementing button press
        Call Write_contrast(mycontrast)
     End If
     If Sw2 = 0 Then
        Decr Mycontrast
        If Mycontrast < 20 Then Mycontrast = 50             'let it wrap around
        Toggle Led1                                         'show decrementing button press
        Call Write_contrast(mycontrast)
     End If
     Tmr_w1 = 200                                           'every 200msec update contrast
  End If
Loop

'1 millisecond interrupt
My_isr:
   Tcd1_per = Timertics                                     'Reload counter with a value of 500 will overflow at 1 msec rate.
   If Tmr_w1 > 0 Then Decr Tmr_w1                           'Decrement the timer variable on each interrupt.
Return
End

'font used
$include "font8x8.font"
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Nov 27, 2019 9:58 am    Post subject: Reply with quote

Hello Jerry,

Thanks for sharing the code. Very Happy

_________________
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 -> Share your working BASCOM-AVR code here 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