|
基于stc89c52单片机的LCD1602液晶屏显示DS1302时钟程序
并且可以按键调节- #include <REG52.H>
- #include "stdio.h"
- #include "lcd1602.h"
- #include "ds1302.h"
- sbit key1 = P3^0;
- sbit key2 = P3^1;
- sbit key3 = P3^2;
- sbit key4 = P3^3;
- sbit key5 = P3^4;
- sbit key6 = P3^5;
- sbit key7 = P3^6;
- sbit key8 = P3^7;
- void delay_ms(unsigned int ms);
- float n = 0,m = 123.56;
- xdata unsigned char tab[10];
- unsigned char sta;
- //unsigned int k = 1234;
- //unsigned char int_time;
- void main()
- {
- LCD_Init();
- Ds1302_Init();
- while(1)
- {
-
- Ds1302_Read_Time();//先读取DS1302的数据
- sprintf (tab,"%02bd:%02bd:%02bd",time_buf1[4],time_buf1[5],time_buf1[6]); //shi fen miao
- LCD_Staing(2,5,tab);
-
- //sprintf (tab,"20%02bd/%02bd/%02bd",time_buf[1],time_buf[2],time_buf[3]);
- //LCD_Staing(1,5,tab);
-
-
- if(key1 == 0)
- {
- while (!key1);
- sta++;
- if(sta>5)
- sta=0;
- }
- if(sta == 0)//时间调整
- {
- if(key2 == 0)
- {
- while (!key1);
- time_buf1[4]++;
- if(time_buf1[4]>23)
- {
- time_buf1[4] = 0;
- }
- Ds1302_Write_Time();
- }
-
- if(key3 == 0)
- {
- while (!key2);
-
- if(time_buf1[4]>0)
- {
- time_buf1[4] --;
- }else
- {
- time_buf1[4]=23;
- }
- Ds1302_Write_Time();
- }
-
-
- }
-
-
- if(sta == 1)
- {
-
- }
-
-
- }
- }
- void delay_ms(unsigned int ms)
- {
- unsigned char i;
- while(ms--)
- {
- for(i = 0;i<123;i++);
- }
- }
复制代码
|
|