'*****************************************
' 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" |