| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 51 人关注过本帖
标题:秒表怎么加中断?能够·暂停,继续,计数
只看楼主 加入收藏
尘曦
Rank: 2
来 自:四川省泸州市
等 级:论坛游民
帖 子:12
专家分:20
注 册:2018-10-28
  问题点数:0  回复次数:0   
秒表怎么加中断?能够·暂停,继续,计数
#include "reg52.h"
#define ucher unsigned char
#define uint unsigned  int                                                                        
typedef unsigned char u8;                                                   

sbit LCD_RW=P2^5;
sbit LCD_RS=P2^6;
sbit LCD_E=P2^7;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
ucher count,fen,miao,hao;
u8   disp[]="11                       ";
ucher code disp1[]="    00:00:0";

void delay(uint c)
{
    uint a,b;
    for (a=0; a<c; a++)
        for (b=0; b<124; b++);            
}

void lcdwrite_com(ucher com)
{
    LCD_E=0;
    LCD_RS=0;
    LCD_RW=0;

    LCD_DATAPINS=com;
    delay(5);

    LCD_E=1;
    delay(5);
    LCD_E=0;

}
void lcdwrite_date(ucher date)
{
    LCD_E=0;
    LCD_RS=1;
    LCD_RW=0;

    LCD_DATAPINS=date;
    delay(5);

    LCD_E=1;
    delay(5);
    LCD_E=0;


}
void init()
{   
    fen=00;
    miao=00;
    hao=00;
    lcdwrite_com(0x38);
    lcdwrite_com(0x38);
    lcdwrite_com(0x38);
    lcdwrite_com(0x0c);
    lcdwrite_com(0x06);
    lcdwrite_com(0x01);
    {
    ucher num;
    lcdwrite_com(0x00+0x80);
    for(num=0;num<16;num++)
        {
        lcdwrite_date(disp[num]);
        }
    lcdwrite_com(0x80+0x40);
    for(num=0;num<11;num++)
        {
        lcdwrite_date(disp1[num]);            
        }
    TMOD=0x01;
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    EA=1;
    ET0=1;
    TR0=1;
}
}
void lcdwrite_fmh1(ucher add,ucher date)
{
    ucher h;
    h=date%10;
    lcdwrite_com(0x80+0x40+add);
    lcdwrite_date(0x30+h);
}

void lcdwrite_fmh(ucher add,ucher date)
{
    ucher s,g;
    s=date/10;
    g=date%10;
    lcdwrite_com(0x80+0x40+add);
    lcdwrite_date(0x30+s);
    lcdwrite_date(0x30+g);        
}         
void main()
{
    init();
    while(1)
    {
        if(count==2)
        {
            count=0;
            hao++;
            if(hao==10)
            {
                hao=0;
                miao++;
                if(miao==60)
                {
                    miao=0;
                    fen++;
                    if(fen==60)
                    {
                        fen=0;     
                    }
                    lcdwrite_fmh(4,fen);   
                }
                lcdwrite_fmh(7,miao);
            }
            lcdwrite_fmh1(10,hao);               
        }
    }
}

void timer0() interrupt 1
{
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    count++;   
}
2018-12-06 20:26







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024472 second(s), 9 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved