Tải bản đầy đủ

THIẾT kế và THI CÔNG MẠCH LED hào QUANG

TRƯỜNG CAO ĐẲNG KỸ THUẬT LÝ TỰ TRỌNG
KHOA ĐIỆN – ĐIỆN TỬ
---------------

PHẦN CODE


;code19/12/2013
;code cho hao quang
;*************

SI

BIT P1.0

RCK BIT P1.1
SCK BIT P1.2
VAN

BIT P3.3


BITDICH

BIT 20H.0

BITTAM

BIT 20H.1

BITXOAd

BIT 20H.2

BITXOAt

BIT 20H.3

BITDON BIT 20H.4
BITLENXUONG BIT 20H.5
BITDICHTRAI BIT 20H.6
BITDICHPHAI BIT 20H.7
BITDICHLEN BIT 21H.0
BITDICHXUONG BIT 21H.1
;***************************
DICHBIT EQU 08H
TAM

EQU 10H

GIATRI_TOCDO EQU 11H
;***************************
HANGTREN EQU P2


HANGDUOI EQU P0
;****************************
TOC_DO

EQU R2

SOLANCHAY EQU R4

MODECHAY EQU R5
;bien xoa mang hinh dau= R6

;****************************
;16byte ram tu 30H...> 40H =MAHANG
;32byte ram tu 41H...> 61H =XUATHANGDUOI
;32byte ram tu 61H...> 81H =XUATHANTREN
;****************************
RAM1DAU DATA 41H
RAM2DAU DATA 61H
RAM1CUOI DATA 61H
RAM2CUOI DATA 81H
RAMTAM1DAU DATA 82H ;32BYTE tu 82H den 0a2H
RAMTAM2DAU DATA 0A3H ;32BYTE tu 0A3H den 0C4H
RAMTAM1CUOI DATA 0A2H
RAMTAM2CUOI DATA 0C3H
;SP = 0C5H

;****************************


ORG 0000H
LJMP MAIN
ORG 000BH ;Dia chi vector bo dinh thoi 0
LJMP T0ISR
; ORG 001BH ;Dia chi vector bo dinh thoi 1
; LJMP T1ISR

MAIN:
;**************************
MOV TMOD,#11H ;Ca 2 bo dinh thoi che do 1
MOV IE,#80H
MOV SP,#0C5H;90H
MOV R7,#20
; CLR VAN
SETB TF0

;Buoc ngat do bo time 0

SETB ET0

;Cho phep ngat bo dinh thoi 0

;*************
LCALL LODE_MAHANG
;************
SETB BITDICHTRAI ;=1 CHAY, =0 BO QUA
SETB BITDICHPHAI
SETB BITDICHLEN


; SETB BITDICHXUONG

CHUONGTRINH1:
;****************
MOV MODECHAY,#1
LCALL TIMMA_DPTR
CLR BITDICH
clr bitlenxuong

;**************************
DICH_LEN_C1:

clr bitxoad
clr bitxoat
mov r6,#0
clr bitdon
MOV SOLANCHAY,#18
MOV TOC_DO,#4
MOV R3,#8
LCALL LOADRAM_TAM
TIEP_C1:
;(((((((
LCALL LOADRAM_HIENTHI
;(((((((


DJNZ TOC_DO,TIEP_C1
MOV TOC_DO,#4
JB BITDICH,D8_16_C1
jb bitlenxuong,xuong_C1
LCALL DICH_RAM_LEN1_8
ljmp _0xC1
xuong_C1:LCALL DICH_RAM_XUONG8_16
_0xC1: jb bitxoat,nor6
inc r6

;lay ma xoa

nor6: DJNZ R3,THOAT_C1
MOV R3,#8
setb bitxoad
SETB BITDICH
;(((((((
THOAT_C1:LJMP TIEP_C1
D8_16_C1:jb bitlenxuong,xuong1_C1
LCALL DICH_RAM_LEN8_16
ljmp _0xC2
xuong1_C1:LCALL DICH_RAM_XUONG1_8
_0xC2: jb bitxoat,nor6_1
inc r6
nor6_1: DJNZ R3,EXIT_C1_1
MOV R3,#8
CLR BITDICH

;dich len 1bit


setb bitxoat
DEC SOLANCHAY
CJNE SOLANCHAY,#16,EXIT_C1
cpl bitlenxuong
setb bitdon
mov r6,#0
jmp EXIT_C1_1
EXIT_C1: jnb bitdon,nor6_2
inc r6
nor6_2: CJNE SOLANCHAY,#0,EXIT_C1_1
INC MODECHAY
EX_01:

; POP 05H

LJMP CHUONGTRINH2;&&&&&&&&
EXIT_C1_1:LJMP TIEP_C1

;**************************************************

CHUONGTRINH2:
;****************
LCALL TIMMA_DPTR
JNB BITDICHLEN,EX_02
CLR BITDICH
clr bitlenxuong
;**************************


DICH_LEN_C2:
clr bitxoad
clr bitxoat
mov r6,#0
clr bitdon
MOV SOLANCHAY,#10
MOV TOC_DO,#6;GIATRI_TOCDO;#6
MOV R3,#8
LCALL LOADRAM_TAM
TIEP_C2:
;(((((((
LCALL LOADRAM_HIENTHI
;(((((((
DJNZ TOC_DO,TIEP_C2
MOV TOC_DO,#6;GIATRI_TOCDO;#6#6
JB BITDICH,D8_16_C2
jb bitlenxuong,xuong_C2
LCALL DICH_RAM_LEN1_8

;dich len 1bit

ljmp _0x2C2
xuong_C2:LCALL DICH_RAM_XUONG8_16
_0x2C2: inc r6
DJNZ R3,THOAT_C2
MOV R3,#8
setb bitxoad

;lay ma xoa


SETB BITDICH
;(((((((
THOAT_C2:LJMP TIEP_C2
D8_16_C2:jb bitlenxuong,xuong1_C2
LCALL DICH_RAM_LEN8_16
ljmp _0x3C2
xuong1_C2:LCALL DICH_RAM_XUONG1_8
_0x3C2: inc r6
DJNZ R3,EXIT_C2
MOV R3,#8
CLR BITDICH
setb bitxoat
DEC SOLANCHAY
CJNE SOLANCHAY,#5,EXIT_C2
cpl bitlenxuong
EXIT_C2: CJNE SOLANCHAY,#0,EXIT_C2_1
LJMP CHUONGTRINH3
EX_02:

LCALL LOADRAM_TAM

LJMP CHUONGTRINH3;&&&&&&&&
EXIT_C2_1:LJMP TIEP_C2
;**************************************************
CHUONGTRINH3:;dich sang trai
JNB BITDICHTRAI,EX_03
;********


mov r6,#0
MOV SOLANCHAY,#100
MOV TOC_DO,#6
; LCALL LOADRAM_TAM
TIEP_C3:
;(((((((
LCALL LOADRAM_HIENTHI
;(((((((
DJNZ TOC_DO,TIEP_C3
MOV TOC_DO,#6
LCALL DICHRAMQUATRAI
DEC SOLANCHAY
CJNE SOLANCHAY,#0,EXIT_C3
EX_03:

LJMP CHUONGTRINH4;&&&&&&&&

EXIT_C3: LJMP TIEP_C3
;$$$$$$$$$$$$$$$$$$$
CHUONGTRINH4:;dich sang phai
JNB BITDICHPHAI,EX1_04
;***********
mov r6,#0
MOV SOLANCHAY,#100
MOV TOC_DO,#6
;***
; LCALL LOADRAM_TAM


TIEP_C4:
;(((((((
LCALL LOADRAM_HIENTHI
;(((((((
DJNZ TOC_DO,TIEP_C4
MOV TOC_DO,#6
LCALL DICHRAMQUAPHAI
DEC SOLANCHAY
CJNE SOLANCHAY,#0,EXIT_C4
EX1_04:

INC MODECHAY
CJNE MODECHAY,#29,EX_04
LJMP CHUONGTRINH1

EX_04: LJMP CHUONGTRINH2

;&&&&&&&&

EXIT_C4: LJMP TIEP_C4

;**************************************************
;**************************************************
T0ISR : CLR TR0

; dung bo dinh thoi

; DJNZ R7,SKIP ;neu chua du thoat
; CPL VAN
; MOV R7,#5
SKIP : MOV TH0,#HIGH(-1000) ;tri hoan 0.1sec
MOV TL0,#LOW(-1000)


CPL VAN
SETB TR0
RETI
;**************************************************
;**********CH/TR con **********************
;**************************************************
LOADRAM_TAM:
LCALL LOADRAMTAM_TREN ;load data tu mang vao
LCALL LOADRAMTAM_DUOI ;ram tam
RET
;*******************************
LOADRAM_HIENTHI:
LCALL LOADRAMDUOI

;load data tu ram tam vao

LCALL LOADRAMTREN
LCALL QUET8HANG1_8
LCALL QUET8HANG8_16
RET
;*******************************
DICHRAMQUATRAI:
LCALL DICHRAM_TRAI_DUOI
LCALL DICHRAM_TRAI_TREN
RET
;*******************************
DICHRAMQUAPHAI:

;ram hien thi


LCALL DICHRAM_PHAI_TREN
LCALL DICHRAM_PHAI_DUOI
RET
;*******************************
DICH_RAM_LEN1_8:
PUSH 00H
PUSH 01H
MOV R0,#RAMTAM2DAU ;ram tren
MOV R1,#RAMTAM1DAU ;ram duoi
DICHT:
MOV A,@R0;nap vao A
CLR C
RRC A ;dich 1 bit sang trai dua bit nay vao co C ;luc nay co C luu bit 7 cua
a
MOV TAM,A;MOV @R0,A;nap vao RAM
;
MOV A,@R1;nap vao A ram duoi
RRC A ;dich 1 bit sang trai dong thoi dua C vao bit vao bit 0
MOV @R1,A;nap vao RAM
;

;C chuan bi nap
mov BITTAM,C

;***********
MOV A,TAM ;Lay lai byte duoi
RL A


MOV C,BITTAM
RRC A ;nap c vao
MOV @R0,A;nap vao RAM
;*******
INC R0
INC R1
CJNE R0,#RAMTAM2CUOI,DICHT

POP 00H
POP 01H
RET
;***************************************
;*******************************
DICH_RAM_XUONG1_8:
PUSH 00H
PUSH 01H
MOV R0,#RAMTAM2DAU ;ram tren
MOV R1,#RAMTAM1DAU ;ram duoi
DICHTX:
MOV A,@R0;nap vao A
CLR C
RLC A ;dich 1 bit sang PHAI dua bit nay vao co C ;luc nay co C luu bit 7
cua a
MOV TAM,A;MOV @R0,A;nap vao RAM


;
MOV A,@R1;nap vao A ram duoi
RLC A ;dich 1 bit sang trai dong thoi dua C vao bit vao bit 0
MOV @R1,A;nap vao RAM
;

;C chuan bi nap
mov BITTAM,C

;***********
MOV A,TAM ;Lay lai byte duoi
RR A
MOV C,BITTAM
RLC A ;nap c vao
MOV @R0,A;nap vao RAM
;*******
INC R0
INC R1
CJNE R0,#RAMTAM2CUOI,DICHTX

POP 00H
POP 01H
RET
;***************************************
DICH_RAM_LEN8_16:
PUSH 00H
PUSH 01H


MOV R0,#RAMTAM2DAU ;ram tren
MOV R1,#RAMTAM1DAU ;ram duoi
DICHT2:
MOV A,@R1;nap vao A
CLR C
RRC A ;dich 1 bit sang trai dua bit nay vao co C ;luc nay co C luu bit 7 cua
a
MOV TAM,A;MOV @R1,A;nap vao RAM
;

;C chuan bi nap
MOV A,@R0;nap vao A ram Tren
RRC A ;dich 1 bit sang trai dong thoi dua C vao bit vao bit 0
MOV @R0,A;nap vao RAM
;C chuan bi nap
mov BITTAM,C

;***********
MOV A,TAM ;Lay lai byte duoi
RL A
MOV C,BITTAM
RRC A ;nap c vao
MOV @R1,A;nap vao RAM
;**************
INC R0
INC R1
CJNE R0,#RAMTAM2CUOI,DICHT2


POP 00H
POP 01H
RET
;**************************************************
;***************************************
DICH_RAM_XUONG8_16:
PUSH 00H
PUSH 01H
MOV R0,#RAMTAM2DAU ;ram tren
MOV R1,#RAMTAM1DAU ;ram duoi
DICHT2X:
MOV A,@R1;nap vao A
CLR C
RLC A ;dich 1 bit sang trai dua bit nay vao co C ;luc nay co C luu bit 7 cua
a
MOV TAM,A;MOV @R1,A;nap vao RAM
;

;C chuan bi nap
MOV A,@R0;nap vao A ram Tren
RLC A ;dich 1 bit sang trai dong thoi dua C vao bit vao bit 0
MOV @R0,A;nap vao RAM
;C chuan bi nap
mov BITTAM,C

;***********
MOV A,TAM ;Lay lai byte duoi


RR A
MOV C,BITTAM
RLC A ;nap c vao
MOV @R1,A;nap vao RAM
;**************
INC R0
INC R1
CJNE R0,#RAMTAM2CUOI,DICHT2X
POP 00H
POP 01H
RET
;**************************************************
QUET8HANG1_8: MOV HANGTREN,#0FFH
PUSH 00H
PUSH 01H
MOV R1,#30H ;chon hang
LAPHANG: MOV R0,#RAM1DAU
CLR RCK
LAPCOT: CLR SCK
MOV A,@R0
SETB C
RLC A
MOV @R0,A
SETB SCK


MOV SI,C
INC R0
CJNE R0,#RAM1CUOI,LAPCOT
LCALL XUNGSAU
SETB RCK
LCALL XUATDUOI; MOV CHONHANG,R7;Sang hang
LCALL DELAYLED
MOV HANGDUOI,#0FFH
INC R1
CJNE R1,#38H,LAPHANG
POP 01H
POP 00H
RET
;*******************************************
;*******************************************
QUET8HANG8_16:MOV HANGDUOI,#0FFH
PUSH 00H
PUSH 01H
MOV R1,#38H ;chon hang
LAPHANG1:
MOV R0,#RAM2DAU
CLR RCK
LAPCOT1:CLR SCK


MOV A,@R0
SETB C
RLC A
MOV @R0,A
SETB SCK
MOV SI,C
INC R0
CJNE R0,#81H,LAPCOT1
LCALL XUNGSAU
SETB RCK
LCALL XUATTREN;
LCALL DELAYLED
MOV HANGTREN,#0FFH
INC R1
CJNE R1,#40H,LAPHANG1
POP 01H
POP 00H
RET
;*******************************************
;********************
XUATDUOI:
MOV A,@R1
MOV HANGDUOI,A
RET


;***********************
XUATTREN:
MOV A,@R1
MOV HANGTREN,A
RET
;***********************
LODE_MAHANG:
PUSH 00H
PUSH 01H
PUSH DPH
PUSH DPL
MOV DPTR,#MAHANG
MOV R0,#30H
MOV R1,#0
NAPTIEP:
MOV A,R1
MOVC A,@A+DPTR
MOV @R0,A
INC R1
INC R0
CJNE R1,#16,NAPTIEP
POP DPL
POP DPH
POP 01H


POP 00H
RET
;*******************************

;*******************************
;*******************************
;*******************************;
LOADRAMDUOI:;(RAM1);sao chep tu ram tam sang ram duoi de hien thi
PUSH 00H
PUSH 01H
;

mov r6,#0
MOV R0,#RAMTAM1DAU
MOV R1,#RAM1DAU

LRAM1:CLR A
MOV A,@R0
jb bitxoad,k_xd
mov dptr,#maxoa
push acc
mov a,r6
movc a,@a+dptr
mov tam,a
pop acc
orl a,tam
jmp lrd


k_xd:jnb bitdon,k_xd1
mov dptr,#madond
push acc
mov a,r6
movc a,@a+dptr
mov tam,a
pop acc
anl a,tam
k_xd1:
lrd:MOV @R1,A
INC R0
INC R1
CJNE R1,#RAM1CUOI,LRAM1
;

pop 06h
POP 01H
POP 00H
RET

;********************************************
LOADRAMTREN:;(RAM2);sao chep tu ram tam sang ram duoi de hien thi
PUSH 00H
PUSH 01H
mov dptr,#maxoat
MOV R0,#RAMTAM2DAU
MOV R1,#RAM2DAU


LRAM2:CLR A
MOV A,@R0
jb bitxoat,k_xt
push acc
mov a,r6
movc a,@a+dptr
mov tam,a
pop acc
orl a,tam
jmp lrt
k_xt:jnb bitdon,k_xt1
mov dptr,#madont
push acc
mov a,r6
movc a,@a+dptr
mov tam,a
pop acc
anl a,tam
k_xt1:
lrt:
MOV @R1,A
INC R0
INC R1
CJNE R1,#RAM2CUOI,LRAM2


POP 01H
POP 00H
RET

;*******************************
LOADRAMTAM_DUOI:
PUSH 00H
PUSH 06H
; LCALL TIMMA_DPTR;MOV DPTR,#HINH_CARO;MAHINH;&&&&
MOV R0,#RAMTAM1DAU
MOV R6,#0;

byte chan 2,4,6

NAPDUOI:
MOV A,R6
MOVC A,@A+DPTR
MOV @R0,A
INC R6
inc r6
INC R0
CJNE R0,#RAMTAM1CUOI,NAPDUOI
POP 06H
POP 00H
RET
;*******************************
;*******************************


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×