các bác ơi,em đang làm mạch mô phỏng dây chuyền đếm sản phẩm...em viết code cho sơ đồ trên,nhưng mà bí quá.em cứ đếm lên được đến 19 thì cái led hàng chục ko lên được nữa...bác nào pro chỉ em chỗ sai trong code với
.INCLUDE "8515def.inc"
.CSEG
.ORG 0x0000
RJMP BATDAU
.ORG 0x0020
BATDAU:
;KHOI DONG STACK POINTER
LDI R17,HIGH(RAMEND)
LDI R16,LOW(RAMEND)
OUT SPL,R16
OUT SPH,R17
;KHOI DONG CAC PORT
CLR R16 ; XOA R16,R16=0
OUT DDRB,R16; DDRB=0,PORTB LA NGO NHAP
LDI R16,0xFF ;SET TAT CA CAC BIT CUA R16 LEN 1
OUT PORTB,R16 ; DDRB=0,PORTB=0xFF,KEO LEN CAC CHAN PORTB
OUT DDRA,R16 ; DDRA=0xFF,PORTA LA NGO XUAT HANG CHUC
CLR R24 ; XOA R24,R24 LA THANH GHI DUNG CHUA SO DEM
OUT DDRC,R16 ; DDRC=0xFF,PORTC LA NGO XUAT HANG DON VI
CLR R25 ; XOA R25,R25 LA THANH GHI DUNG CHUA SO DEM
SER R20 ; R20 LA THANH GHI TAM CHUA GIA TRI TRUOC DO CUA PINB
MAIN:
IN R21,PINB; DOC GIA TRI TU PINB,TUC TU CAC BUTTON
RCALL SOSANH; GOI CHUONG TRINH CON SO SANH
OUT PORTC,R25; XUAT GIA TRI DEM RA PORTC
OUT PORTA,R24; XUAT GIA TRI DEM RA PORTA
SBRS R21,0; NEU BIT 0 CUA R21(TUC CHAN PB0)=1 THI BO QUA DONG TIEP THEO
RCALL TANG ; NHAY DEN CHUONG TRINH CON TANG GIA TRI DEM
SBRS R21,1; NEU BIT 1 CUA R21 (TUC CHAN PB1)=1 THI BO QUA DONG TIEP THEO
RCALL GIAM ; NHAY DEN CHUONG TRINH CON GIAM GIA TRI DEM
MOV R20,R21; LUU LAI TRANG THAI PINB
RJMP MAIN
;******************CHUONG TRINH CON****************
;******************KIEM TRA GIOI HAN ( TU 0 DEN 9) CUA SO DEM**************
SOSANH:
CPI R25,10
BREQ RESET0; NEU GIA TRI DEM=10 THI TRA VE 0
CPI R25,255
BREQ RESET9; NEU GIA TRI DEM =255 THI TRA VE 9
RJMP QUAYVE;NHAY DEN NHAN QUAY VE
RESET0:
LDI R25,$0;TRA GIA TRI DEM VE 0
LDI R24, $1;TRA GIA TRI DEM VE 1
RJMP QUAYVE
RESET9:
LDI R25,$9;GAN 9 CHO GIA TRI DEM
LDI R24,$9
QUAYVE:
RET
;************************************************* ***********
;****************TANG SO DEM 1 DON VI************************
TANG:
SBRS R20,0
RET
INC R25
RET
CPI R25,$0
INC R24
RET
;************************************************* *************
;***************GIAM SO DEM 1 DON VI***************************
GIAM:
SBRS R20,1
RET
DEC R25
RET
LDI R25,$0
DEC R24
RET
.INCLUDE "8515def.inc"
.CSEG
.ORG 0x0000
RJMP BATDAU
.ORG 0x0020
BATDAU:
;KHOI DONG STACK POINTER
LDI R17,HIGH(RAMEND)
LDI R16,LOW(RAMEND)
OUT SPL,R16
OUT SPH,R17
;KHOI DONG CAC PORT
CLR R16 ; XOA R16,R16=0
OUT DDRB,R16; DDRB=0,PORTB LA NGO NHAP
LDI R16,0xFF ;SET TAT CA CAC BIT CUA R16 LEN 1
OUT PORTB,R16 ; DDRB=0,PORTB=0xFF,KEO LEN CAC CHAN PORTB
OUT DDRA,R16 ; DDRA=0xFF,PORTA LA NGO XUAT HANG CHUC
CLR R24 ; XOA R24,R24 LA THANH GHI DUNG CHUA SO DEM
OUT DDRC,R16 ; DDRC=0xFF,PORTC LA NGO XUAT HANG DON VI
CLR R25 ; XOA R25,R25 LA THANH GHI DUNG CHUA SO DEM
SER R20 ; R20 LA THANH GHI TAM CHUA GIA TRI TRUOC DO CUA PINB
MAIN:
IN R21,PINB; DOC GIA TRI TU PINB,TUC TU CAC BUTTON
RCALL SOSANH; GOI CHUONG TRINH CON SO SANH
OUT PORTC,R25; XUAT GIA TRI DEM RA PORTC
OUT PORTA,R24; XUAT GIA TRI DEM RA PORTA
SBRS R21,0; NEU BIT 0 CUA R21(TUC CHAN PB0)=1 THI BO QUA DONG TIEP THEO
RCALL TANG ; NHAY DEN CHUONG TRINH CON TANG GIA TRI DEM
SBRS R21,1; NEU BIT 1 CUA R21 (TUC CHAN PB1)=1 THI BO QUA DONG TIEP THEO
RCALL GIAM ; NHAY DEN CHUONG TRINH CON GIAM GIA TRI DEM
MOV R20,R21; LUU LAI TRANG THAI PINB
RJMP MAIN
;******************CHUONG TRINH CON****************
;******************KIEM TRA GIOI HAN ( TU 0 DEN 9) CUA SO DEM**************
SOSANH:
CPI R25,10
BREQ RESET0; NEU GIA TRI DEM=10 THI TRA VE 0
CPI R25,255
BREQ RESET9; NEU GIA TRI DEM =255 THI TRA VE 9
RJMP QUAYVE;NHAY DEN NHAN QUAY VE
RESET0:
LDI R25,$0;TRA GIA TRI DEM VE 0
LDI R24, $1;TRA GIA TRI DEM VE 1
RJMP QUAYVE
RESET9:
LDI R25,$9;GAN 9 CHO GIA TRI DEM
LDI R24,$9
QUAYVE:
RET
;************************************************* ***********
;****************TANG SO DEM 1 DON VI************************
TANG:
SBRS R20,0
RET
INC R25
RET
CPI R25,$0
INC R24
RET
;************************************************* *************
;***************GIAM SO DEM 1 DON VI***************************
GIAM:
SBRS R20,1
RET
DEC R25
RET
LDI R25,$0
DEC R24
RET
Comment