Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Six digit numeric LCD with HT1621 and Attiny804

 
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
srecko

Bascom Member



Joined: 05 Sep 2007
Posts: 23
Location: Dolenjske Toplice

slovenia.gif
PostPosted: Thu Apr 28, 2022 1:39 am    Post subject: Six digit numeric LCD with HT1621 and Attiny804 Reply with quote

Hello all. I'm sharing you a working example of how to work with HT1621 LCD controller chip. This example is for six digit display with battery charge symbol, available in different stores. It is back-lit with white, blue or green LED. I hope you find this code useful. More info is in the file itself. All comments are welcome. Best wishes to all.

Code:

'This is just a sample program demonstrating how to use HT1621 based LCD displays.
'This example works with six digit display with battery indicator, purchased on AliExpress.
'https://www.aliexpress.com/item/32885549612.html
'Author: Srecko Lavric, Eldema elektronika, www.eldema.si, info@eldema.si
'Sorry, no English page at the moment Sad

'Dots are only available on three digits, other three segments are used to show battery
'symbol and lines instead of dots. The "real" supply voltage for this display is 3.3V,
'below 3V it becomes dim and above 4V blank segments start showing. Vewing angle is very poor
'from below (6 o'clock) but great from above (12 o'clock). If you need more info, please
'check the datasheet for HT1621B. This example uses Xtiny library, but it works on other
'chips too. It is done my way so it can surely be optimized.

'You are free to use this code however you want, but with absolutely no warranties whatsoever!

$regfile = "atXtiny804.DAT"
$crystal = 3333333
$framesize = 128
$hwstack = 128
$swstack = 64

Config Porta.1 = Output : Ht_cs Alias Porta.1
Config Porta.2 = Output : Ht_clk Alias Porta.2
Config Porta.3 = Output : Ht_data Alias Porta.3

Config Vref = Dummy , Adc0 = 1v5
Config Adc0 = Single , Adc = Enabled , Reference = Internal , Prescaler = 32 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32 , Mux = 7

'Display variables/constant
Const P = 10                                                'communication delay
Dim 7seg(30) As Byte                                        'segment combination data
Dim Disp(6) As Byte                                         'digita for six digits
Dim Disp_raw As Byte                                        'variable for shifting to display

'General variables
Dim N As Word , M As Word , Tmp As Byte
Dim Tmp2 As Long , Tmp3 As Long
Dim Ubat As Dword                                           'battery voltage x 10
Dim Bat As Byte                                             'this will show which battery symbols to show
Dim Value As Long                                           'some value to show
Dim Temp As Integer                                         'some temperature value x 10

'reset HT1621 chip (see datasheet)
Set Ht_data
Set Ht_clk
Set Ht_cs
Waitus P
Reset Ht_cs
Waitus P

'Load combination data from table to the variable for quick access
Restore Tabela
For N = 1 To 30
   Read 7seg(n)
Next N

'initialize HT chip
Restore Ht_init
For N = 1 To 4
   Read Tmp
   Shiftout Ht_data , Ht_clk , Tmp , 0 , 8 , P
Next N

Waitms 100

Do
'Read battery voltage
   Ubat = Getadc(7)
'Calculate result for divider with 33k and 10k resistors on Ch 7
   Ubat = Ubat * 1000
   Ubat = Ubat / 1573

'Set the bat value according to actual voltage
   Bat = 0
   If Ubat > 300 Then Bat = 1                               '> 3.0V
   If Ubat > 320 Then Bat = 2                               '> 3.2V
   If Ubat > 340 Then Bat = 3                               '> 3.4V

'This simply sets the appropriate variables to show certain characters
   Gosub Compile_minus                                      'this will show " ---- " on the display
   Gosub Show_display                                       'this sub puts the content on display
   Wait 2

'Clear display
   Gosub Compile_blank                                      'this will show blank display
   Gosub Show_display                                       'this sub puts the content on display
   Wait 2

'Show some error
   Gosub Compile_adc_error                                  'this will show "AdCErr"
   Gosub Show_display                                       'this sub puts the content on display
   Wait 2

'Show some numbers
   Value = 12345
   Gosub Compile_value                                      'show number on the display
   Gosub Show_display
   Wait 2

'Show negative number. 1st digit is -
   Value = -54321
   Gosub Compile_value                                      'show number on the display
   Gosub Show_display
   Wait 2

'Show battery voltage
   Value = Ubat
   Gosub Compile_value                                      'show number on the display
   Gosub Show_display
   Wait 2

'You can show temperature too.
   Temp = 217                                               '21.7°C
   Gosub Compile_temp
   Gosub Show_display
   Wait 2
Loop
End

'************ END OF LOOP ************************************

Compile_value:
   If Value < 0 Then Disp(6) = 11 Else Disp(6) = 12         'Show blank or minus
   Tmp2 = Abs(value)
   Tmp3 = Tmp2 / 10000                                      'digit 5
   Incr Tmp3 : Disp(5) = Tmp3
   Tmp2 = Tmp2 Mod 10000
   Tmp3 = Tmp2 / 1000                                       'digit 4
   Incr Tmp3 : Disp(4) = Tmp3
   Tmp2 = Tmp2 Mod 1000
   Tmp3 = Tmp2 / 100
   Incr Tmp3 : Disp(3) = Tmp3                               'digit 3
   Tmp2 = Tmp2 Mod 100
   Tmp3 = Tmp2 / 10
   Incr Tmp3 : Disp(2) = Tmp3                               'digit 2
   Tmp3 = Tmp2 Mod 10
   Incr Tmp3 : Disp(1) = Tmp3                               'digit 1

   'You can blank leading zeros if you want
   Tmp2 = Abs(value)
   If Tmp2 < 10000 Then Disp(5) = 12
   If Tmp2 < 1000 Then Disp(4) = 12
   If Tmp2 < 100 Then Disp(3) = 12
Return

'Show temperature in °C
Compile_temp:
   If Temp < 0 Then Disp(6) = 11 Else Disp(6) = 12          'Show blank or minus
   Tmp2 = Abs(temp)
   Tmp3 = Tmp2 / 100
   Incr Tmp3 : Disp(5) = Tmp3
   Tmp2 = Tmp2 Mod 100
   Tmp3 = Tmp2 / 10
   Incr Tmp3 : Disp(4) = Tmp3
   Tmp3 = Tmp2 Mod 10
   Incr Tmp3 : Disp(3) = Tmp3
   Disp(2) = 28                                            
   Disp(1) = 15                                             'C
   'Blank leading zero
   If Temp < 100 Then Disp(5) = 12
Return

Compile_minus:
   Disp(6) = 12
   Disp(5) = 11
   Disp(4) = 11                                  
   Disp(3) = 11
   Disp(2) = 11
   Disp(1) = 12                                      
Return

Compile_blank:
   Disp(6) = 12
   Disp(5) = 12
   Disp(4) = 12                                          
   Disp(3) = 12
   Disp(2) = 12
   Disp(1) = 12                                      
Return

Compile_adc_error:
   Disp(6) = 13
   Disp(5) = 16
   Disp(4) = 15                                      
   Disp(3) = 17
   Disp(2) = 25
   Disp(1) = 25                                          
Return

Show_display:
   Set Ht_clk
   Set Ht_cs
   Waitus 5
   Reset Ht_cs
   Waitus 5
   M = &HA000                                               '40960. Don't ask Smile
   Shiftout Ht_data , Ht_clk , M , 0 , 9 , P
   For N = 1 To 6
      Disp_raw = 7seg(disp(n))
      'Place the dot
'      If N = 1 Then Disp_raw = Disp_raw + 128               'this places the dot
      If N = 2 Then Disp_raw = Disp_raw + 128               'this places the dot
'      If N = 3 Then Disp_raw = Disp_raw + 128               'this places the dot
      'Show battery simbols
      If N = 4 And Bat > 0 Then Disp_raw = Disp_raw + 128   '1st battery simbol
      If N = 5 And Bat > 1 Then Disp_raw = Disp_raw + 128   '2nd battery simbol
      If N = 6 And Bat > 2 Then Disp_raw = Disp_raw + 128   '3rd battery simbol
      Shiftout Ht_data , Ht_clk , Disp_raw , 0 , 8 , P
   Next N
   Set Ht_data
   Set Ht_clk
   Waitms 3
Return

Tabela:
'POS.    1     2    3    4     5    6    7    8     9     10   11  12   13   14   15    16   17   18   19    20    21   22   23   24   25  26   27    28   29   30
   Data 125 , 96 , 62 , 122 , 99 , 91 , 95 , 112 , 127 , 123 , 2 , 0 , 119 , 79 , 29 , 110 , 31 , 23 , 93 , 103 , 108 , 13 , 70 , 55 , 6 , 15 , 109 , 51 , 78 , 71
'SYMBOL  0     1    2    3     4    5    6    7     8     9    -   _    A     b    C    d     E    F    G    H     J     L    n    P   r    t    U     °   o    h
Ht_init:
   Data &H80 , &H22 , &H90 , &H18
 
Back to top
View user's profile Visit poster's website
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Thu Apr 28, 2022 3:24 am    Post subject: Reply with quote

Very nice!

JC
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Apr 28, 2022 2:17 pm    Post subject: Reply with quote

ha, great Very Happy . Thanks for sharing your code.
Seems like a nice display. your code is clear and good to follow.
Perhaps you can include a link to the data sheet of the LCD.

_________________
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