chương trình chạy led

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down

chương trình chạy led

Bài gửi by ngocpho on Sat Aug 27, 2011 10:20 am

đây là chương trình:
$include(reg51.inc)
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
;chtrinh dieu khien port 0 va port 2

;doan chtr sang dan - tat dan tu tren xuong
;doan chtr sang dan - tat dan tu duoi len
;doan chtr sang dan tu tren xuong nhung - tat dan tu duoi len
;doan chtr sang dan tu tren xuong nhung - tat dan tu duoi len
;doan chtr sang - tat tu ngoai vao trong
;doan chtr sang - tat tu trong ra ngoai
;doan chtr chop tat 4 lan
;doan chtr chop tat xen ke 3 lan
;ket noi port 0 va port 1 den 16 led bang 2 soi cap 8 soi
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
cseg
Batdau:
;-------------------------------------------------------------------------
;doan chtr sang dan - tat dan tu tren xuong
;-------------------------------------------------------------------------

port01_15: mov p0,#00h ;tat port 0
mov p2,#00h ;tat port 2
port01_15a: lcall delaynhanh ;goi chuong trinh con delay
mov a,p0 ;chuyen noi dung port0 vao thanh ghi A
setb c ;lam cho bit C = 1
rlc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
mov a,p2 ;chuyen noi dung port1 vao thanh ghi A
rlc a ;xoay noi dung thanh ghi A sang trai
mov p2,a ;tra lai cho port2
jnc port01_15a ;nhay ve de thuc hien tiep
port01_15b: lcall delaynhanh ;goi chuong trinh con delay
mov a,p0 ;chuyen noi dung port0 vao thanh ghi A
clr c ;lam cho bit C = 0
rlc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
mov a,p2
rlc a
mov p2,a
jc port01_15b ;nhay ve de thuc hien tiep

;-------------------------------------------------------------------------
;doan chtr sang dan - tat dan tu duoi len
;-------------------------------------------------------------------------
port01_15c: lcall delaynhanh;
mov a,p2 ;
setb c;
rrc a ;
mov p2,a ;
mov a,p0 ;
rrc a ;
mov p0,a ;
jnc port01_15c ;
port01_15d: lcall delaynhanh
mov a,p0 ;
clr c ;
rlc a
mov p0,a ;
mov a,p2;
rlc a ;
mov p2,a ;
jc port01_15d ;

;ooooooooooooooooooooooooooooooooooooooooooooooooo ooooooooooooooooooooooooooooo
;doan chtr chop tat 4 lan
;ooooooooooooooooooooooooooooooooooooooooooooooooo ooooooooooooooooooooooooooooo
choptat: mov r0, #05;
choptat1:
mov p0, #00h;
mov p2, #00h;
lcall delaynhanh;
mov p2, #0ffh;
mov p0, #0ffh;
lcall delaynhanh;
djnz r0, choptat1;
;-------------------------------------------------------------------------
;doan chtr sang dan tu tren xuong nhung - tat dan tu duoi len
;-------------------------------------------------------------------------
mov p0,#00h ;tat port 0
mov p2,#00h ;tat port 2

port01_15e: lcall delaynhanh ;goi chuong trinh con delay
mov a,p0 ;chuyen noi dung port0 vao thanh ghi A
setb c ;lam cho bit C = 1
rlc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
mov a,p2 ;chuyen noi dung port1 vao thanh ghi A
rlc a ;xoay noi dung thanh ghi A sang trai
mov p2,a ;tra lai cho port2
jnc port01_15e ;nhay ve de thuc hien tiep

port01_15f: lcall delaynhanh ;goi chuong trinh con delay
mov a,p0 ;chuyen noi dung port0 vao thanh ghi A
clr c ;lam cho bit C = 0
rlc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
mov a,p2
rlc a
mov p2,a
jc port01_15f ;nhay ve de thuc hien tiep
;-------------------------------------------------------------------------
;doan chtr sang dan tu tren xuong nhung - tat dan tu duoi len
;-------------------------------------------------------------------------
port01_15g: lcall delaynhanh ;goi chuong trinh con delay
mov a,p2 ;chuyen noi dung port0 vao thanh ghi A
setb c ;lam cho bit C = 1
rrc a ;xoay noi dung thanh ghi A sang trai
mov p2,a ;tra lai cho port0
mov a,p0 ;chuyen noi dung port1 vao thanh ghi A
rrc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
jnc port01_15g ;nhay ve de thuc hien tiep
port01_15h: lcall delaynhanh ;goi chuong trinh con delay
mov a,p0 ;chuyen noi dung port0 vao thanh ghi A
rlc a ;xoay noi dung thanh ghi A sang trai
mov p0,a ;tra lai cho port0
mov a,p2
rlc a
mov p2,a
jc port01_15h ;nhay ve de thuc hien tiep
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
;doan chtr sang - tat tu ngoai vao trong
SANGNGOAIVAO:lcall delaynhanh;
SETB C;
RLC A;
MOV P0, A;
MOV A, P2;
SETB C;
RRC A;
MOV P2, A;
MOV A, P0;
JNC SANGNGOAIVAO;
TATNGOAIVAO: lcall delaynhanh;
CLR C;
RLC A;
MOV P0, A;
MOV A, P2;
CLR C;
RRC A;
MOV P2, A;
MOV A, P0;
JC TATNGOAIVAO;
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
;doan chtr sang - tat tu trong ra ngoai
SANGTRONGRA: lcall delaynhanh;
SETB C;
RRC A;
MOV P0, A;
MOV A, P2;
SETB C;
RLC A;
MOV P2, A;
MOV A, P0;
JNC SANGTRONGRA;
TATTRONGRA: lcall delaynhanh;
CLR C;
RRC A;
MOV P0, A;
MOV A, P2;
CLR C;
RLC A;
MOV P2, A;
MOV A, P0;
JC TATTRONGRA;

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
;doan chtr chop tat xen ke 3 lan
lcall delaynhanh;
mov p0, #55h;
mov p2, #55h;
lcall delaynhanh;
mov p0, #0aah;
mov p2, #0aah;
lcall delaynhanh;
mov p0, #55h;
mov p2, #55h;
lcall delaynhanh;
mov p0, #0aah;
mov p2, #0aah;
lcall delaynhanh;
mov p0, #55h;
mov p2, #55h;
lcall delaynhanh;
mov p0, #0aah;
mov p2, #0aah;
ljmp Batdau;
;chuong trinh con delay
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
delaynhanh: cjne r1,#1,v4
nop
nop
nop
nop
ret
nop
nop
v4: dec r1
ret
end
còn hình vẽ thì em dung mô phong trên protues. p0,p2 nối với 16 led

Ai ko pit thi hoi admin nha

ngocpho

Tổng số bài gửi : 9
Join date : 15/06/2011

Xem lý lịch thành viên

Về Đầu Trang Go down

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang


 
Permissions in this forum:
Bạn không có quyền trả lời bài viết