| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 746 人关注过本帖
标题:秒表慢了,这是什么情况?求解
只看楼主 加入收藏
尘曦
Rank: 2
来 自:四川省泸州市
等 级:论坛游民
帖 子:14
专家分:20
注 册:2018-10-28
收藏
 问题点数:0 回复次数:0 
秒表慢了,这是什么情况?求解
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS=P2^6;  
sbit LCD_RW=P2^5;
sbit LCD_E=P2^7;
sbit k2=P3^0;

long int count,count1;
char mil,sec,min,mil1,sec1,min1;

unsigned char code table[ ]="          miaobiao  ";
unsigned char code table1[ ]="    00:00:0   ";

void delay(uint z)
{
        uchar j,k;
        for(j=z;j>0;j--)
        for(k=256;k>0;k--);
}
void write_com(uchar com)
{
        LCD_RS=0;
        LCD_E=0;
        LCD_RW=0;
        LCD_DATAPINS=com;
        delay(5);
        LCD_E=1;
        delay(5);
        LCD_E=0;
}

void write_date(uchar date)
{
        LCD_RS=1;
        LCD_E=0;
        LCD_RW=0;
        LCD_DATAPINS=date;
        delay(5);
        LCD_E=1;
        delay(5);
        LCD_E=0;
}

void init()
{
        uchar num;
        LCD_E=0;
        write_com(0x38);
        write_com(0x0c);
        write_com(0x06);
        write_com(0x01);
        write_com(0x80);
        for(num=0;num<20;num++)
        {
                write_date(table[num]);
                delay(5);
        }
        write_com(0x80+0x40);
        for(num=0;num<12;num++)
        {
                write_date(table1[num]);
                delay(5);
        }
        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;
        ET0=1;
        EX0=1;
        TR0=0;
}

void write_min(uchar add,uchar date)
{
        uchar one,two;
        one=date/10;
        two=date%10;
        write_com(0x80+0x40+add);
        write_date(0x30+one);
        write_date(0x30+two);
}

void write_sec(uchar add,uchar date)
{
        uchar three,four;
        three=date/10;
        four=date%10;
        write_com(0x80+0x40+add);
        write_date(0x30+three);
        write_date(0x30+four);
}

void write_mil(uchar add,uchar date)
{
        uchar five;
        five=date%10;
        write_com(0x80+0x40+add);
        write_date(0x30+five);
}

void zjs()
{
        if(count==2)
        {
        delay(5);
                count=0;
                mil++;
                if(mil==10)
                {
                        delay(5);
                        mil=0;
                        sec++;
                        if(sec==60)
                        {
                                delay(5);
                                sec=0;
                                min++;
                                if(min==60)
                                {
                                        delay(5);
                                        min=0;
                                        mil=0;         
                                }
                        }
                }
        write_min(4,min);
        write_sec(7,sec);
        write_mil(10,mil);                        
        }
}

void main()
{
        init();
        while(1)
        {
                zjs();
        }
}

void int0() interrupt 0  
{
        delay(10);
        TR0=~TR0;
}

void timer0() interrupt 1
{
        count++;
}
搜索更多相关主题的帖子: void delay date num add 
2018-12-19 20:55
快速回复:秒表慢了,这是什么情况?求解
数据加载中...
 
   



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

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