这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » lcd,1602 lcd 1602 时钟程序,望提意见!

共2条 1/1 1 跳转至

lcd,1602 lcd 1602 时钟程序,望提意见!

院士
2006-09-17 18:14:16     打赏
lcd,1602 lcd 1602 时钟程序,望提意见!



关键词: 时钟     程序     提意见    

院士
2006-12-22 22:43:00     打赏
2楼
问 /*本电路很简单,有兴趣的可以向我索要,本时钟程序,有年月日,时间,闹铃,等功能,我也是生手,欢迎在家一起探讨!,我用C和汇编两种编写,后面附的为汇编程序*/



#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={"TIME0"};
uchar code table1[]={"GET UP TIME!0"};
uchar code table2[]={"MON0TUE0WED0THU0FRI0SAT0SUN0"};
uchar data buf[]={5,2,11,4,12,0,0};
uchar data buf1[]={7,0};
sbit enable=P3^3;
sbit rs=P3^4;
sbit rw=P3^5;
sbit k1=P2^2;
sbit k2=P2^3;
sbit k3=P2^4;
sbit k4=P2^5;
sbit k5=P2^6;
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P1_7=P1^7;
sbit P2_7=P2^7;
uchar temp,num,num1,hi,li,kk;
uchar a=10,b,c,disp_var,ww,ee;
uchar  *table_var,(*fun)( );
uchar miao,day,key_var,address;
unsigned long lamp_var;
bit bdata nao,flash_var;
void initial (void);
void cls (void);
void busy (void);
void write (void);
void writedata (void);
void delay (uchar m);
void year_disp(void);
void string_disp(void);
void week_disp(void);
void time_disp(void);
void display(void);
void seenao_time(void);
void nao_display(void);
void adjust_nao(void);
void adjust_nao_key(void);
void adjust_nao_key1(void);
void nao_disp(void);
void datetime_adjust(void);
void adjust_year_key(void);
void adjust_mon_key(void);
void write_kong (void);
void adjust_day_key(void);
void flash (uchar job);        
void flash2 (void);
void adjust_week_key(void);
void adjust_time1_key(void);
void adjust_time2_key(void);
void datetime_adjust(void)                    //年月日,星期,时间总调整程序
{
    time_disp();
    while(1)
    {
    switch(key_var)
    {
    case 1:
        {(*fun)=adjust_year_key;
        address=0x82;
        flash (1);}
        break;
    case 2:
        {(*fun)=adjust_mon_key;
        address=0x85;
        flash (2);}
        break;
    case 3:
        {(*fun)=adjust_day_key;
        address=0x88;
        flash (3);
        year_disp();}
        break;
    case 4:
        {flash2 ();
        week_disp();}
        break;
    case 5:
        {(*fun)=adjust_time1_key;
        address=0xc5;
        flash (4);}
        break;
    case 6:
        {(*fun)=adjust_time2_key;
        address=0xc8;
        flash (5);
        time_disp();}
        break;
    default:break;
    }
    if(k4==0){goto lable2;}
    }
lable2:
    {a=10;
    lamp_var=69999;
    TL0=183;
    TH0=60;
    TR0=1;
    display();}                                //GOTO跳出调整
}
void flash (uchar job)                            //年月日,时间闪动
{        
    for(ww=8;ww>0;ww--)
        {for(ee=188;ee>0;ee--);
            {if(job<=3)    {year_disp();}
             if((job>=4)&&(job<=6))    {time_disp();}
                if((job>=7)&&(job<=8))    {nao_display();}
            (*fun)();
            if(k3==0)
                {do
                {;}
                while(k3==0);
                {key_var++;
                if((key_var>6)&&(flash_var==0)) {key_var=1;}
                if((key_var>8)&&(flash_var==1)) {key_var=7;}
                break;
                }
                }
            if(k4==0){goto lable;}
            }
        }
    for(ww=12;ww>0;ww--)
        {for(ee=218;ee>0;ee--);
            {
            disp_var=address;
            write_kong ();
            (*fun)();
            }
        }
lable:{;}
}
void flash2 (void)                        //星期 闪动
{
    for(ww=11;ww>0;ww--)
        {for(ee=188;ee>0;ee--);
            {week_disp();
            adjust_week_key();
            if(k3==0)
                {do
                {week_disp();}
                while(k3==0);
                {key_var++;break;}
                }
            if(k4==0){goto lable1;}
            }
        }
    for(ww=11;ww>0;ww--)
        {for(ee=188;ee>0;ee--);
            {disp_var=0x8c;
            write_kong ();
            disp_var++;
            temp=disp_var;
            write();
            temp=' ';
            writedata();
            adjust_week_key();
            }
        }
lable1:{;}
}
void adjust_year_key(void)                // year ++;--
{
    while(k1==0)
        {buf[0]++;    
        if(buf[0]==16){buf[0]=5;}
        year_disp();
        delay(199);}            
    while(k2==0)
        {if(buf[0]==5){buf[0]=16;}
        buf[0]--;    
        year_disp();
        delay(199);}
}
void adjust_mon_key(void)                // mon ++;--
{
    while(k1==0)
        {buf[1]++;    
        if(buf[1]==13){buf[1]=1;}
        year_disp();
        delay(199);}            
    while(k2==0)
        {if(buf[1]==1){buf[1]=13;}
        buf[1]--;    
        year_disp();
        delay(199);}
}
void adjust_day_key(void)                // day ++;--
{
    while(k1==0)
        {buf[2]++;    
        if(buf[2]==32){buf[2]=1;}
        year_disp();
        delay(128);}            
    while(k2==0)
        {if(buf[2]==1){buf[2]=32;}
        buf[2]--;    
        year_disp();
        delay(128);}
}
void write_kong (void)                    // 写入空字符
{
    temp=disp_var;
    write();
    temp=' ';
    writedata();
    disp_var++;
    temp=' ';
    writedata();
}
void adjust_time1_key(void)                    // HH ++;--
{
    while(k1==0)
        {buf[4]++;    
        if(buf[4]==24){buf[4]=0;}
        time_disp();
        delay(128);}        
    while(k2==0)
        {if(buf[4]==0){buf[4]=24;}
        buf[4]--;    
        time_disp();
        delay(128);}
}
void adjust_time2_key(void)                    // MM ++;--
{
    while(k1==0)
        {buf[5]++;    
        if(buf[5]==60){buf[5]=0;}
        time_disp();
        delay(128);}        
    while(k2==0)
        {if(buf[5]==0){buf[5]=60;}
        buf[5]--;    
        time_disp();
        delay(128);}
}
void adjust_week_key(void)                    // WEEK ++;--
{    
    while(k1==0)
        {buf[3]++;    
        if(buf[3]==7){buf[3]=0;}
        week_disp();
        delay(228);}            
    while(k2==0)
        {if(buf[3]==0){buf[3]=7;}
        buf[3]--;
        week_disp();
        delay(228);}
}
void seenao_time(void)                    //闹铃时间查询,6秒后自动返回
{
    uint x;
    uchar y,z,un=0;
    cls ();
    disp_var=0x80;
    table_var=&table1[0];
    string_disp();
    nao_display();
    for(x=1119;x>0;x--)
        {for(y=219;y>0;y--);
            {for(z=219;z>0;z--);
                {    
                if(k3==0)            //K3按下调时间,否则6秒后退出
                {    do        
                    {;}
                    while(k3==0);
                    {key_var=7;
                    flash_var=1;
                    adjust_nao();
                    goto lable2;
                    }
                }
                }                
            }
        }
lable2:
    {cls ();
    display();
    lamp_var=66666;
    key_var=1;}
}
void adjust_nao(void)                        //闹铃调整
{    
    while(1)
    {
    switch(key_var)
    {
    case 7:
        {(*fun)=adjust_nao_key;
        address=0xc5;
        flash(7);}
        break;
    case 8:
        {(*fun)=adjust_nao_key1;
        address=0xc8;
        flash(8);}
        break;
    default: break;
    }
    if(k4==0){goto lable3;}
    }
lable3:return;
}
void adjust_nao_key(void)                //闹铃hh++;--
{                
    while(k1==0)
        {buf1[0]++;    
        if(buf1[0]==24){buf1[0]=0;}
        nao_display();
        delay(199);}            
    while(k2==0)
        {if(buf1[0]==0){buf1[0]=24;}
        buf1[0]--;    
        nao_display();
        delay(199);}
}
void adjust_nao_key1(void)                //闹铃mm++;--
{        
    while(k1==0)
        {buf1[1]++;    
        if(buf1[1]==60){buf1[1]=0;}
        nao_display();
        delay(159);}
    while(k2==0)
        {if(buf1[1]==0){buf1[1]=60;}
        buf1[1]--;    
        nao_display();
        delay(159);}
}
void nao_display(void)                    //闹铃时间扫描显示
{
    disp_var=0xc5;
    temp=disp_var;
    write();
    temp=((buf1[0]/10)+0x30);
    writedata();
    disp_var++;
    temp=((buf1[0]%10)+0x30);
    writedata();
    disp_var++;
    temp=disp_var;
    write();
    temp=':';
    writedata();
    disp_var++;
    temp=disp_var;
    write();
    temp=((buf1[1]/10)+0x30);
    writedata();
    disp_var++;
    temp=((buf1[1]%10)+0x30);
    writedata();
}
void display(void)                //全显示程序
{    
    year_disp();                //年月日函数
    week_disp();                //星期扫描函数
    disp_var=0xc0;                //TIME字符扫描
    table_var=&table[0];            //指针赋值
    string_disp();                //字符串函数
    time_disp();                //时间扫描函数
    nao_disp();                    //闹铃符号显示函数
}
void nao_disp(void)                //闹铃符号显示函数
{
    if(nao==1)
        {temp=0xce;
        write();
        temp=0x40;
        writedata(); }
    if(nao==0)
        {temp=0xce;
        write();
        temp=0x20;
        writedata(); }
}
void year_disp(void)                    //年月日函数
{
    num=0;
    kk=0;
    temp=0x80;                        //显示年的高位20;
    write();
    temp=0x32;
    writedata();
    temp=0x81;
    write();
    temp=0x30;
    writedata();
    disp_var=0x82;                    //显示年月日;
    while(num<3)        
    {
    temp=disp_var;
    write();
    hi=((buf[num]/10)+0x30);
    li=((buf[num]%10)+0x30);
    temp=hi;
    writedata();
    disp_var++;
    temp=li;
    writedata();
    disp_var++;
    temp=disp_var;
    if(kk!=2){write();temp='/';writedata();}
    num++;
    kk++;
    disp_var++;
    }
}
void week_disp(void)                    //星期扫描
{
    disp_var=0x8c;
    table_var=&table2[(buf[3]*4)];
    string_disp();
}
void string_disp(void)                    //字符串扫描
{
    do
    {temp=disp_var;
    write();
    temp=*table_var;
    writedata();
    disp_var++;
    table_var++;}
    while(*table_var!=0x30);
}
void time_disp(void)                    //时间扫描        
{    
    disp_var=0xc5;
    num=4;
    kk=0;
    while(num!=7)        
    {
    temp=disp_var;
    write();
    hi=((buf[num]/10)+0x30);
    li=((buf[num]%10)+0x30);
    temp=hi;
    writedata();
    disp_var++;
    temp=li;
    writedata();
    disp_var++;
    temp=disp_var;
    if(kk<2){write();temp=':';writedata();}
    num++;
    kk++;
    disp_var++;
    }
}
void initial (void)                        //LCD初始化
{
    temp=0x38;            //#00111000b
    write();
    temp=0x0c;            //#00001100b
    write();
    temp=0x06;            //#00000110b
    write();
}
void cls (void)                            //清屏
{
    temp=0x01;
    enable=0;
    write();
}
void write (void)                            //写资料寄存器
{
    busy();
    enable=0;
    rw=0;

    rs=0;
    enable=1;
    P1=temp;
    enable=0;
}
void writedata (void)                        //写数据
{
    busy();
    enable=0;
    rw=0;
    rs=1;
    enable=1;
    P1=temp;
    enable=0;
}
void busy (void)                            //忙查询
{
    uchar busy_temp;
    enable=0;
    do
    {rw=1;
    rs=0;
    enable=1;
    busy_temp=P1_7;
    enable=0;}
    while(busy_temp==1);
    delay(6);
}
void delay (uchar m)                        //延时
{
    uchar n;
    for(;m>0;m--)
        for(n=100;n>0;n--);
}
void intermit() interrupt 1 using 0                //中断服务程序
{
    EA=0;
    TR0=0;
    TL0+=183;
    TH0+=60;
    a--;
        if(a==0)
            {a=10; P0_0=!P0_0; b++;}
        if(b==2)
            {b=0;buf[6]++;}
        if(buf[6]==60)
            {buf[6]=0;buf[5]++;}
        if(buf[5]==60)
            {buf[5]=0; buf[4]++;}
        if(buf[4]==24)
            {buf[4]=0; buf[3]++; buf[2]++;}
        if(buf[3]==7)
            {buf[3]=0;}
        if(buf[2]==32)
            {buf[2]=1; buf[1]++;}
        if(buf[1]==13)
            {buf[1]=1; buf[0]++;}
        if(buf[0]==16)
            {buf[7]=(05,02,11,1,12,00,00);}
        if(nao==1)
            {if(buf1[0]==buf[4])
                { if(buf1[1]==buf[5]) { P2_7=0; } }
            }
    EA=1;
    TR0=1;
}
void main(void)                            //主程序
{    
    TMOD=1;
    EA=1;
    ET0=1;
    TL0=0xb0;
    TH0=0x3c;
    TR0=1;
    P0_0=0;
    initial();
    cls();
    display();
    miao=buf[6];
    day=buf[3];
    while(1)
    {
    if(miao!=buf[6])                     //比较旧秒与新秒之间有无变化,如有则扫描
        {miao=buf[6];time_disp();}
    if(day!=buf[3])                     //比较旧日期与新日期之间有无变化,如有则扫描
        {miao=buf[3];display();}
    if(k1==0)                        //闹铃时间查询与调整
        {P0_1=0;seenao_time();}
    if(k2==0)                        //闹铃开 / 关
        {do
        {;}
        while(k2==0);
        {P0_1=0;
        lamp_var=69999;
        nao=!nao;
        nao_disp();}
        }
    if(k3==0)                        //总调整(年月日,星期,时间)
        {TR0=0;
        miao=buf[6]=0;
        P0_1=0;
        key_var=1;
        flash_var=0;
        datetime_adjust();}
    if(k5==0){P0_1=0;lamp_var=69999;}        //背光开关
    lamp_var--;                        //延时6秒关背光
    if(lamp_var==1) {P0_1=1;}
    }
}


汇编程序:

org 00h
ljmp start
org 0bh
ljmp to_int
org 1bh
ljmp to_int1
org 50h
start:
enable bit p3.3
rs bit p3.4
rw bit p3.5
k1 bit p2.2
k2 bit p2.3
k3 bit p2.4
k4 bit p2.5
k5 bit p2.6
db0_db7 data p1
nao   equ 30h       ;闹铃符号
buf   equ 31h       ;年月日
buf1  equ 32h       ;时间
mia0  equ 35h
day0  equ 36h
shi   equ 37h
year1 equ 38h
year2 equ 39h
mon   equ 40h
day   equ 41h
week  equ 42h
hh    equ 43h
mm    equ 44h
mia   equ 45h
lhh   equ 46h
lmm   equ 47h
mov sp,#70h
mov r4,#10         
mov r3,#50
mov r1,#2    
lcall cls
lcall initial           
lcall int
mov tmod,#00010001b
mov ie,#10001010b
mov ip,#00000010b
mov th1,#00
mov tl1,#00
begin:
mov th0,#60
mov tl0,#183   
setb tr0
start2:
mov dptr,#line2
mov a,#2
lcall string
lcall tim_pro        ;年
lcall tim_pro1       ;时间
lcall week_xin       ;星期   
start1:
lcall tim_p                       ;时间
lcall tim_pr                      ;年
jb k1,key1         
lcall delay
jb k1,key1
lcall ling
mov r2,#3
mov r5,#18
ling2:
lcall delay1
djnz r2,ling2
lcall cls
setb tr1
ljmp start2
key1:
jb k2,key2          ;-
lcall delay
jb k2,key2
ljmp open
key2:                ;set
jb k3,key3
call delay        
jnb k3,$
ljmp key_year
key3:                ;ok
jb k4,key4
jnb k4,$
ljmp ko1
key4:
jb k5,key5           ;lamp
jnb k5,$
clr p0.1
clr tr1
mov th1,#00
mov tl1,#00
mov r3,#50
mov 37h,#00
setb tr1
setb p2.7
key5:
mov a,nao
cjne a,#1,key6
mov a,#"@"
mov b,#14
lcall disp1
key6:
ljmp start1
ko1:
clr p0.1
clr tr1
mov th1,#00
mov tl1,#00
mov r3,#50
mov 37h,#00
lcall cls
tt:
mov dptr,#line12
mov a,#1
lcall string
mov dptr,#line13
mov a,#2
lcall string
lcall ko2
lcall cls
mov dptr,#line14
mov a,#1
lcall string
mov dptr,#line15
mov a,#2
lcall string
lcall ko2
lcall cls
mov dptr,#line16
mov a,#1
lcall string
mov dptr,#line17
mov a,#2
lcall string
lcall ko2
lcall cls
mov dptr,#line18
mov a,#1
lcall string
mov dptr,#line19
mov a,#2
lcall string
lcall ko2
lcall cls
jb k4,tt
jnb k4,$
lcall cls
setb tr1
ljmp START2
ko2:
mov r2,#99
mov r5,#6
ko3:
lcall delay
jb k4,ko4
jnb k4,$
lcall cls
setb tr1
ljmp START2
ko4:
djnz r2,ko3
djnz r5,ko3
ret
int:
mov 30h,#00          ;nao
mov 31h,#00          ;年
mov 32h,#00
mov 35h,#00           
mov 36h,#01
mov 37h,#00
mov 38h,#20          ;year1
mov 39h,#05          ;year2
mov 40h,#01          ;mon
mov 41h,#01          ;day
mov 42h,#01          ;week
mov 43h,#12          ;hh
mov 44h,#00          ;mm
mov 45h,#00          ;mia
mov 46h,#07          ;lhh
mov 47h,#00          ;lmm
mov p2,#0ffh
ret
key_year:            ;年调整
clr tr0
clr tr1
clr p0.1
mov th1,#00
mov tl1,#00
mov r3,#50
mov 37h,#00
mov mia,#00
mov mia0,#00
year_set1:
mov dptr,#line2
mov a,#2
lcall string
lcall tim_pro        ;年
lcall tim_pro1       ;时间
lcall week_xin       ;星期  
mov a,nao
cjne a,#1,year_set
mov a,#"@"
mov b,#14
lcall disp1
year_set:
mov a,year2
mov buf,#2
lcall conv
mov r5,#98       
mov r6,#118
ke2:
lcall ke1
djnz r5,ke2
djnz r6,ke2
mov a,#" "
mov b,#2
lcall disp
mov a,#" "
inc b
lcall disp
mov r5,#98       
mov r6,#98
ke3:
lcall ke1
djnz r5,ke3
djnz r6,ke3
ljmp year_set1
ke1:
jb k1,fan1
lcall year_up
fan1:
jb k2,fan2
lcall year_down
fan2:
jb k3,fan3
call delay         
jnb k3,$
ljmp mon_set
fan3:
jb k4,fan4
jnb k4,$
lcall cls
setb tr1
ljmp begin                 
fan4:
ret
year_up:
mov a,year2
mov buf,#2
lcall conv
mov r5,#2            
lcall delay1
jb k1,up1
inc year2
mov r5,#28
lcall delay1
mov a,year2
cjne a,#16,year_up
mov year2,#05
ljmp year_up
up1:
ret
year_down:
mov a,year2
mov buf,#2
lcall conv
mov r5,#2           
lcall delay1
jb k2,up2
mov r5,#28
lcall delay1
dec year2
mov a,year2
cjne a,#4,year_down
mov year2,#15
ljmp year_down
up2:
ret
mon_set:                 ;月调整
mov a,year2
mov buf,#2
lcall conv
mon_set1:
mov a,mon
mov buf,#5
lcall conv
mov r5,#98      
mov r6,#118
mon0:
lcall mon1
djnz r5,mon0
djnz r6,mon0
mov a,#" "
mov b,#5
lcall disp
mov a,#" "
inc b
lcall disp
mov r5,#98      
mov r6,#98
mon2:
lcall mon1
djnz r5,mon2
djnz r6,mon2
ljmp mon_set1
mon1:
jb k1,kek4
lcall mon_up
kek4:
jb k2,kek5
lcall mon_down
kek5:
jb k3,kek6
call delay          
jnb k3,$
ljmp day_set
kek6:
jb k4,mon_se
jnb k4,$
lcall cls
setb tr1
ljmp begin
mon_se:
ret
mon_up:
mov a,mon
mov buf,#5
lcall conv
mov r5,#2            
lcall delay1
jb k1,up3
inc mon
mov r5,#28
lcall delay1
mov a,mon
cjne a,#13,mon_up
mov mon,#01
ljmp mon_up
up3:
ret
mon_down:
mov a,mon
mov buf,#5
lcall conv
mov r5,#2            
lcall delay1
jb k2,up4
dec mon
mov r5,#28
lcall delay1
mov a,mon
cjne a,#00,mon_down
mov mon,#12
ljmp mon_down
up4:
ret
day_set:                ;日调整
mov a,mon
mov buf,#5
lcall conv
day_set1:
mov a,day
mov buf,#8
lcall conv
mov r5,#98       
mov r6,#118
day3:
lcall day1
djnz r5,day3
djnz r6,day3
mov a,#" "
mov b,#8
lcall disp
mov a,#" "
inc b
lcall disp
mov r5,#98       
mov r6,#98
day2:
lcall day1
djnz r5,day2
djnz r6,day2
ljmp day_set1
day1:
jb k1,kek7
lcall day_up
kek7:
jb k2,kek8
lcall day_down
kek8:
jb k3,kek9
call delay         
jnb k3,$
ljmp week_set
kek9:
jb k4,day_se
jnb k4,$
lcall cls
setb tr1
ljmp begin
day_se:
ret
day_up:
mov a,day
mov buf,#8
lcall conv
mov r5,#2            
lcall delay1
jb k1,up5
inc day
mov r5,#28
lcall delay1
mov a,day
cjne a,#32,day_up
mov day,#01
ljmp day_up
up5:
mov day0,day
ret
day_down:
mov a,day
mov buf,#8
lcall conv
mov r5,#2      
lcall delay1
jb k2,up6
dec day
mov r5,#28
lcall delay1
mov a,day
cjne a,#00,day_down
mov day,#31
ljmp day_down
up6:
mov day0,day
ret
week_set:                ;星期调整
mov a,day
mov buf,#8
lcall conv
week_set1:
lcall week_xin
mov r5,#98       
mov r6,#118
week2:
lcall week0
djnz r5,week2
djnz r6,week2
mov dptr,#line1
lcall week_disp
mov r5,#98       
mov r6,#98
week3:
lcall week0
djnz r5,week3
djnz r6,week3
ljmp week_set1
week0:

jb k1,wee1
lcall week_up
wee1:
jb k2,wee2
lcall week_down
wee2:
jb k3,wee3
call delay            
jnb k3,$
ljmp hh_set
wee3:
jb k4,week1
jnb k4,$
lcall cls
setb tr1
ljmp begin
week1:
ret
week_up:
lcall week_xin
mov r5,#2
lcall delay1
jb k1,wee4
inc week
mov r5,#58
lcall delay1
mov a,week
cjne a,#8,week_up
mov week,#01
ljmp week_up
wee4:
ret
week_down:
lcall week_xin
mov r5,#2
lcall delay1
jb k2,wee5
dec week
mov r5,#58
lcall delay1
mov a,week
cjne a,#0,week_down
mov week,#7
ljmp week_down
wee5:
ret
hh_set:                ;小时调整
lcall week_xin
hh_set1:
mov a,hh
mov buf1,#5
lcall conv1
mov r5,#98      
mov r6,#118
hh0:
lcall hh1
djnz r5,hh0
djnz r6,hh0
mov a,#" "
mov b,#5
lcall disp1
mov a,#" "
inc b
lcall disp1
mov r5,#98      
mov r6,#98
hh3:
lcall hh1
djnz r5,hh3
djnz r6,hh3
ljmp hh_set1
hh1:
jb k1,wee6
lcall hh_up
wee6:
jb k2,wee7
lcall hh_down
wee7:
jb k3,wee8
call delay
jnb k3,$
ljmp mm_set
wee8:
jb k4,hh2
call delay
jnb k4,$
lcall cls
setb tr1
ljmp begin
hh2:
ret
hh_up:
mov a,hh
mov buf1,#5
lcall conv1
mov r5,#2
lcall delay1
jb k1,wee9
inc hh
mov r5,#28
lcall delay1
mov a,hh
cjne a,#24,hh_up
mov hh,#00
ljmp hh_up
wee9:
ret
hh_down:
mov a,hh
mov buf1,#5
lcall conv1
mov r5,#2
lcall delay1
jb k2,wee10
mov a,hh
cjne a,#00,hh_down1   
mov hh,#23
mov r5,#28                   
lcall delay1
ljmp hh_down
hh_down1:
dec hh
mov r5,#18
lcall delay1
ljmp hh_down
wee10:
ret
mm_set:                ;分钟调整
mov a,hh
mov buf1,#5
lcall conv1
mm_set1:
mov a,mm
mov buf1,#8
lcall conv1
mov r5,#98      
mov r6,#118
mm2:
lcall mm0
djnz r5,mm2
djnz r6,mm2
mov a,#" "
mov b,#8
lcall disp1
mov a,#" "
inc b
lcall disp1
mov r5,#98      
mov r6,#98
mm3:
lcall mm0
djnz r5,mm3
djnz r6,mm3
ljmp mm_set1
mm0:
jb k1,wee11
lcall mm_up
wee11:
jb k2,wee12
lcall mm_down
wee12:
jb k3,wee13
call delay         
jnb k3,$
ljmp lhh_set
wee13:
jb k4,mm1
jnb k4,$
lcall cls
setb tr1
ljmp begin
mm1:
ret
mm_up:
mov a,mm
mov buf1,#8
lcall conv1
mov r5,#2
lcall delay1
jb k1,wee14
inc mm
mov r5,#18
lcall delay1
mov a,mm
cjne a,#60,mm_up
mov mm,#00
ljmp mm_up
wee14:
ret
mm_down:
mov a,mm
mov buf1,#8
lcall conv1
mov r5,#2
lcall delay1
jb k2,wee15
mov a,mm
cjne a,#00,mm_down2    
mov mm,#59
mov r5,#18
lcall delay1
ljmp mm_down
mm_down2:
dec mm
mov r5,#18
lcall delay1
ljmp mm_down
wee15:
ret
lhh_set:               ;闹铃小时调整
lcall cls
lcall ling1
lhh0:
mov a,lhh
mov buf1,#5
lcall conv1
mov r5,#98      
mov r6,#118
lhh1:
lcall lhh2
djnz r5,lhh1
djnz r6,lhh1
mov a,#" "
mov b,#5
lcall disp1
mov a,#" "
inc b
lcall disp1
mov r5,#98      
mov r6,#98
lhh4:
lcall lhh2
djnz r5,lhh4
djnz r6,lhh4
ljmp lhh0
lhh2:
jb k1,kan1
lcall lhh_up
kan1:
jb k2,kan2
lcall lhh_down
kan2:
jb k3,kan3
call delay          
jnb k3,$
ljmp lmm_set
kan3:
jb k4,lhh3
jnb k4,$
lcall cls
setb tr1
ljmp begin
lhh3:
ret
lhh_up:
mov a,lhh
mov buf1,#5
lcall conv1
mov r5,#2
lcall delay1
jb k1,kan4
inc lhh
mov r5,#28      
lcall delay1
mov a,lhh
cjne a,#24,lhh_up
mov lhh,#00
ljmp lhh_up
kan4:
ret
lhh_down:
mov a,lhh
mov buf1,#5
lcall conv1
mov r5,#2
lcall delay1
jb k2,kan5
mov a,lhh
cjne a,#00,lhh_down1
mov lhh,#23
mov r5,#28
lcall delay1
ljmp lhh_down
lhh_down1:
dec lhh
mov r5,#18
lcall delay1
ljmp lhh_down
kan5:
ret
lmm_set:                 ;闹铃分钟调整
mov a,lhh
mov buf1,#5
lcall conv1
lmm_set1:
mov a,lmm
mov buf1,#8
lcall conv1
mov r5,#98      
mov r6,#118
lmm2:
lcall lmm0
djnz r5,lmm2
djnz r6,lmm2
mov a,#" "
mov b,#8
lcall disp1
mov a,#" "
inc b
lcall disp1
mov r5,#98  
mov r6,#98
lmm3:
lcall lmm0
djnz r5,lmm3
djnz r6,lmm3
ljmp lmm_set1
lmm0:
jb k1,kan6
lcall lmm_up
kan6:
jb k2,kan7
lcall lmm_down
kan7:
jb k3,kan8
call delay          
jnb k3,$
lcall cls
ljmp year_set1              ;遁环调整
kan8:
jb k4,lmm1
jnb k4,$
lcall cls
setb tr1
mov mia,#00
mov mia0,#00
ljmp begin
lmm1:
ret
lmm_up:
mov a,lmm
mov buf1,#8
lcall conv1
mov r5,#2
lcall delay1
jb k1,kan9
inc lmm
mov r5,#18      
lcall delay1
mov a,lmm
cjne a,#60,lmm_up
mov lmm,#00
ljmp lmm_up
kan9:
ret
lmm_down:
mov a,lmm
mov buf1,#8
lcall conv1
mov r5,#2
lcall delay1
jb k2,kan10
mov a,lmm
cjne a,#00,lmm_down1    
mov lmm,#59
mov r5,#18
lcall delay1
ljmp lmm_down
lmm_down1:
dec lmm
mov r5,#18
lcall delay1
ljmp lmm_down
kan10:
ret
open:                   ;开/关闹钟
clr p0.1
clr tr1
mov th1,#00
mov tl1,#00
mov r3,#50
mov 37h,#00
mov a,nao
cjne a,#1,open1
mov a,#" "
mov b,#14
lcall disp1
mov nao,#00
setb tr1
ljmp start2
open1:
mov a,#"@"
mov b,#14
lcall disp1
mov nao,#01
setb tr1
ljmp start2
ling:                   ;闹钟时间查询
clr p0.1
clr tr1
mov th1,#00
mov tl1,#00
mov r3,#50
mov 37h,#00
lcall cls
ling1:
mov dptr,#line11
mov a,#1
lcall string
mov a,lhh
mov buf1,#5
lcall conv1
inc buf1
mov a,#":"
mov b,buf1
lcall disp1
mov a,lmm
inc buf1
lcall conv1
ret
tim_p:                 ;时间扫描
mov a,mia
mov b,mia0
cjne a,b,pp1
ljmp pp2
pp1:
lcall tim_pro1
mov mia0,mia
pp2:
ret
tim_pr:               ;年月日扫描
mov a,day
mov b,day0
cjne a,b,pp3
ljmp pp4
pp3:
lcall tim_pro
lcall week_xin
mov day0,day
pp4:
ret
week_xin:                ;星期子程序
mov a,week
cjne a,#1,xin2
mov dptr,#line4
ljmp week_disp
xin2:
cjne a,#2,xin3
mov dptr,#line5
ljmp week_disp
xin3:
cjne a,#3,xin4
mov dptr,#line6
ljmp week_disp
xin4:
cjne a,#4,xin5
mov dptr,#line7
ljmp week_disp
xin5:
cjne a,#5,xin6
mov dptr,#line8
ljmp week_disp
xin6:
cjne a,#6,xin7
mov dptr,#line9
ljmp week_disp
xin7:
mov dptr,#line10
week_disp:
mov a,#10001100b
lcall write
lcall fill
ret
tim_pro:              ;年月日
mov a,year1
mov buf,#0
lcall conv
inc buf
mov a,year2
lcall conv
inc buf
mov a,#"/"
mov b,buf
lcall disp
mov a,mon
inc buf
lcall conv
inc buf
mov a,#"/"
mov b,buf
lcall disp
mov a,day
inc buf
lcall conv
ret
tim_pro1:          ;时间
mov a,hh
mov buf1,#5
lcall conv1
inc buf1
mov a,#":"
mov b,buf1
lcall disp1
mov a,mm
inc buf1
lcall conv1
inc buf1
mov a,#":"
mov b,buf1
lcall disp1
mov a,mia
inc buf1
lcall conv1
ret
conv:                  ;年月日转换
mov b,#10
div ab
add a,#30h
push b
mov b,buf
lcall disp
pop b
mov a,b
add a,#30h
inc buf
mov b,buf
lcall disp
ret
conv1:                ;时间转换
mov b,#10
div ab
add a,#30h
push b
mov b,buf1
lcall disp1
pop b
mov a,b
add a,#30h
inc buf1
mov b,buf1
lcall disp1
ret
disp:                     ;年月日显示
push acc
mov a,b
add a,#80h
lcall write
pop acc
lcall writedata    
ret
disp1:                    ;时间显示
push acc
mov a,b
add a,#0c0h
lcall write
pop acc
lcall writedata
ret
string:                  ;字符串显示
cjne a,#1,lin2
lin1:
mov a,#80h
lcall write
ljmp fill
lin2:
mov a,#0c0h
lcall write
fill:
clr a
movc a,@a+dptr
cjne a,#0,lc1
ret
lc1:
lcall writedata
inc dptr
ljmp fill
ret
writedata:
lcall busy
clr enable
setb rs
clr rw
setb enable
mov db0_db7,a
clr enable
ret
cls:
mov a,#01h
clr enable
lcall write
ret
line1:
db "   ",00h
line2:
db "TIME",00h
line4:
db "MON",0h
line5:
db "TUE",0h
line6:
db "WED",0h
line7:
db "THU",0h
line8:
db "FRI",0h
line9:
db "SAT",0h
line10:
db "SUN",0h
line11:
db "Get up time!",00h
line12:
db "K1:+/Time & Bell",00h
line13:
db "K2:-/ON/Off Bell",00h
line14:
db "K3:Set Type/Stop",00h
line15:
db "K4:OK/ Explain",00h
line16:
db "K4:Exit Explain",00h
line17:
db "K5:Lamp/Bell Off",00h
line18:
db "Wish good luck!",00h
line19:
db "YU JUN FENG",00h
initial:
mov a,#00111000b
lcall write
mov a,#00001100b
lcall write
mov a,#00000110b
lcall write
ret
busy:
push acc
busy1:
clr enable
setb rw
clr rs
setb enable
mov a,db0_db7
clr enable
jb acc.7,busy1
pop acc
lcall delay
lcall delay
ret
write:
lcall busy
clr enable
clr rw
clr rs
setb enable
mov db0_db7,a
clr enable
ret
to_int1:                        ;背光中断服务程序
mov th1,#00
mov tl1,#00    
push acc  
push psw
djnz r3,rett1
mov r3,#50
inc 37h
mov a,37h
cjne a,#20,rett1
mov 37h,#00
setb p0.1
rett1:
pop psw
pop acc
reti
to_int:                         ;定时中断服务程序              
push acc
push psw
clr ea
clr tr0
mov a,#183
add a,tl0
mov tl0,a
mov a,#60
addc a,th0
mov th0,a
setb tr0
setb ea  
djnz r4,rett3
cpl p0.0
mov r4,#10              
djnz r1,rett3
inc mia
mov r1,#2
mov a,mia
cjne a,#60,rett3          ;是否到了1秒?
mov mia,#00            
inc mm
mov a,mm
cjne a,#60,rett          
inc hh
mov mm,#00
mov a,hh
cjne a,#24,rett
inc day
inc week
mov hh,#00
mov a,week
cjne a,#8,rett2
mov week,#01
rett2:
mov a,day
cjne a,#32,rett
inc mon
mov day,#01
mov a,mon
cjne a,#13,rett
inc year2
mov mon,#01
mov a,year2
cjne a,#16,rett
mov year2,#05
rett:
mov a,nao
cjne a,#1,rett3
mov a,mm
mov b,lmm
cjne a,b,rett3
mov a,hh
mov b,lhh
cjne a,b,rett3
clr p2.7
rett3:
pop psw
pop acc
reti
delay1:
mov r6,#20
d1:
mov r7,#150
djnz r7,$
djnz r6,d1
djnz r5,delay1
ret
delay:
mov r6,#08
d2:
mov r7,#169
djnz r7,$
djnz r6,d2
ret
end

1: 贴电路 2: 能不能给我发一份
  谢谢了!我想学习一下
  E-mail:guoox@163.com 3: 程序写的有点罗嗦,不同月份天数不同,没作判断会用函数指针不错,但这个程序好像没必要,字符串显示最好用指针

程序中标号中英文混合,显得有点乱

模块化不好,比如显示其实只要写一个定点显示字符和一个定点显示字符串的程序作为公用函数即可(外加一个液晶初始化以及特殊显示程序),不要让其他模块涉及太多的底层操作,以保证模块的封装性(不同功能不同文件,加入工程改下主程序就可编译运行),这样以后程序多了时你会感到很方便的。


随便说说,不要介意哦:-) 4: 还有合理使用#include

主程序(main())最好放前面,一目了然

C中不要用goto(完全可以避免的)

所有的硬件连接应全部用标号,改变硬件时程序只需修改一个地方

合理注释,空行和特殊分隔也是注释 5: 谢谢大哥指点 6: 老师,可以发一份电路给我学习一下么? 7: 给一份sdyx21@tom.com 8: 大哥,能不能给我发一份电路图  zhangrui5102@163.com 9: 哈哈论坛就需要你这样的好心人.才有气氛啊!
不过我也自己做了一时钟程序什么时候也贴上来
10: 我也想要图,谢谢!jian84000@126.com 11: 给我一份原理图。谢谢!botome@126.com 12: 学习一下给个图先,谢了,daming1999@hotmail.com 13: 顶一个!email:daishengjiang@sina.com

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]