代码如下秒为什么不动
- #include<reg51.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit E=P2^2;
- sbit RST=P2^5;
- sbit CLK=P2^6;
- sbit IO=P2^7;
- sbit ACC0=ACC^0;
- sbit ACC7=ACC^7;
- void delay(); //延时程序
- void lcd1602_write_DAT(uchar DAT); //写数据
- void lcd1602_write_CMD(uchar CMD); //写指令
- void lcd1602_init(); //初始话显示屏
- void dis_char(uchar h,uchar l,uchar dat); //显示位置程序
- void dis_str(uchar h,uchar l,uchar *p); //显示字符串
- void dis_num(uchar h,uchar l,uchar num); //显示数字
- void write_bit(uchar dat); //位操作写
- void ds1302_write(uchar add,uchar dat); //写1302
- void ds1302_init(); //初始值
- void init();
- uchar read_bit(); //位操作读
- uchar ds1302_read(uchar add); //读取1302
- uchar BCD_Decimal(uchar bcd);
- uchar miao,fen,shi,ri,yue,nian,zhou;
- void main()
- {
- lcd1602_init();
- ds1302_init();
- //init();
- while(1)
- {
- dis_str(1,1,"20");
- dis_char(1,5,'-');
- dis_char(1,8,'-');
- dis_char(2,7,':');
- dis_char(2,10,':');
- dis_num(1,3,22);
- miao=ds1302_read(0x81);
- dis_num(2,11,miao);
- }
- }
- void delay()
- {
- uchar x,y;
- for(x=0;x<=10;x++)
- for(y=0;y<=20;y++);
- }
- void lcd1602_write_DAT(uchar DAT)
- {
- P0=DAT;
- RS=1;
- RW=0;
- E=0;
- delay();
- E=1;
- delay();
- E=0;
- }
- void lcd1602_write_CMD(uchar CMD)
- {
- P0=CMD;
- RS=0;
- RW=0;
- E=0;
- delay();
- E=1;
- delay();
- E=0;
- }
- void lcd1602_init()
- {
- lcd1602_write_CMD(0x38);//显示模式设置(16*2)显示,5*7点阵
- lcd1602_write_CMD(0x01);//显示清零
- lcd1602_write_CMD(0x06);//显示光标移动设置
- lcd1602_write_CMD(0x0c);//显示开关,光标设置
- }
- void dis_char(uchar h,uchar l,uchar DAT)
- {
- if(h==1)
- {
- lcd1602_write_CMD(0x7F+l);
- }
- if(h==2)
- {
- lcd1602_write_CMD(0xBF+l);
- }
- lcd1602_write_DAT(DAT);
- }
- void dis_str(uchar h,uchar l,uchar *p)
- {
- if(h==1)
- {
- lcd1602_write_CMD(0x7F+l);
- }
- if(h==2)
- {
- lcd1602_write_CMD(0xBF+l);
- }
- while(1)
- {
- if(*p=='\0')break;
- lcd1602_write_DAT(*p);
- p++;
- }
- }
- void dis_num(uchar h,uchar l,uchar num)
- {
- dis_char(h,l,num/10%10+'0');
- dis_char(h,l+1,num%10+'0');
- }
- void write_bit(uchar dat)
- {
- uchar a;
- ACC=dat;
- RST=1;
- for(a=1;a<=8;a++)
- {
- IO=ACC^0;
- CLK=0;
- CLK=1;
- ACC=ACC>>1;
- }
- }
- uchar read_bit()
- {
- uchar a;
- RST=1;
- for(a=1;a<=8;a++)
- {
- ACC7=IO;
- CLK=1;
- CLK=0;
- ACC=ACC>>1;
- }
- return (ACC);
- }
- void ds1302_write(uchar add,uchar dat)
- {
- RST=0;
- CLK=0;
- RST=1;
- write_bit(add);
- write_bit(dat);
- CLK=1;
- RST=0;
- }
- uchar ds1302_read(uchar add)
- {
- uchar temp;
- RST=0;
- CLK=0;
- RST=1;
- write_bit(add);
- temp=read_bit();
- CLK=1;
- RST=0;
- return(temp);
- }
- void ds1302_init()
- {
- RST=0;
- CLK=0;
- ds1302_write(0x8e,0x00);
- ds1302_write(0x80,0x00);
- ds1302_write(0x82,0x00);
- ds1302_write(0x84,0x12);
- ds1302_write(0x86,0x22);
- ds1302_write(0x88,0x04);
- ds1302_write(0x8a,0x01);
- ds1302_write(0x8c,0x20);
- ds1302_write(0x8e,0x80);
- }
复制代码
|