mình ko bít làm lưu đồ giải thuật , chỉ còn 12h nữa giao đồ án rồi các bạn giúp dùm mình với .
Mạch này đếm sản phẩm UP + Down hiện thị LCD , cảm biếm đo nhiệt độ môi trường hiện thị LCD . LCD = dòng 1 hiện thị chữ TRUONG CAO DANG KY THUAT CAO THANG - MẠCH DEM SAN PHAM , dòng 2 ( bên trái hiện thị giá trị đếm sản phẩm , bên phải hiện thị nhiệt độ )
chương trình :
;CHUONG TRINH DEM SAN PHAM HIEN THI TREN LCD
;************************************************* *
;KHAI BAO BIEN
RS BIT P0.0
RW BIT P0.1
EN BIT P0.2
DATABUS EQU P2
UP BIT P1.0
DOWN BIT P1.1
WR_ADC BIT P1.7
ORG 0000H
MOV 30H,#' '
MOV 31H,#' '
MOV 32H,#' '
MOV 33H,#' '
MOV 34H,#' '
MOV 35H,#' '
MOV 36H,#' '
MOV 37H,#' '
MOV 38H,#' '
MOV 39H,#' '
MOV 3AH,#' '
MOV 3BH,#' '
MOV 3CH,#' '
MOV 3DH,#' '
MOV 3EH,#' '
MOV 3FH,#' '
MOV 40H,#'T'
MOV 41H,#'R'
MOV 42H,#'U'
MOV 43H,#'O'
MOV 44H,#'N'
MOV 45H,#'G'
MOV 46H,#' '
MOV 47H,#'C'
MOV 48H,#'A'
MOV 49H,#'O'
MOV 4AH,#' '
MOV 4BH,#'D'
MOV 4CH,#'A'
MOV 4DH,#'N'
MOV 4EH,#'G'
MOV 4FH,#' '
MOV 50H,#'K'
MOV 51H,#'Y'
MOV 52H,#' '
MOV 53H,#'T'
MOV 54H,#'H'
MOV 55H,#'U'
MOV 56H,#'A'
MOV 57H,#'T'
MOV 58H,#' '
MOV 59H,#'C'
MOV 5AH,#'A'
MOV 5BH,#'O'
MOV 5CH,#' '
MOV 5DH,#'T'
MOV 5EH,#'H'
MOV 5FH,#'A'
MOV 60H,#'N'
MOV 61H,#'G'
MOV 62H,#' '
MOV 63H,#' '
MOV 64H,#' '
MOV 65H,#' '
MOV 66H,#' '
MOV 67H,#' '
MOV 68H,#' '
MOV 69H,#' '
MOV 6AH,#' '
MOV 6BH,#' '
MOV 6CH,#' '
MOV 6DH,#' '
MOV 6EH,#'M'
MOV 6FH,#'A'
MOV 70H,#'C'
MOV 71H,#'H'
MOV 72H,#' '
MOV 73H,#'D'
MOV 74H,#'E'
MOV 75H,#'M'
MOV 76H,#' '
MOV 77H,#'S'
MOV 78H,#'A'
MOV 79H,#'N'
MOV 7AH,#' '
MOV 7BH,#'P'
MOV 7CH,#'H'
MOV 7DH,#'A'
MOV 7EH,#'M'
MOV 7FH,#' '
;***************************************
MOV 10H,#0H
MOV 11H,#0H
MOV 12H,#0H
MOV 13H,#0H
MOV 14H,#0H
MOV 15H,#0H
MOV 16H,#0H
MOV 17H,#0H
MOV 18H,#0H
MOV 19H,#0H
CALL BCD_LCD
;**********************************
MAIN:
CALL HIENTHI
CALL DOC_ADC
CALL TEXT_UP
CALL TEXT_DOWN
JMP MAIN
;**********************************
TEXT_UP: JNB UP,HOME ;KIEM TRA CHAN P1.0 NEU CO VAT CHAN THI =1
AGAIN : JNB UP,NEXT ;LAP TAI DAY NEU CHAN P1.0 CON =1 (CON VAT CHAN)
JMP AGAIN
HOME : RET
NEXT :
MOV R4,10H ;CHUYEN GIA TRI CUA 10H VAO R4
INC R4 ;TANG R4 MOT DON VI
MOV 10H,R4 ;NAP GIA TRI VUA TANG VAO 10H
CJNE R4,#0AH,BCD_LCD ;SO SANH NEU R4<>OAH THI NHAY
MOV 10H,#0H ;XOA 10H =0
MOV R4,11H
INC R4
MOV 11H,R4
CJNE R4,#0AH,BCD_LCD
MOV 10H,#0H
MOV 11H,#0H
MOV R4,12H
INC R4
MOV 12H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET1
MOV R4,13H
INC R4
MOV 13H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET2
MOV R4,14H
INC R4
MOV 14H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET3
MOV R4,15H
INC R4
MOV 15H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET4
JMP BCD_LCD
RET
;************************************************* ****************************
BCD_LCD:
MOV DPTR,#500H
MOV R0,#10H
MOV R1,#20H
LOOP:
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
CJNE R0,#16H,LOOP
RET
;************************************************* *****************
TEXT_DOWN: JNB DOWN,HOME1 ;KIEM TRA CHAN P1.1 NEU CO VAT CHAN THI =1
AGAIN1 : JNB DOWN,NEXT1 ;LAP TAI DAY NEU CHAN P1.1 CON =1 (CON VAT CHAN)
JMP AGAIN1
HOME1 : RET
NEXT1 : MOV R4,15H ;KIEM TRA NEU SP=000000 THI K0 GIAM
CJNE R4,#00H,GIAM
MOV R4,14H
CJNE R4,#00H,GIAM
MOV R4,13H
CJNE R4,#00H,GIAM
MOV R4,12H
CJNE R4,#00H,GIAM
MOV R4,11H
CJNE R4,#00H,GIAM
MOV R4,10H
CJNE R4,#00H,GIAM
JMP HERE6
GIAM:
MOV R4,10H ;CHUYEN GIA TRI CUA 10H VAO R4
CJNE R4,#00H,NEXT_1
MOV 10H,#09H
JMP HERE1
NEXT_1:
DEC R4 ;GIAM R4 MOT DON VI
MOV 10H,R4 ;NAP GIA TRI VUA TANG VAO 10H
JMP BCD_LCD
HERE1 :
MOV R4,11H
CJNE R4,#00H,NEXT_2
MOV 11H,#09H
JMP HERE2
NEXT_2:
DEC R4
MOV 11H,R4
JMP BCD_LCD
HERE2 :
MOV R4,12H
CJNE R4,#00H,NEXT_3
MOV 12H,#09H
JMP HERE3
NEXT_3:
DEC R4
MOV 12H,R4
JMP BCD_LCD
HERE3 :
MOV R4,13H
CJNE R4,#00H,NEXT_4
MOV 13H,#09H
JMP HERE4
NEXT_4:
DEC R4
MOV 13H,R4
JMP BCD_LCD
HERE4 :
MOV R4,14H
CJNE R4,#00H,NEXT_5
MOV 14H,#09H
JMP HERE5
NEXT_5:
DEC R4
MOV 14H,R4
JMP BCD_LCD
HERE5 :
MOV R4,15H
CJNE R4,#00H,NEXT_6
MOV 15H,#09H
JMP HERE6
NEXT_6:
DEC R4
MOV 15H,R4
JMP BCD_LCD
HERE6 :
JMP BCD_LCD
RET
;************************************************* ***************
BCD_LCD_1: JMP BCD_LCD
;************************************************* ****************
SET4: MOV 15H,#0H
SET3: MOV 14H,#0H
SET2: MOV 13H,#0H
SET1: MOV 12H,#0H
MOV 11H,#0H
MOV 10H,#0H
RET
;************************************************* ***************
DOC_ADC:
MOV DPTR,#500H
SETB WR_ADC
CALL DELAY
CLR WR_ADC
MOV A,P3
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV 2AH,A
MOV A,B
MOVC A,@A+DPTR
MOV 2BH,A
RET
;************************************************* *********************
HIENTHI : MOV R2,#80
MOV TMOD,#01H
CALL INIT_LCD
CALL CLEAR_LCD
LAP : CALL PRESENT
CALL DELAY
CALL TEXT_UP
CALL TEXT_DOWN
DJNZ R2,LAP
CALL DICH
RET
;************************************************
DICH : MOV R2,30H
MOV R0,#30H
MOV R1,#31H
DICH_TIEP : MOV A,@R1
MOV @R0,A
INC R0
INC R1
CJNE R0,#7FH,DICH_TIEP
MOV 7FH,R2
RET
;******************************************
INIT_LCD : MOV R3,#04
SETUP : SETB EN
CLR RS
MOV DATABUS,#38H
CLR EN
LCALL WAIT_LCD
DJNZ R3,SETUP
SETB EN
CLR RS
MOV DATABUS,#0EH
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATABUS,#06H
CLR EN
LCALL WAIT_LCD
LCALL CLEAR_LCD
RET
;************************************************
CLEAR_LCD : SETB EN
CLR RS
MOV DATABUS,#02H
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATABUS,#01H
CLR EN
LCALL WAIT_LCD
RET
;***********************************************
WRITE_TEXT : SETB EN
SETB RS
MOV DATABUS,A
CLR EN
LCALL WAIT_LCD
RET
;***********************************************
DELAY :
MOV TH0,#HIGH(-5000)
MOV TL0,#LOW (-5000)
SETB TR0
JNB TF0,$
CLR TF0
CLR TR0
RET
;************************************************
WAIT_LCD : SETB EN
CLR RS
SETB RW
MOV DATABUS,#0FFH
MOV A,DATABUS
JB ACC.7,WAIT_LCD
CLR EN
CLR RW
RET
;************************************************
PRESENT : MOV A,30H
LCALL WRITE_TEXT
MOV A,31H
LCALL WRITE_TEXT
MOV A,32H
LCALL WRITE_TEXT
MOV A,33H
LCALL WRITE_TEXT
MOV A,34H
LCALL WRITE_TEXT
MOV A,35H
LCALL WRITE_TEXT
MOV A,36H
LCALL WRITE_TEXT
MOV A,37H
LCALL WRITE_TEXT
MOV A,38H
LCALL WRITE_TEXT
MOV A,39H
LCALL WRITE_TEXT
MOV A,3AH
LCALL WRITE_TEXT
MOV A,3BH
LCALL WRITE_TEXT
MOV A,3CH
LCALL WRITE_TEXT
MOV A,3DH
LCALL WRITE_TEXT
MOV A,3EH
LCALL WRITE_TEXT
MOV A,3FH
LCALL WRITE_TEXT
;************************
;LENH XUONG DONG 2 CUA LCD
SETB EN
CLR RS
MOV DATABUS,#0C0H
CLR EN
LCALL WAIT_LCD
;***********************
MOV A,#'S'
LCALL WRITE_TEXT
MOV A,#'P'
LCALL WRITE_TEXT
MOV A,#':'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,25H
LCALL WRITE_TEXT
MOV A,24H
LCALL WRITE_TEXT
MOV A,23H
LCALL WRITE_TEXT
MOV A,22H
LCALL WRITE_TEXT
MOV A,21H
LCALL WRITE_TEXT
MOV A,20H
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,2AH
LCALL WRITE_TEXT
MOV A,2BH
LCALL WRITE_TEXT
MOV A,#'*'
LCALL WRITE_TEXT
MOV A,#'C'
LCALL WRITE_TEXT
RET
;*********************************************
ORG 500H
DB '0','1','2','3','4','5','6','7','8','9'
END
Mạch này đếm sản phẩm UP + Down hiện thị LCD , cảm biếm đo nhiệt độ môi trường hiện thị LCD . LCD = dòng 1 hiện thị chữ TRUONG CAO DANG KY THUAT CAO THANG - MẠCH DEM SAN PHAM , dòng 2 ( bên trái hiện thị giá trị đếm sản phẩm , bên phải hiện thị nhiệt độ )
chương trình :
;CHUONG TRINH DEM SAN PHAM HIEN THI TREN LCD
;************************************************* *
;KHAI BAO BIEN
RS BIT P0.0
RW BIT P0.1
EN BIT P0.2
DATABUS EQU P2
UP BIT P1.0
DOWN BIT P1.1
WR_ADC BIT P1.7
ORG 0000H
MOV 30H,#' '
MOV 31H,#' '
MOV 32H,#' '
MOV 33H,#' '
MOV 34H,#' '
MOV 35H,#' '
MOV 36H,#' '
MOV 37H,#' '
MOV 38H,#' '
MOV 39H,#' '
MOV 3AH,#' '
MOV 3BH,#' '
MOV 3CH,#' '
MOV 3DH,#' '
MOV 3EH,#' '
MOV 3FH,#' '
MOV 40H,#'T'
MOV 41H,#'R'
MOV 42H,#'U'
MOV 43H,#'O'
MOV 44H,#'N'
MOV 45H,#'G'
MOV 46H,#' '
MOV 47H,#'C'
MOV 48H,#'A'
MOV 49H,#'O'
MOV 4AH,#' '
MOV 4BH,#'D'
MOV 4CH,#'A'
MOV 4DH,#'N'
MOV 4EH,#'G'
MOV 4FH,#' '
MOV 50H,#'K'
MOV 51H,#'Y'
MOV 52H,#' '
MOV 53H,#'T'
MOV 54H,#'H'
MOV 55H,#'U'
MOV 56H,#'A'
MOV 57H,#'T'
MOV 58H,#' '
MOV 59H,#'C'
MOV 5AH,#'A'
MOV 5BH,#'O'
MOV 5CH,#' '
MOV 5DH,#'T'
MOV 5EH,#'H'
MOV 5FH,#'A'
MOV 60H,#'N'
MOV 61H,#'G'
MOV 62H,#' '
MOV 63H,#' '
MOV 64H,#' '
MOV 65H,#' '
MOV 66H,#' '
MOV 67H,#' '
MOV 68H,#' '
MOV 69H,#' '
MOV 6AH,#' '
MOV 6BH,#' '
MOV 6CH,#' '
MOV 6DH,#' '
MOV 6EH,#'M'
MOV 6FH,#'A'
MOV 70H,#'C'
MOV 71H,#'H'
MOV 72H,#' '
MOV 73H,#'D'
MOV 74H,#'E'
MOV 75H,#'M'
MOV 76H,#' '
MOV 77H,#'S'
MOV 78H,#'A'
MOV 79H,#'N'
MOV 7AH,#' '
MOV 7BH,#'P'
MOV 7CH,#'H'
MOV 7DH,#'A'
MOV 7EH,#'M'
MOV 7FH,#' '
;***************************************
MOV 10H,#0H
MOV 11H,#0H
MOV 12H,#0H
MOV 13H,#0H
MOV 14H,#0H
MOV 15H,#0H
MOV 16H,#0H
MOV 17H,#0H
MOV 18H,#0H
MOV 19H,#0H
CALL BCD_LCD
;**********************************
MAIN:
CALL HIENTHI
CALL DOC_ADC
CALL TEXT_UP
CALL TEXT_DOWN
JMP MAIN
;**********************************
TEXT_UP: JNB UP,HOME ;KIEM TRA CHAN P1.0 NEU CO VAT CHAN THI =1
AGAIN : JNB UP,NEXT ;LAP TAI DAY NEU CHAN P1.0 CON =1 (CON VAT CHAN)
JMP AGAIN
HOME : RET
NEXT :
MOV R4,10H ;CHUYEN GIA TRI CUA 10H VAO R4
INC R4 ;TANG R4 MOT DON VI
MOV 10H,R4 ;NAP GIA TRI VUA TANG VAO 10H
CJNE R4,#0AH,BCD_LCD ;SO SANH NEU R4<>OAH THI NHAY
MOV 10H,#0H ;XOA 10H =0
MOV R4,11H
INC R4
MOV 11H,R4
CJNE R4,#0AH,BCD_LCD
MOV 10H,#0H
MOV 11H,#0H
MOV R4,12H
INC R4
MOV 12H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET1
MOV R4,13H
INC R4
MOV 13H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET2
MOV R4,14H
INC R4
MOV 14H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET3
MOV R4,15H
INC R4
MOV 15H,R4
CJNE R4,#0AH,BCD_LCD
CALL SET4
JMP BCD_LCD
RET
;************************************************* ****************************
BCD_LCD:
MOV DPTR,#500H
MOV R0,#10H
MOV R1,#20H
LOOP:
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
CJNE R0,#16H,LOOP
RET
;************************************************* *****************
TEXT_DOWN: JNB DOWN,HOME1 ;KIEM TRA CHAN P1.1 NEU CO VAT CHAN THI =1
AGAIN1 : JNB DOWN,NEXT1 ;LAP TAI DAY NEU CHAN P1.1 CON =1 (CON VAT CHAN)
JMP AGAIN1
HOME1 : RET
NEXT1 : MOV R4,15H ;KIEM TRA NEU SP=000000 THI K0 GIAM
CJNE R4,#00H,GIAM
MOV R4,14H
CJNE R4,#00H,GIAM
MOV R4,13H
CJNE R4,#00H,GIAM
MOV R4,12H
CJNE R4,#00H,GIAM
MOV R4,11H
CJNE R4,#00H,GIAM
MOV R4,10H
CJNE R4,#00H,GIAM
JMP HERE6
GIAM:
MOV R4,10H ;CHUYEN GIA TRI CUA 10H VAO R4
CJNE R4,#00H,NEXT_1
MOV 10H,#09H
JMP HERE1
NEXT_1:
DEC R4 ;GIAM R4 MOT DON VI
MOV 10H,R4 ;NAP GIA TRI VUA TANG VAO 10H
JMP BCD_LCD
HERE1 :
MOV R4,11H
CJNE R4,#00H,NEXT_2
MOV 11H,#09H
JMP HERE2
NEXT_2:
DEC R4
MOV 11H,R4
JMP BCD_LCD
HERE2 :
MOV R4,12H
CJNE R4,#00H,NEXT_3
MOV 12H,#09H
JMP HERE3
NEXT_3:
DEC R4
MOV 12H,R4
JMP BCD_LCD
HERE3 :
MOV R4,13H
CJNE R4,#00H,NEXT_4
MOV 13H,#09H
JMP HERE4
NEXT_4:
DEC R4
MOV 13H,R4
JMP BCD_LCD
HERE4 :
MOV R4,14H
CJNE R4,#00H,NEXT_5
MOV 14H,#09H
JMP HERE5
NEXT_5:
DEC R4
MOV 14H,R4
JMP BCD_LCD
HERE5 :
MOV R4,15H
CJNE R4,#00H,NEXT_6
MOV 15H,#09H
JMP HERE6
NEXT_6:
DEC R4
MOV 15H,R4
JMP BCD_LCD
HERE6 :
JMP BCD_LCD
RET
;************************************************* ***************
BCD_LCD_1: JMP BCD_LCD
;************************************************* ****************
SET4: MOV 15H,#0H
SET3: MOV 14H,#0H
SET2: MOV 13H,#0H
SET1: MOV 12H,#0H
MOV 11H,#0H
MOV 10H,#0H
RET
;************************************************* ***************
DOC_ADC:
MOV DPTR,#500H
SETB WR_ADC
CALL DELAY
CLR WR_ADC
MOV A,P3
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV 2AH,A
MOV A,B
MOVC A,@A+DPTR
MOV 2BH,A
RET
;************************************************* *********************
HIENTHI : MOV R2,#80
MOV TMOD,#01H
CALL INIT_LCD
CALL CLEAR_LCD
LAP : CALL PRESENT
CALL DELAY
CALL TEXT_UP
CALL TEXT_DOWN
DJNZ R2,LAP
CALL DICH
RET
;************************************************
DICH : MOV R2,30H
MOV R0,#30H
MOV R1,#31H
DICH_TIEP : MOV A,@R1
MOV @R0,A
INC R0
INC R1
CJNE R0,#7FH,DICH_TIEP
MOV 7FH,R2
RET
;******************************************
INIT_LCD : MOV R3,#04
SETUP : SETB EN
CLR RS
MOV DATABUS,#38H
CLR EN
LCALL WAIT_LCD
DJNZ R3,SETUP
SETB EN
CLR RS
MOV DATABUS,#0EH
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATABUS,#06H
CLR EN
LCALL WAIT_LCD
LCALL CLEAR_LCD
RET
;************************************************
CLEAR_LCD : SETB EN
CLR RS
MOV DATABUS,#02H
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATABUS,#01H
CLR EN
LCALL WAIT_LCD
RET
;***********************************************
WRITE_TEXT : SETB EN
SETB RS
MOV DATABUS,A
CLR EN
LCALL WAIT_LCD
RET
;***********************************************
DELAY :
MOV TH0,#HIGH(-5000)
MOV TL0,#LOW (-5000)
SETB TR0
JNB TF0,$
CLR TF0
CLR TR0
RET
;************************************************
WAIT_LCD : SETB EN
CLR RS
SETB RW
MOV DATABUS,#0FFH
MOV A,DATABUS
JB ACC.7,WAIT_LCD
CLR EN
CLR RW
RET
;************************************************
PRESENT : MOV A,30H
LCALL WRITE_TEXT
MOV A,31H
LCALL WRITE_TEXT
MOV A,32H
LCALL WRITE_TEXT
MOV A,33H
LCALL WRITE_TEXT
MOV A,34H
LCALL WRITE_TEXT
MOV A,35H
LCALL WRITE_TEXT
MOV A,36H
LCALL WRITE_TEXT
MOV A,37H
LCALL WRITE_TEXT
MOV A,38H
LCALL WRITE_TEXT
MOV A,39H
LCALL WRITE_TEXT
MOV A,3AH
LCALL WRITE_TEXT
MOV A,3BH
LCALL WRITE_TEXT
MOV A,3CH
LCALL WRITE_TEXT
MOV A,3DH
LCALL WRITE_TEXT
MOV A,3EH
LCALL WRITE_TEXT
MOV A,3FH
LCALL WRITE_TEXT
;************************
;LENH XUONG DONG 2 CUA LCD
SETB EN
CLR RS
MOV DATABUS,#0C0H
CLR EN
LCALL WAIT_LCD
;***********************
MOV A,#'S'
LCALL WRITE_TEXT
MOV A,#'P'
LCALL WRITE_TEXT
MOV A,#':'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,25H
LCALL WRITE_TEXT
MOV A,24H
LCALL WRITE_TEXT
MOV A,23H
LCALL WRITE_TEXT
MOV A,22H
LCALL WRITE_TEXT
MOV A,21H
LCALL WRITE_TEXT
MOV A,20H
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,2AH
LCALL WRITE_TEXT
MOV A,2BH
LCALL WRITE_TEXT
MOV A,#'*'
LCALL WRITE_TEXT
MOV A,#'C'
LCALL WRITE_TEXT
RET
;*********************************************
ORG 500H
DB '0','1','2','3','4','5','6','7','8','9'
END
Comment