; Program Name HT1621.asm ; microcontroller 48R10A-1 ; version 1.01 ; Date 4/15/2003 ; Author Holtek USA FAE ; Fsys 2MHz ; Options BZ and /BZ Disabled ; WDT disabled ; PB pull high ; ; Configuration HT1621 is configured as 4 commons and 32 segments. ; PB0 -- DATA pin of HT1621 ; PB1 -- /WR pin of HT1621 ; PB2 -- /RD pin of HT1621 ; PB3 -- /CS pin of HT1621 #INCLUDE HT48R10A-1.INC #include S700.mac ;---------------------------- HT1621_CS equ PB.3 HT1621_RD equ PB.2 HT1621_WR equ PB.1 HT1621_Data equ PB.0 Set_H macro Port set port endm Set_L macro Port clr port endm DATA .SECTION 'DATA' address db ? data db ? ;---------------------------- CODE .SECTION 'CODE' ORG 00H ; Holtek MCU's start point JMP START ORG 04H ; Holtek MCU's INT ISR (Interrupt Service Routine) reti ORG 08H ; Holtek MCU's Tmr ISR reti START: CLR PBC ; set PB as output mode SET PB ; all PB ports are hight ;***************************************************** ; Output "SYS EN" cmd (100 0000-0001 X) ;***************************************************** Set_L HT1621_CS ; /CS = Low call dly mov A,4h ; ID = 4 call Output_ID mov A,1h ; cmd = 1: Sys EN call Output_Cmd call Output_x ; the 9'th bit set_H HT1621_CS ;***************************************************** ; Output "LCD ON" cmd (100 0000-0011 X) ;***************************************************** Set_L HT1621_CS ; /CS = Low call dly mov A,4h ; ID = 4 call Output_ID mov A,3h ; cmd = 3: LCD on call output_cmd call Output_x ; x call dly set_H HT1621_CS ;***************************************************** ; Output 4 com, 1/2 bias ;***************************************************** Set_L HT1621_CS ; /CS = Low call dly mov A,4h ; ID = 4 call Output_ID mov A,00101011b ; 0010-abcd call Output_Cmd ; ab = 10: 4 com ; c = don't care ; d = 0: 1/2 bias, 1: 1/3 bias call Output_x ; x call dly set_H HT1621_CS ; Now you can see LCD waveforms on Coms and Segs ;**************************************************** ; write address 0x05 data 0x06 ;************************************************** Set_L HT1621_CS ; /CS = Low call dly mov A,5h ; write call Output_ID mov A,5 ; address = 5 mov Address,A call Output_Addr mov A,0110b ; data = 6 mov Data,A call output_data call dly set_H HT1621_CS ;**************************************************** ; read data from address 0x05 ;************************************************** Set_L HT1621_CS ; /CS = Low call dly mov A,110b ; read call Output_ID mov A,address ; Acc = adress call output_addr set PBC.0 ; **** SET PB.0 AS INPUT *** call Input_A_nibble ; Data bit 0 xor A,Data ; compare data skp_Z ; equal ? jmp Error Correct: jmp $ ; Error: jmp $ ; ;**************************************************** ; delay ;************************************************** dly Proc ; delay subroutine nop nop nop nop nop nop nop nop nop nop nop ret dly endp ;**************************************************** ; Output bit 7 of Acc to data ;************************************************** Output_x Proc RLC Acc Set_L HT1621_WR sz C ; jmp Output_C_1 Output_C_0: set_L HT1621_DATA ; data bit = 0 jmp Output_C_OK Output_C_1: set_H HT1621_DATA ; data bit = 1 Output_C_OK: call dly SET_H HT1621_WR call dly ret Output_x endp ;**************************************************** ; Input a bit from data bus ;************************************************** Input_a_bit Proc Set_L HT1621_RD call dly clr C SET_H HT1621_RD sz HT1621_data set C call dly ret Input_a_bit endp ;**************************************************** ; Input 4 bit in a row ( a nibble ) data bus ; input: x ; output: A ;************************************************** Input_a_nibble Proc call input_a_bit RRC Acc call input_a_bit RRC Acc call input_a_bit RRC Acc call input_a_bit RRC Acc swap Acc ret Input_a_nibble endp ;**************************************************** ; input: A = xxxx xIII, where III = ID ; output: ;************************************************** Output_ID proc swap Acc ; move low nibble to high nibble RLC Acc ; discard bit 3 call Output_x call Output_x call Output_x ret Output_ID endp ;**************************************************** ; input: A = CCCC CCCC, where CCC CCCC = command ; output: ;************************************************** Output_Cmd proc call Output_x call Output_x call Output_x call Output_x call Output_x call Output_x call Output_x call Output_x ret Output_Cmd endp ;**************************************************** ; input: A = xxAA AAAA, where AA AAAA = address ; output: ;************************************************** Output_Addr proc RLC Acc ; discard bit 7 RLC Acc ; discard bit 6 call Output_x call Output_x call Output_x call Output_x call Output_x call Output_x ret Output_Addr endp ;**************************************************** ; input: A = xxxx DDDD, where DDDD = address ; output: ;************************************************** Output_Data proc swap ACC call Output_x call Output_x call Output_x call Output_x ret Output_Data endp