设计电路,买的共阴数码管3对显示时分秒,4个红色发光二极管做为分隔符。
CPU使用STC89C52RC,
P0口的0到6对应数码管的a到g,用了7个NPN三极管驱动,高关低开,
P2口的0到5,对应时时分分秒秒,用了6个PNP三极管驱动,高开低关,
P10对应1302的CE,P12对应1302的I/O,P11对应1302的SCLK,
P14对应SET按钮,P15对应增大按钮,P16对应减小按钮,P17对应确认按钮,
晶振用12MHz。
001 驱动电路pcb板划线.jpg
002 驱动电路pcb板刻线.jpg
003 驱动电路pcb板打孔.jpg
004 显示电路pcb板刻板,后来证明该设计不方便焊接.jpg
005 显示电路pcb板焊接.jpg
006 显示电路pcb板反面.jpg
007 显示电路焊接完毕,反面,展示一下自己的小台钳.jpg
008 驱动电路焊接完成.jpg
009 显示电路焊接完成,正面.jpg
010 键盘焊接完成.jpg
011 电源部分偷懒了,买了块充电板和升压板,底下是旧电纸书电池.jpg
012 STC89C52RC最小系统.jpg
接下来的工作就是学习编程,花了将近1个星期的所有业余时间,然后又花了1个星期的业余时间完成编码,调试,成功后开始制作外壳。
后面的工作就是木工,很枯燥,过程就不发了。
013 对了,你没有看错,就是4个三极管,用来做按键.jpg
014 将黑漆刮掉.jpg
015 装上按钮的效果,反面.jpg
016 装上按钮的效果,正面.jpg
017 组装完成,角度1.jpg
018 组装完成,角度2.jpg
019 装了一个手机应急充电口.jpg
020 整体效果,正面.jpg
后面的包装木纹纸、围栏里面放置绿草地、玩偶,都交给孩子去做了,我还是喜欢本色。
程序直接贴上,请无视那些英文注释,本人英文水平一直是CLR。
顺便分享一个小技巧,在数码管上贴上双面胶,在粘上一层白纸,不刺眼,效果杠杠滴。
dispbuff equ 30h
delay248 equ 5fH ;delay1ms
count128 equ 3fh
blink_p equ 4fH ;crunt blink point
dispcount equ 4eH ;use display function to delay 1.5s
l_pr_count equ 4dh ;use to count long press time
curentendnum equ 4ch ;store blink_p related end num,1ah,13h,16h
dispcount2 equ 4bh ;
disp_h_s equ 30h
disp_h_g equ 31h
disp_m_s equ 32h
disp_m_g equ 33h
disp_s_s equ 34h
disp_s_g equ 35h
ce1302 equ p1.0 ;1302 CE
io1302 equ p1.2 ;1302 I/O
sclk1302 equ p1.1 ;1302 SCLK
ds1302rds equ 81h
ds1302rdm equ 83h
ds1302rdh equ 85h
ds1302wrs equ 80h
ds1302wrm equ 82h
ds1302wrh equ 84h
ds1302wren equ 8eh;data=00,write enable /80 write protect
issetting equ psw.5 ;key scan sub,if is setting,this bit =1
org 0000
ljmp startdisp
org 0030h
tab:db 40h,79h,24h,30h,19h,12h,02h,78h,00h,10h ;need not #
timeendnum:
db 13h,1ah,16h,1ah,16h,1ah
org 0040h
startdisp:
mov sp,#60h
mov p2,#00h
mov r2,#00h
mov delay248,#248
mov dispcount,#0ffh
mov blink_p,#00h
clr issetting
mov l_pr_count ,#0ffh
mov dispcount2,#7
mov r3,#ds1302rdh
lcall read1302
mov disp_s_s,r4
mov disp_s_g,r5
mov r3,#ds1302rds
lcall read1302
mov disp_s_s,r4
mov disp_s_g,r5
mov r3,#ds1302rdm
lcall read1302
mov disp_m_s,r4
mov disp_m_s,r5
scankey:
mov p1,#0ffh
mov a,p1
orl a,#0fh
cjne a,#0ffh,some_key_pressed
mov l_pr_count ,#0ffh ;not long press
jnb issetting,jmptoend
lcall disp6
djnz dispcount, scankey
djnz dispcount2,scankey
clr issetting
mov dispcount,#0ffh
mov dispcount2,#07h
jmptoend:
ajmp end_of_scankey
some_key_pressed:
mov dispcount ,#0ffh ;not no key press ,need not
jb issetting ,process_set
mov p1,#0ffh
mov a,p1 ;still press ?
orl a,#0fh
cjne a,#7fh,jmptoend ;set key ,1st key ,not issetting and not press 1 , end sub
lcall disp6 ;1 is processed ,beging to count , long enough (1.5s) ,set issetting flag
djnz l_pr_count,jmptoscankey
setb issetting ;1 is processed enough long
mov blink_p,#05h
mov l_pr_count,#0ffh
jmptoscankey:
ajmp scankey
process_set:
waitrelease:
mov p1,#0ffh
mov a,p1
orl a,#0fh
mov b,a
push 0f0h ;b in stake
lcall disp6
pop 0f0h ;b out stake
mov p1,#0ffh
mov a,p1
orl a,#0fh
cjne a,#0ffh,waitrelease
mov a,b
process1:
cjne a,#7fh,process2
mov a,blink_p
mov r0,#dispbuff
add a,r0
mov r0,a
mov a,@r0
clr acc.4 ;clear crunt blink flag
mov @r0,a
inc blink_p ;0-1=5
mov a,blink_p
cjne a,#06h,blinknext ;
clr a ;if 255 , 5
mov blink_p,a
blinknext:
mov r0,#dispbuff
add a,r0
mov r0,a
mov a,@r0
setb acc.4 ;set blink flag
mov @r0,a
toscankey:
ajmp scankey
process2:
cjne a,#0bfh,process3
mov a,blink_p
mov dptr,#timeendnum
movc a,@a+dptr
mov curentendnum,a
mov a,blink_p
mov r0,#dispbuff
add a,r0
mov r0,a
mov a,@r0
inc a
cjne a,curentendnum,add1
mov a,#10h
add1:
mov @r0,a
ajmp scankey
process3:
cjne a,#0dfh,process4
mov a,blink_p
mov dptr,#timeendnum
movc a,@a+dptr
mov curentendnum,a
mov a,blink_p
mov r0,#dispbuff
add a,r0
mov r0,a
mov a,@r0
cjne a,#10h,dec1
mov a,curentendnum
dec1:
dec a
mov @r0,a
ajmp scankey
process4:
cjne a,#0efh,processother
mov a,blink_p
mov r0,#dispbuff
add a,r0
mov r0,a
mov a,@r0
clr acc.4
mov @r0,a ;close blink
mov a,disp_h_s
rr a
cpl a
mov c,acc.0
mov acc.1,c
rl a
rl a
orl a,#0f3h
anl a,disp_h_g
mov disp_h_g,a
mov r3,#ds1302wren
mov r4,#00h
mov r5,#00h
call write1302 ;open write protect ,1302 write enabled
mov r3,#ds1302wrh
mov r4,disp_h_s
mov r5,disp_h_g
lcall write1302
mov r3,#ds1302wrm
mov r4,disp_m_s
mov r5,disp_m_g
lcall write1302
mov r3,#ds1302wrs
mov r4,disp_s_s
mov r5,disp_s_g
lcall write1302
mov r3,#ds1302wren
mov r4,#08h
mov r5,#00h
call write1302 ;open write protect ,1302 write enabled
end_of_scankey:
clr issetting
mov count128,#0
mov dispcount,#0ffh
mov dispcount2,#7
mov l_pr_count ,#0ffh
mov blink_p,#0
mov r3,#ds1302rdh
lcall read1302
mov disp_h_s,r4
mov disp_h_g,r5
mov r3,#ds1302rds
lcall read1302
mov disp_s_s,r4
mov disp_s_g,r5
mov r3,#ds1302rdm
lcall read1302
mov disp_m_s,r4
mov disp_m_g,r5
lcall disp6
ajmp scankey
processother:
ajmp end_of_scankey
disp6: ;disp 6 led
;use r0,r1,r2,r3,r4,acc,and with a count128 named ram unit
mov r4,count128 ;blink counter
mov r2,#0 ;disp point
mov r3,#20h ;place code
disploop:
mov r0,#dispbuff
mov a,r2
add a,r0
mov r0,a
mov a,@r0
jb acc.4,processblink
getnumcode:
mov a,@r0
anl a,#0fh
mov dptr,#tab
movc a,@a+dptr
writep0:
mov p0,a
mov p2,r3
push 02 ;r2 in stake
lcall delay1ms
pop 02 ;r2 out stake
mov p0,#0ffh
mov p2,#00
inc r2
mov a,r3
rr a
mov r3,a
cjne r2,#6,disploop
ajmp endtoret
processblink:
inc count128
mov a,count128
jnb acc.7,getnumcode
mov a,#0ffh
ajmp writep0
;disp6 end
endtoret:
ret
delay1ms:
;use r2
mov r2,0 ;this line make 2 p
mov r2,delay248 ;this line make 2 p
d1:
djnz r2,d1 ;this line make 2 p 248 times
mov r2,delay248 ;this line make 2 p
d2:
djnz r2,d2 ;this line make 2 p 248 times
ret ;this line make 2 p
;total 1000 p =1000us=1ms
write1302:
;use r2 , a , r3=address and contrl r4=high 4 ,r5=low 4
clr ce1302
clr sclk1302
clr io1302
setb ce1302
mov r2,#8
mov a,r3
sendwriteclock:
mov c,acc.0
rr a
mov io1302,c
setb sclk1302
clr sclk1302
djnz r2,sendwriteclock
clr a
mov a,r4
swap a
add a,r5
mov r2,#8
write8bit:
mov c,acc.0
rr a
mov io1302,c
setb sclk1302
clr sclk1302
djnz r2 ,write8bit
clr ce1302
ret
read1302:
;use r2 , a , r3=address and contrl r4=high 4 ,r5=low 4
clr ce1302
clr sclk1302
clr io1302
setb ce1302
mov r2,#8
mov a,r3
sendreadclock:
clr sclk1302
mov c,acc.0
rr a
mov io1302,c
setb sclk1302
djnz r2,sendreadclock
mov r2,#8
clr a
read8bit:
rr a
clr sclk1302
mov c,io1302
mov acc.7,c
setb sclk1302
djnz r2,read8bit
mov r5,a ;r5 low 4
swap a
anl a,#0fh
mov r4,a ;r4 high 4
mov a,r5
anl a,#0fh
mov r5,a
clr ce1302
ret
end
|