1。电源VCC为5V,至少提供200mA。(可以用3w6v的变压器整流滤波再通过7805稳压获得。) 2。J1为液晶屏的接口,图中液晶屏选用的是HD61202芯片,128*64点阵,网友购买时需向 供货商索要相关资料及接口定义。液晶屏的接口定义已实现标准化,但引脚分布可能不 同,此千万要注意。如果购买时能测试液晶屏的好坏最好。 程序如下: time0 equ 32 ;53ms time1 equ 187 ;10s sel0 equ 0feh ;秒低位 sel1 equ 0fdh ;秒高位 sel2 equ 0fbh ;分低位 sel3 equ 0f7h ;分高位 sel4 equ 0efh ;时低位 sel5 equ 0dfh ;时高位 sel6 equ 0bfh ;日低位 sel7 equ 07fh ;日高位 sel8 equ 0feh ;月低位 sel9 equ 0fdh ;月高位 sel10 equ 0fbh ;年低位 sel11 equ 0f7h ;年高位 selno equ 0ffh ;--------------------- outPort data p0 selPort0 data p2 selPort1 data p1
second0 data 08h second1 data 09h minute0 data 0ah minute1 data 0bh hour0 data 0ch hour1 data 0dh date0 data 0eh date1 data 0fh month0 data 10h month1 data 11h year0 data 12h year1 data 13h
selled data 30h ;led动态扫描计数 seldata data 31h ;修改时选择项目 key0Data data 32h ;按键状态 key1Data data 33h key2Data data 34h key3Data data 35h tims data 36h tims0 data 37h ;--------------------- rst bit p3.0 io bit p3.1 sclk bit p3.2 key0Pin bit p1.4 key1Pin bit p1.5 key2Pin bit p1.6 key3Pin bit p1.7 ;--------------------- chgMode bit 20h.0 ;修改状态或平常状态 sel0Dot bit 21h.0 ;小数点状态 sel1Dot bit 21h.1 sel2Dot bit 21h.2 sel3Dot bit 21h.3 sel4Dot bit 21h.4 sel5Dot bit 21h.5 sel6Dot bit 21h.6 sel7Dot bit 21h.7 sel8Dot bit 22h.0 sel9Dot bit 22h.1 sel10Dot bit 22h.2 sel11Dot bit 22h.3 ;--------------------- org 0 ljmp main org 0bh ;---------------------------------------- tim0: mov th0,#0f2h ;24M-1666us,50Hz刷新率 mov tl0,#0fch ;3332 push acc push psw push 00h
mov a,selled rl a jmp @a+dptr selLab: ajmp sel0do ajmp sel1do ajmp sel2do ajmp sel3do ajmp sel4do ajmp sel5do ajmp sel6do ajmp sel7do ajmp sel8do ajmp sel9do ajmp sel10do ;ajmp sel11do sel11do:mov selled,#0ffh mov c,sel11Dot mov selPort1,#sel11 ajmp sel10a sel0do: mov selPort0,#sel0 mov c,sel0Dot ajmp sel7a sel1do: mov selPort0,#sel1 mov c,sel1Dot ajmp sel7a sel2do: mov selPort0,#sel2 mov c,sel2Dot ajmp sel7a sel3do: mov selPort0,#sel3 mov c,sel3Dot ajmp sel7a sel4do: mov selPort0,#sel4 mov c,sel4Dot ajmp sel7a sel5do: mov selPort0,#sel5 mov c,sel5Dot ajmp sel7a sel6do: mov selPort0,#sel6 mov c,sel6Dot ajmp sel7a sel7do: mov selPort0,#sel7 mov c,sel7Dot sel7a: mov selPort1,#selno ajmp _tim0a sel8do: mov selPort1,#sel8 mov c,sel8Dot ajmp sel10a sel9do: mov selPort1,#sel9 mov c,sel9Dot ajmp sel10a sel10do:mov selPort1,#sel10 mov c,sel10Dot sel10a: mov selPort0,#selno ;ajmp _tim0a _tim0a:mov f0,c mov a,selled add a,#second0 mov r0,a mov a,@r0 add a,#2 movc a,@a+pc sjmp _tim0b NUMLAB: ;共阳 db 0C0H ;NUM_0 db 0F9H ;NUM_1 db 0A4H ;NUM_2 db 0B0H ;NUM_3 db 99H ;NUM_4 db 92H ;NUM_5 db 82H ;NUM_6 db 0F8H ;NUM_7 db 80H ;NUM_8 db 90H ;NUM_9 ;db 88H ;NUM_A ;db 83H ;NUM_B ;db 0C6H ;NUM_C ;db 0A1H ;NUM_D ;db 86H ;NUM_E ;db 8EH ;NUM_F _tim0b:mov c,f0 mov acc.7,c mov outPort,a inc selled
djnz tims,_tim0c mov tims,#time0 acall read1302 ;读1302/53ms jnb chgMode,_tim0c djnz tims0,_tim0c clr chgMode ;修改模式结束 mov a,#0ffh mov 21h,a mov 22h,a _tim0c:mov a,tims anl a,#7 jnz _tim0d acall key0 ;按键扫描 acall key1 acall key2 acall key3 _tim0d:pop 00h pop psw pop acc reti ;---------------------------------------- main: mov sp,#3fh mov tmod,#01h setb tr0 mov ie,#82h clr a mov selled,a mov seldata,a mov 21h,a mov 22h,a clr chgMode mov tims,#time0 mov dptr,#selLab sjmp $ ;---------------------------------------- _Key0Do: ;up acall _keyIn jnc _Key0Do0 ajmp inc_vale _Key0Do0: ret ;---------------------------------------- _Key1Do: ;down acall _keyIn jnc _Key0Do0 ajmp dec_vale ;---------------------------------------- _Key2Do: ;left acall _keyIn jnc _Key3Do0 ;第一次进入修改模式,不修改内容 inc seldata mov a,seldata cjne a,#6,_Key3Do0 clr a ;秒-0,分-1,时-2,日-3,月-4,年-5 sjmp _Key3Do2 ;---------------------------------------- _Key3Do: ;right acall _keyIn jnc _Key3Do0 ;第一次进入修改模式,不修改内容 dec seldata mov a,seldata cjne a,#0ffh,_Key3Do0 mov a,#5 ;秒-0,分-1,时-2,日-3,月-4,年-5 _Key3Do2: mov seldata,a _Key3Do0: mov a,seldata cjne a,#4,$+3 jnc _Key3Do1 mov 22h,#0ffh mov 21h,#0fch jz _Key3Do0a mov b,a mov a,21h rl a rl a djnz b,$-2 mov 21h,a _Key3Do0a: ret _Key3Do1: clr acc.2 ;subb a,#4 mov 21h,#0ffh mov 22h,#0fch jz _Key3Do1a mov b,a mov a,22h rl a rl a djnz b,$-2 mov 22h,a _Key3Do1a: ret ;---------------------------------------- _keyIn: mov c,chgMode jc _keyIn0 setb chgMode ;第一次进入修改模式 _keyIn0:mov tims0,#time1 ret ;---------------------------------------- read1302: mov r1,#second1+1 mov b,#81h ;second acall read1302a mov b,#83h ;minute acall read1302a mov b,#85h ;hour acall read1302a mov b,#87h ;date acall read1302a mov b,#89h ;month acall read1302a mov b,#8dh ;year acall read1302a ret ;---------------------------------------- read1302a: setb rst mov a,b acall wr_1302 acall rd_1302 clr rst mov b,a anl a,#0fh dec r1 mov @r1,a xch a,b swap a anl a,#07h dec r1 mov @r1,a ret ;--------------------------- wr_cmd: setb rst push acc mov a,b acall wr_1302 pop acc acall wr_1302 clr rst ret ;--------------------------- wr_1302: mov b,#8 wr_1302_0: rrc a mov io,c setb sclk sjmp $+2 clr sclk djnz b,wr_1302_0 ret ;--------------------------- rd_1302: mov b,#8 rd_1302_0: setb sclk setb io mov c,io clr sclk rrc a djnz b,rd_1302_0 ret ;--------------------------- key0: jb Key0Pin,$+8 mov Key0Data,#0 sjmp $+21h ;无键按下,跳 mov a,Key0Data cjne a,#0c0h,$+3 jnc $+0dh add a,#40h mov Key0Data,a cjne a,#0c0h,$+14 acall _Key0Do ;第一次 sjmp $+0fh anl a,#3fh djnz acc,$+7 ;第二次1.3s acall _Key0Do mov a,#10 ;连键,200ms orl a,#0c0h mov Key0Data,a ret ;---------------------------------------- key1: jb Key1Pin,$+8 mov Key1Data,#0 sjmp $+21h ;无键按下,跳 mov a,Key1Data cjne a,#0c0h,$+3 jnc $+0dh add a,#40h mov Key1Data,a cjne a,#0c0h,$+14 acall _Key1Do ;第一次 sjmp $+0fh anl a,#3fh djnz acc,$+7 ;第二次1.3s acall _Key1Do mov a,#10 ;连键,200ms orl a,#0c0h mov Key1Data,a ret ;---------------------------------------- key2: jb Key2Pin,$+8 mov Key2Data,#0 sjmp $+21h ;无键按下,跳 mov a,Key2Data cjne a,#0c0h,$+3 jnc $+0dh add a,#40h mov Key2Data,a cjne a,#0c0h,$+14 acall _Key2Do ;第一次 sjmp $+0fh anl a,#3fh djnz acc,$+7 ;第二次1.3s acall _Key2Do mov a,#10 ;连键,200ms orl a,#0c0h mov Key2Data,a ret ;---------------------------------------- key3: jb Key3Pin,$+8 mov Key3Data,#0 sjmp $+21h ;无键按下,跳 mov a,Key3Data cjne a,#0c0h,$+3 jnc $+0dh add a,#40h mov Key3Data,a cjne a,#0c0h,$+14 acall _Key3Do ;第一次 sjmp $+0fh anl a,#3fh djnz acc,$+7 ;第二次1.3s acall _Key3Do mov a,#10 ;连键,200ms orl a,#0c0h mov Key3Data,a ret ;----------------------------------计算 inc_vale:mov a,seldata cjne a,#5,inc_vale_1 inc year0 mov a,year0 cjne a,#10,inc_vale_0a mov year0,#0 inc year1 mov a,year1 cjne a,#10,inc_vale_0a mov year1,#0 inc_vale_0a: mov a,year1 swap a orl a,year0 mov b,#8ch acall wr_cmd ajmp inc_vale_end inc_vale_1: cjne a,#4,inc_vale_2 mov a,month1 jnz inc_vale_1b inc month0 mov a,month0 cjne a,#10,inc_vale_1a mov month0,#0 mov month1,#1 ajmp inc_vale_1a inc_vale_1b: inc month0 mov a,month0 cjne a,#3,inc_vale_1a mov month0,#1 mov month1,#0 inc_vale_1a: mov a,month1 swap a orl a,month0 mov b,#88h acall wr_cmd ajmp inc_vale_end inc_vale_2: cjne a,#3,inc_vale_3 mov a,date1 cjne a,#3,inc_vale_2b inc date0 mov a,date0 cjne a,#2,inc_vale_2a mov date0,#1 mov date1,#0 sjmp inc_vale_2a inc_vale_2b: inc date0 mov a,date0 cjne a,#10,inc_vale_2a mov date0,#0 inc date1 inc_vale_2a: mov a,date1 swap a orl a,date0 mov b,#86h acall wr_cmd ajmp inc_vale_end inc_vale_3: cjne a,#2,inc_vale_4 mov a,hour1 cjne a,#2,inc_vale_3b inc hour0 mov a,hour0 cjne a,#4,inc_vale_3a mov hour0,#0 mov hour1,#0 ajmp inc_vale_3a inc_vale_3b: inc hour0 mov a,hour0 cjne a,#10,inc_vale_3a mov hour0,#0 inc hour1 inc_vale_3a: mov a,hour1 swap a orl a,hour0 mov b,#84h acall wr_cmd ajmp inc_vale_end inc_vale_4: cjne a,#1,inc_vale_5 inc minute0 mov a,minute0 cjne a,#10,inc_vale_4a mov minute0,#0 inc minute1 mov a,minute1 cjne a,#6,inc_vale_4a mov minute1,#0 inc_vale_4a: mov a,minute1 swap a orl a,minute0 mov b,#82h acall wr_cmd ajmp inc_vale_end inc_vale_5: inc second0 mov a,second0 cjne a,#10,inc_vale_5a mov second0,#0 inc second1 mov a,second1 cjne a,#6,inc_vale_5a mov second1,#0 inc_vale_5a: mov a,second1 swap a orl a,second0 mov b,#80h acall wr_cmd inc_vale_end: ret ;-------------------------------------------- dec_vale:mov a,seldata cjne a,#5,dec_vale_1 dec year0 mov a,year0 cjne a,#0ffh,dec_vale_0 mov year0,#9 dec year1 mov a,year1 cjne a,#0ffh,dec_vale_0 mov year1,#9 dec_vale_0: ajmp inc_vale_0a dec_vale_1: cjne a,#4,dec_vale_2 dec month0 mov a,month0 jnz dec_vale_1a mov a,month1 jnz dec_vale_1b mov month0,#2 mov month1,#1 ajmp inc_vale_1a dec_vale_1b: dec month1 mov month0,#9 dec_vale_1a: ajmp inc_vale_1a dec_vale_2: cjne a,#3,dec_vale_3 mov a,date1 jnz dec_vale_2b dec date0 mov a,date0 cjne a,#0,dec_vale_2a mov date0,#1 mov date1,#3 sjmp dec_vale_2a dec_vale_2b: dec date0 mov a,date0 cjne a,#0ffh,dec_vale_2a mov date0,#9 dec date1 dec_vale_2a: ajmp inc_vale_2a dec_vale_3: cjne a,#2,dec_vale_4 dec hour0 mov a,hour0 cjne a,#0ffh,dec_vale_3a mov hour0,#9 dec hour1 mov a,hour1 cjne a,#0ffh,dec_vale_3a mov hour0,#3 mov hour1,#2 dec_vale_3a: ajmp inc_vale_3a dec_vale_4: cjne a,#1,dec_vale_5 dec minute0 mov a,minute0 cjne a,#0ffh,dec_vlae_4a mov minute0,#9 dec minute1 mov a,minute1 cjne a,#0ffh,dec_vlae_4a mov minute1,#5 dec_vlae_4a: ajmp inc_vale_4a dec_vale_5: inc second0 mov a,second0 cjne a,#0ffh,dec_vlae_5a mov second0,#9 dec second1 mov a,second1 cjne a,#0ffh,dec_vlae_5a mov second1,#5 dec_vlae_5a: ajmp inc_vale_5a ;-------------------------------------------- ;说明:本程序应网友slaoliu所做,没有经过电路试验和调试,有不对之处欢迎指正。 ;LED显示分布: ; 年(高低) 月(高低) 日(高低) 时(高低) 分(高低) 秒(高低) ; sl11 sl10 sl9 sl8 sl7 sl6 sl5 sl4 sl3 sl2 sl1 sl0 ;平常状态:小数点不显示。 ;修改状态:小数点显示正被修改的数据。 ;key0:被修改的数据增加。 ;key1:被修改的数据减少。 ;key2:左循环选择要修改的项目。 ;key3:右循环选择要修改的项目。
|