Home » Electronic News » The drive design of 51 single chip microcomputer to 602 LCD display

The drive design of 51 single chip microcomputer to 602 LCD display

Posted by: Yoyokuo 2022-08-22 Comments Off on The drive design of 51 single chip microcomputer to 602 LCD display

The drive design of 51 single chip microcomputer to 602 LCD Display

;Hardware connection: 1602LCD display 000000Hz short circuit p1.4–p3.5 then display 0000010hz

;LCD1602 shows that the test software can measure the highest frequency up to 460KHz without adding external counting hardware

;working principle:

;The number of times the input pulse is counted in 1S clock is the frequency value.

;The maximum count value of the 16-bit binary addition counter is 65535.

;Set timer 0 to work in timing mode 1, timing 1S.

;Set timer 1 to work in counting mode 1, count input pulses, and generate an interrupt on overflow.

; Define timer 1 interrupt as priority. Count the number of interrupts in the interrupt handler. After 1S arrives,

; Take out the number of interruptions and the count value in the counter for comprehensive data processing, and send the processed data to LCD1602 for display?

The drive design of 51 single chip microcomputer to 602 LCD display

;Signal source:

;1. In the software, the timing of P1.4 is reversed to form an output pulse, which can be self-tested when connected to P3.5.

; Display result: P1.4 → P3.5 Display: 000010 (Hz)

;If possible, use special equipment (signal generator and frequency meter) for correction.

; Frequency meter program

;Includes: external interrupt settings, interrupt service routines, timing routines, timing service routines

; and data processing, display, including conversion of three decimal digits to four-digit BCD codes,

;—————————————————————

BEEPBITP3.7

LCD_RSBITP2.0

LCD_RWBITP2.1

LCD_ENBITP2.2

LCD_XEQU3FH; LCD address variable

TIMER_HEQU30H; timer high byte unit

TIMER_LEQU31H; Timer low byte unit

TIMCOUNTEQU32H; number of time interrupts

INT_GEQU35H; interrupt count buffer unit high address

INT_HEQU34H; address in interrupt count buffer unit

INT_LEQU33H; interrupt count buffer unit low address

T_SEQU36H; data display low

T_MEQU37H; data display median

T_HEQU38H; data display high

T_GEQU39H; data display the highest bit

;—————————————————————

ORG0000H

JMPMAIN; Main program starts

ORG000BH

JMPTIMER_INT; timer T0 interrupt service routine

ORG001BH; Timer T1 Interrupt Service Routine

JMPTIMER1

ORG0030H

;—————————————————————

MAIN:

MOVSP, #60H; set SP pointer

LCALLPRO_SET; initialization

CALLSET_LCD

LCALLTIM_T0

;—————————————————————–

; LCD1602 is a slow display device, so 100MS display once.

;—————————————————————–

MAIN1:

MOV5, 40

MAIN2:

ACALLDELAY1;3ms

DJNZR5, MAIN2

ACALLSBIN_SBCD

CALLCONV

JMPMAIN1

;—————————————————————

;T1 counter interrupt service routine

;Count T1 counter overflow times

;—————————————————————

TIMER1:

INC2AH

RETI

;—————————————————————

;Initializer

;—————————————————————

PRO_SET:MOVA, #00H

MOVB, #00H

MOV2AH, A

MOVP0, #0FFH

MOVP1, #0FFH

MOVP2, #0FFH

MOVINT_H, #00H

MOVINT_L, #00H

MOVINT_G, #00H

MOVT_S, #00H

MOVT_H, #00H

MOVT_M, #00H

MOVT_G, #00H

MOVTIMCOUNT, #00H

MOVTIMER_H, #04CH; timing 50MS

MOVTIMER_L, #10H;

CLRBEEP

SETBP3.5; P3.5 port is set to input state

RET; T1 (the external input pin of TIMER1)

;——————————————————–

;LCD initialization settings

;——————————————————–

SET_LCD:

CLRLCD_EN

CALLINIT_LCD; initialize LCD

CALLDELAY1

MOVDPTR, #INFO1; pointer points to display information 1

MOVA, #1; is displayed on the first line

CALLLCD_SHOW

MOVDPTR, #INFO2; pointer points to display information 2

MOVA, #2; is displayed on the second line

CALLLCD_SHOW

RET

;——————————————————–

INFO1:DB “CYMOMETER”, 0; the first line of LCD displays information

INFO2:DB “FREQ:HZ”, 0; LCD second line displays information

;——————————————————–

;LCD interface initialization

;8-bit I/O control

;——————————————————–

INIT_LCD:

MOVA, #38H; double column display, font 5*7 dot matrix

CALLWCOM

CALLDELAY1

MOVA, #38H; double column display, font 5*7 dot matrix

CALLWCOM

CALLDELAY1

MOVA, #38H; double column display, font 5*7 dot matrix

CALLWCOM

CALLDELAY1

MOVA, #0CH; open the display, close the cursor,

CALLWCOM

CALLDELAY1

MOVA, #01H; clear LCD display

CALLWCOM

CALLDELAY1

RET

;——————————————————-

LCD_SHOW: ; Display information characters on the first or second line of the LCD

CJNEA, #1, LINE2; determine whether it is the first line

LINE1:MOVA, #80H; Set the first line address of LCD

CALLWCOM; write command

CALLCLR_LINE; clear this line of character data

MOVA, #80H; Set the first line address of the LCD

CALLWCOM; write command

JMPFILL

LINE2:MOVA, #0C0H; Set the second line address of LCD

CALLWCOM; write command

CALLCLR_LINE; clear this line of character data

MOVA, #0C0H; Set the address of the second line of the LCD

CALLWCOM

FILL:CLRA; fill in characters

MOVCA, @A+DPTR; extract characters from the message area

CJNEA, #0, LC1; determine whether it is an end code

RET

LC1: CALLWDATA; write data

INCDPTR; Pointer plus 1

JMPFILL; continue to fill in characters

RET

;——————————————————

CLR_LINE: ;Clear the LCD characters of this line

MOVR0, #24

CL1:MOVA, #”

CALLWDATA

DJNZR0, CL1

RET

;——————————————————–

;Write instruction, data enable subroutine

;——————————————————–

ENABLE:; write command enable

CLRLCD_RS;RS=L, LCD_RW=L, D0-D7=command code, E=high pulse

CLRLCD_RW

SETBLCD_EN

CALLDELAY0

CLRLCD_EN

RET

ENABLE1:; write data enable

SETBLCD_RS; RS=H, RW=L, D0-D7=data, E=high pulse

CLRLCD_RW

SETBLCD_EN

CALLDELAY0

CLRLCD_EN

RET

DELAY0:MOVR7, #250; delay 500 microseconds

DJNZR7, $

RET

;——————————————————-

;Write command subroutine

;——————————————————-

WCOM: ;Write command to LCD in 8-bit control mode

MOVP0, A; write command

CALLENABLE

RET

;——————————————————-

;Write data subroutine

;——————————————————-

WDATA: ;Write data to LCD in 8-bit control mode

MOVP0, A; write data

CALLENABLE1

RET

;——————————————————

;Display characters on the second line of the LCD

;A=ASCDATA,B=LINEXPOS

;——————————————————

LCDP2: ; Display characters on the second line of the LCD

PUSHACC;

MOVA, B; set display address

ADDA, #0C0H; set the second line address of LCD

CALLWCOM; write command

POPACC; remove A from the stack

CALLWDATA; write data

RET

;—————————————————————-

;ASCII convert and display numeric subroutine on second line

;—————————————————————-

CONV: ;MOVA, T_G

MOVLCD_X, #6; set position

;CALLSHOW_DIG2

MOVA, T_H

;INCLCD_X;Load hour data

CALLSHOW_DIG2; display data

MOVA, T_M; load minute data

INCLCD_X; set position

CALLSHOW_DIG2; display data

MOVA, T_S; load seconds data

INCLCD_X; set position

CALLSHOW_DIG2; display data

RET

;——————————————————-

SHOW_DIG2:

MOVB, #16

DIVAB

ADDA, #30H

PUSHB

MOVB, LCD_X

CALLLCDP2

POPB

MOVA, B

ADDA, #30H

INCLCD_X

MOVB, LCD_X

CALLLCDP2

RET

;——————————————————–

DELAY1:; delay 3MS

MOVR6, #15

D2:MOVR7, #100

DJNZR7, $

DJNZR6, D2

RET

;——–timer settings ————————

;Set timer 0 to work in timing mode 1, and timer 1 to work in counting mode 1

;—————————————————————

TIM_T0:MOVTMOD, #0D1H

MOVTH0, TIMER_H; set the high bit of the timing initial value

MOVTL0, TIMER_L; set the low bit of the timing initial value

MOVTH1, #00H; clear T1 counter

MOVTL1, #00H

MOVIE, #8AH; open interrupt always allow, allow T0 overflow interrupt

SETBPT1

SETBTR1

SETBTR0; timer starts working

RET

;—————————————————————

; Timer 0 Interrupt Service Routine

;—————————————————————

TIMER_INT:

CLRTR0; close the timer

MOVTL0, TIMER_L; reassign initial value

MOVTH0, TIMER_H;

INCTIMCOUNT; timing 1S, time unit

MOVA, TIMCOUNT; view quantity value

CPLP1.4; generate self-test signal

CJNEA, #20, T_END; if not return to 1S

CLRTR1; close counter T1

MOVTIMCOUNT, #00H; clear to 1S

MOVINT_L, TL1; take out the low bit of the count value

MOVINT_H, TH1; take out the high bit of the count value

MOVINT_G, 2AH; take out the overflow count value bit

MOVTH1, #00H

MOVTL1, #00H

MOV2AH, #00H

SETBTR1

T_END:SETBTR0;Restart timing operation

RETI

;—————————————————————

;Convert three-byte binary integer to four-byte BCD code subroutine

;Binary numbers are stored in INT_L, INT_H, INT_G units from low to high

;BCD code is stored in T_S, T_M, T_H, T_G units from low to high

;—————————————————————

SBIN_SBCD:

PUSHPSW

SETBPSW.3; set the current register

CLRPSW.4

CLRA; clear accumulator

MOVT_G, A

MOVT_H, A; clear exit unit, ready for conversion

MOVT_M, A

MOVT_S, A

MOVR5, INT_G

MOVR7, INT_L; set the starting address of the binary number

MOVR6, INT_H

MOVR2, #24

CLRC

HH1:

MOVA, R7

RLCA

MOVR7, A

MOVA, R6

RLCA

MOVR6, A

MOVA, R5

RLCA

MOVR5, A

MOVA, T_S; get low data

ADDCA, T_S; Accumulate

DAA; Decimal Adjustment

MOVT_S, A; save data

MOVA, T_M; get the second bit of data

ADDCA, T_M; Accumulate

DAA; Decimal Adjustment

MOVT_M, A; save the result

MOVA, T_H; get third place

ADDCA, T_H; Accumulate

DAA

MOVT_H, A; save

MOVA, T_G; get fourth

ADDCA, T_G; Accumulate

;DAA

MOVT_G, A

DJNZR2, HH1;

POPPSW

RET

;—————————————————————-

END; tells the compiler that this program ends here.

The Links:   G150X1-L01 MG25Q6ES43