flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [x51] Deal 8051 with HW-069

Author
Thread Post new topic Reply to topic
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
This code helps to control HW-069 module, based on TM1637 chip, with 8051 type MCU. Chip supports 6 digits and also can scan keyboard, but this code uses only four digits and has no key reading procedure as HW-069 module has only 4-digit LED display onboard.

Code:
;=======================================================================
; HW-069 module with TM1637 support. No key reading implemented.
; Procedures to fill or clear display use only first 4 addresses.
;-----------------------------------------------------------------------
TM16_DIO equ P1.0
TM16_CLK equ P1.1
;-----------------------------------------------------------------------
TM16_CMDDATA = 01000000b
TM16_FIXADDR = TM16_CMDDATA or 00000100b 
TM16_AUTOINC = TM16_CMDDATA
TM16_READKEY = TM16_CMDDATA or 00000010b
TM16_CMDADDR = 11000000b
TM16_CMDCTRL = 10000000b
TM16_PWMASK  = 00000111b
TM16_DISPON  = TM16_CMDCTRL or 00001000b
TM16_DISPOFF = TM16_CMDCTRL 
;-----------------------------------------------------------------------
LED_H = 10000000b
LED_G = 01000000b
LED_F = 00100000b
LED_E = 00010000b
LED_D = 00001000b
LED_C = 00000100b
LED_B = 00000010b
LED_A = 00000001b

DIG_0 = LED_A or LED_B or LED_C or LED_D or LED_E or LED_F
DIG_1 = LED_B or LED_C
DIG_2 = LED_A or LED_B or LED_D or LED_E or LED_G
DIG_3 = LED_A or LED_B or LED_C or LED_D or LED_G
DIG_4 = LED_B or LED_C or LED_F or LED_G
DIG_5 = LED_A or LED_C or LED_D or LED_F or LED_G
DIG_6 = LED_A or LED_C or LED_D or LED_E or LED_F or LED_G
DIG_7 = LED_A or LED_B or LED_C
DIG_8 = LED_A or LED_B or LED_C or LED_D or LED_E or LED_F or LED_G
DIG_9 = LED_A or LED_B or LED_C or LED_D or LED_F or LED_G
DIG_A = LED_A or LED_B or LED_C or LED_E or LED_F or LED_G
DIG_B = LED_C or LED_D or LED_E or LED_F or LED_G
DIG_C = LED_A or LED_D or LED_E or LED_F
DIG_D = LED_B or LED_C or LED_D or LED_E or LED_G
DIG_E = LED_A or LED_D or LED_E or LED_F or LED_G
DIG_F = LED_A or LED_E or LED_F or LED_G

DIG_M = LED_G ; MINUS

DIG_H = LED_B or LED_C or LED_E or LED_F or LED_G
DIG_L = LED_D or LED_E or LED_F

DIG_DOT = LED_H
;-----------------------------------------------------------------------
tm16_char: ; set char directly. A - addr, B - data. 
           ; call tm16_fixaddr before use: once and after tm16_fill
           ; or tm16_clear execution 
;-----------------------------------------------------------------------
    call tm16_addr
    mov  A,B
    call tm16_put
    call tm16_get_ack
    call tm16_stop
    ret
;-----------------------------------------------------------------------
tm16_clear: ; blank display. sets address autoincrement mode!
;-----------------------------------------------------------------------
    call tm16_autoinc
    mov  A,#0
    call tm16_addr
    call tm16_put
    call tm16_get_ack
    call tm16_put
    call tm16_get_ack
    call tm16_put
    call tm16_get_ack
    call tm16_put
    call tm16_get_ack
    call tm16_stop
    ret
;-----------------------------------------------------------------------
tm16_fill: ; fill display from memory. sets address autoincrement mode!
;-----------------------------------------------------------------------
    call tm16_autoinc
    mov  A,#0
    call tm16_addr
    mov  A,DISP
    call tm16_put
    call tm16_get_ack
    mov  A,DISP+1
    call tm16_put
    call tm16_get_ack
    mov  A,DISP+2
    call tm16_put
    call tm16_get_ack
    mov  A,DISP+3
    call tm16_put
    call tm16_get_ack
    call tm16_stop
    ret
;-----------------------------------------------------------------------
tm16_addr: ; send address
;-----------------------------------------------------------------------
    orl  A,#TM16_CMDADDR
    call tm16_start
    call tm16_put
    call tm16_get_ack
    ret
;-----------------------------------------------------------------------
tm16_autoinc: ; set auto address increment mode
;-----------------------------------------------------------------------
    mov  A,#TM16_AUTOINC
    jmp  tm16_cmd
;-----------------------------------------------------------------------
tm16_fixaddr: ; set fixed address mode
;-----------------------------------------------------------------------
    mov  A,#TM16_FIXADDR
    jmp  tm16_cmd
;-----------------------------------------------------------------------
tm16_off: ; turn display off
;-----------------------------------------------------------------------
    mov  A,#TM16_DISPOFF
    jmp  tm16_cmd
;-----------------------------------------------------------------------
tm16_on: ; turn display on, A: brightness value 0..7
;-----------------------------------------------------------------------
    anl  A,#TM16_PWMASK
    orl  A,#TM16_DISPON
tm16_cmd:
    call tm16_start
    call tm16_put
    call tm16_get_ack
    jmp  tm16_stop
;-----------------------------------------------------------------------
tm16_start:
    setb TM16_CLK
    call tm16_delay
    setb TM16_DIO
    call tm16_delay
    clr  TM16_DIO
    call tm16_delay
    clr  TM16_CLK
    call tm16_delay
    ret
;-----------------------------------------------------------------------
tm16_put:
    push B
    mov  B,#8
.loop:
    rrc  A
    mov  TM16_DIO,C
    call tm16_delay
    setb TM16_CLK
    call tm16_delay
    clr  TM16_CLK
    call tm16_delay
    djnz B,.loop
    pop  B
    ret    
;-----------------------------------------------------------------------
tm16_get_ack:
    setb TM16_DIO
    setb TM16_CLK
    call tm16_delay
    mov  C,TM16_DIO
    clr  TM16_CLK
    call tm16_delay
    ret
;-----------------------------------------------------------------------
tm16_stop:
    clr  TM16_DIO
    setb TM16_CLK
    call tm16_delay
    setb TM16_DIO
    call tm16_delay
    ret
;-----------------------------------------------------------------------
tm16_delay:
;    nop    ; 5 us
;    nop    ; 
;    nop    ; 4 us
;    nop    ; 
;    nop    ; 3 us
;    nop    ; 
    ret    ; 2 us (1 us + 1 us call) @ 24MHz
;=======================================================================    


Usage example:
Code:
;=======================================================================
start:
;-----------------------------------------------------------------------
    call tm16_clear
;-----------------------------------------------------------------------
    mov  A,#0
    call tm16_on
;-----------------------------------------------------------------------
    call tm16_fixaddr 
;-----------------------------------------------------------------------
    mov  A,#0
    mov  B,#DIG_1
    call tm16_char
;-----------------------------------------------------------------------
    mov  A,#1
    mov  B,#DIG_2 or DIG_DOT
    call tm16_char
;-----------------------------------------------------------------------
    mov  A,#2
    mov  B,#DIG_3
    call tm16_char
;-----------------------------------------------------------------------
    mov  A,#3
    mov  B,#DIG_4
    call tm16_char
;-----------------------------------------------------------------------
;    tm16_fill example
;-----------------------------------------------------------------------
;    mov  DISP+0,#DIG_D
;    mov  DISP+1,#DIG_A
;    mov  DISP+2,#DIG_C
;    mov  DISP+3,#DIG_B
;    call tm16_fill    
;-----------------------------------------------------------------------
mainloop:
    jmp  mainloop
;-----------------------------------------------------------------------    

_________________
UNICODE forever!
Post 30 Sep 2020, 17:59
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.