;***************************************************************************************** .equ LCD_RS_COMMAND = 0 .equ LCD_RS_DATA = 1 .equ LCD_CLEAR = 0b00000001 ;display clear .equ LCD_HOME = 0b00000010 ;return home .equ LCD_HOME2 = 0b11000000 ;set DD ram adress 0x40 .equ LCD_ENTRY = 0b00000100 .equ LCD_ENTRY_INC = 0b00000010 .equ LCD_ENTRY_DEC = 0b00000000 .equ LCD_ENTRY_SHIFT = 0b00000001 .equ LCD_ENTRY_NOSHIFT = 0b00000000 .equ LCD_DISP = 0b00001000 .equ LCD_DISP_OFF = 0b00000000 .equ LCD_DISP_ON = 0b00000100 .equ LCD_DISP_NOCURSOR = 0b00000000 .equ LCD_DISP_CURSOR = 0b00000010 .equ LCD_DISP_NOBLINK = 0b00000000 .equ LCD_DISP_BLINK = 0b00000001 .equ LCD_SET = 0b00100000 .equ LCD_SET_4BIT = 0b00000000 .equ LCD_SET_8BIT = 0b00010000 .equ LCD_SET_1LINE = 0b00000000 .equ LCD_SET_2LINE = 0b00001000 .equ LCD_SET_FONT7 = 0b00000000 .equ LCD_SET_FONT10 = 0b00000100 ;***************************************************************************************** .DSEG hbx_keys: .byte 1 ;***************************************************************************************** .CSEG hbx_label_tab: .dw hbx_test_init .db L_CMD ,"HBXI " .dw hbx_test_verify .db L_CMD ,"HBXV " .dw hbx_test_write_data .db L_CMD ,"HBXD " .dw hbx_test_write_command .db L_CMD ,"HBXC " .dw hbx_test_read .db L_CMD ,"HBXR " .dw hbx .db L_CMD ,"HBX " .dw hbx_read .db L_CMD ,"HBXREAD " .dw hbx_test .db L_CMD ,"HBXTEST " .dw 0 .db L_END , 0 ;**************************************************************************************** ; hbx_test_init: rcall hbx_init_lcd ret ;**************************************************************************************** ; hbx_test_verify: call next_int_value brtc hbx_tve_exit mov r16 ,AKKU_5 call printf_byte_hex mov r16 ,AKKU_6 call printf_byte_hex mov r16 ,AKKU_7 call printf_byte_hex mov r16 ,AKKU_8 call printf_byte_hex hbx_tve_loop: mov r16 ,AKKU_8 rcall hbx_write_port ldi r17 ,100 hbx_tve_wait: nop nop nop nop nop nop nop nop dec r17 brne hbx_tve_wait rcall hbx_read_port cp r16 ,AKKU_8 breq hbx_tve_ok push r16 mov r16 ,AKKU_8 call printf_byte_binary PUTC 13 pop r16 call printf_byte_binary PUTC 13 PUTC 13 rjmp hbx_tve_not_ok hbx_tve_ok: PUTC '.' hbx_tve_not_ok: sec sbc AKKU_8 ,r17 sbc AKKU_7 ,r17 sbc AKKU_6 ,r17 sbc AKKU_5 ,r17 brcc hbx_tve_loop hbx_tve_exit: ret ;**************************************************************************************** ; hbx_test_write_command: call next_int_value brtc hbx_twc_exit mov r16 ,AKKU_8 rcall hbx_write_command hbx_twc_exit: ret ;**************************************************************************************** ; hbx_test_write_data: call next_int_value brtc hbx_twd_exit mov r16 ,AKKU_8 rcall hbx_write_data hbx_twd_exit: ret ;**************************************************************************************** ; hbx_test_read: rcall hbx_init_port rcall hbx_read_port push r16 putc '0' putc 'x' pop r16 push r16 call printf_byte_hex putc ' ' putc 'b' pop r16 call printf_byte_binary putc 13 ret ;***************************************************************************************** ;set data direction register of LCD port hbx_init_port: sbi LCD_DDR ,LCD_PIN_RS_DS cbi LCD_PORT ,LCD_PIN_RW_CLK sbi LCD_DDR ,LCD_PIN_RW_CLK cbi LCD_PORT ,LCD_PIN_E_STCP sbi LCD_DDR ,LCD_PIN_E_STCP sbi LCD_DDR ,LCD_PIN_LOAD cbi LCD_DDR ,LCD_PIN_INPUT ret ;***************************************************************************************** ;init sequence for HD44780 controller ; hbx_init_lcd: ldi r16 ,100 call util_delay_ms ldi r16 ,0b00110000 ;ldi r17 ,LCD_RS_COMMAND rcall hbx_write_command ldi r16 ,100 ;minimum 4.1 ms call util_delay_ms ldi r16 ,0b00110000 ;ldi r17 ,LCD_RS_COMMAND rcall hbx_write_command ldi r16 ,100 ;minimum 0.1 ms call util_delay_ms ldi r16 ,0b00110000 ;ldi r17 ,LCD_RS_COMMAND rcall hbx_write_command ldi r16 ,100 ;??? call util_delay_ms PUTC '1' ldi r16 ,LCD_SET + LCD_SET_8BIT + LCD_SET_2LINE + LCD_SET_FONT7 ;ldi r17 ,LCD_RS_COMMAND rcall hbx_write_command ldi r16 ,100 ;minimum 0.1 ms call util_delay_ms PUTC '2' ldi r16 ,LCD_DISP + LCD_DISP_ON + LCD_DISP_NOCURSOR + LCD_DISP_NOBLINK rcall hbx_write_command ldi r16 ,100 ;minimum 0.1 ms call util_delay_ms PUTC '3' ldi r16 ,LCD_CLEAR rcall hbx_write_command ldi r16 ,100 ;minimum 0.1 ms call util_delay_ms PUTC '4' ldi r16 ,LCD_ENTRY + LCD_ENTRY_INC + LCD_ENTRY_NOSHIFT rcall hbx_write_command ldi r16 ,100 ;minimum 0.1 ms call util_delay_ms PUTC '!' PUTC 13 ret ;***************************************************************************************** ;read buttons ; hbx_read_keys: rcall hbx_read_port sts hbx_keys ,r16 ret ;***************************************************************************************** ;read byte from 166 shift register ; ;r16 byte hbx_read_port: push r17 in r1 ,SREG ;save interrupt enable flag cli ;disable interrupts sbi LCD_DDR ,LCD_PIN_LOAD sbi LCD_DDR ,LCD_PIN_RW_CLK cbi LCD_DDR ,LCD_PIN_INPUT nop nop nop nop nop nop nop nop cbi LCD_PORT ,LCD_PIN_LOAD cbi LCD_PORT ,LCD_PIN_RW_CLK nop nop nop nop nop nop nop nop ldi r17 ,8 ;8 bits to load hbx_rdp_loop: sbi LCD_PORT ,LCD_PIN_RW_CLK ;Clock = 1 nop nop nop nop nop nop nop nop cbi LCD_PORT ,LCD_PIN_RW_CLK ;Clock = 0 nop nop nop nop nop nop nop nop sbi LCD_PORT ,LCD_PIN_LOAD lsl r16 sbic LCD_PINS ,LCD_PIN_INPUT ori r16 ,1 dec r17 ;all bits shifted ? brne hbx_rdp_loop sbrc r1 ,7 ;restore interrupt enable flag sei pop r17 ret ;***************************************************************************************** ;write command/data byte into LCD ; ;r16 byte hbx_write_command: ldi r17 ,LCD_RS_COMMAND rjmp hbx_write_port hbx_write_data: ldi r17 ,LCD_RS_DATA hbx_write_port: push r16 push r17 push r18 in r1 ,SREG ;save interrupt enable flag cli ;disable interrupts cbi LCD_PORT ,LCD_PIN_E_STCP cbi LCD_PORT ,LCD_PIN_RS_DS cbi LCD_PORT ,LCD_PIN_RW_CLK sbi LCD_DDR ,LCD_PIN_E_STCP sbi LCD_DDR ,LCD_PIN_RS_DS sbi LCD_DDR ,LCD_PIN_RW_CLK ldi r18 ,8 ;8 bits to shift hbx_wrp_loop: sbrc r16 ,7 ;highest bit set ? sbi LCD_PORT ,LCD_PIN_RS_DS ;yes, output bit = 1 sbrs r16 ,7 ;highest bit not set ? cbi LCD_PORT ,LCD_PIN_RS_DS ;yes, output bit = 0 nop nop nop nop nop nop nop nop sbi LCD_PORT ,LCD_PIN_RW_CLK ;CLOCK HIGH nop nop nop nop nop nop nop nop cbi LCD_PORT ,LCD_PIN_RW_CLK ;CLOCK LOW lsl r16 dec r18 ;all bits shifted ? brne hbx_wrp_loop ;no sbrc r17 ,0 ;RS = 1 (skip if 0) ? sbi LCD_PORT ,LCD_PIN_RS_DS ;yes sbrs r17 ,0 ;RS = 0 (skip if 1) ? cbi LCD_PORT ,LCD_PIN_RS_DS ;yes sbi LCD_PORT ,LCD_PIN_E_STCP ;ENABLE ON nop nop nop nop nop nop nop nop cbi LCD_PORT ,LCD_PIN_E_STCP ;ENABLE OFF sbrc r1 ,7 ;restore interrupt enable flag sei pop r18 pop r17 pop r16 ret ;***************************************************************************************** .CSEG hbx: rcall hbx_init PUTC 'H' ldi r16 ,LCD_HOME rcall hbx_write_command PUTC 'T' ldi r16 ,'H' rcall hbx_write_data ldi r16 ,'a' rcall hbx_write_data ldi r16 ,'l' rcall hbx_write_data ldi r16 ,'l' rcall hbx_write_data ldi r16 ,'o' rcall hbx_write_data ldi r16 ,'!' rcall hbx_write_data ldi r16 ,250 call util_delay_ms PUTC 'C' ldi r16 ,LCD_CLEAR rcall hbx_write_command putc '0' putc 'x' lds r16 ,hbx_keys rcall printf_byte_hex putc ' ' putc 'b' lds r16 ,hbx_keys rcall printf_byte_binary putc 13 set ret ;***************************************************************************************** .CSEG hbx_read: ;rcall hbx_init hbx_read_loop: call hbx_read_port PUTC '0' PUTC 'b' lds r16 ,hbx_keys rcall printf_byte_binary putc 13 call getc_check ;character from serial connection ? brtc hbx_read_loop set ret ;***************************************************************************************** .CSEG hbx_test: cli rcall hbx_init hbx_test_loop: lds r16 ,hbx_keys rcall hbx_write_byte call getc_check ;character from serial connection ? brtc hbx_test_loop ;***************************************************************************************** ;init sequence for HD44780 controller ; hbx_init: ldi r16 ,200 call util_delay_ms clr r16 out LCD_PORT ,r16 ldi r16 ,(1<