它可以动态显示表盘的转动。
单片机源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "lcd.h"
- #include "usmart.h"
- #include "rtc.h"
- #include "stdio.h"
- #include "string.h"
- #include "math.h"
- #include "beep.h"
- extern const unsigned char gImage_pic16[153600];
- #define PI 3.14
- #define CLOCK_X 100
- #define CLOCK_Y 180
- int main(void)
- {
- RTC_TimeTypeDef RTC_TimeStruct;
- RTC_DateTypeDef RTC_DateStruct;
- int i;
- u8 t=0;
- u8 sh[10];
- u8 ch[10];
- u8 zh[10];
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
- delay_init(168); //初始化延时函数
- uart_init(115200); //初始化串口波特率为115200
-
- usmart_dev.init(84); //初始化USMART
- LED_Init(); //初始化LED
- LCD_Init(); //初始化LCD
- My_RTC_Init(); //初始化RTC
- //BEEP_Init();
-
- RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits,0); //配置WAKE UP中断,1秒钟中断一次
-
- POINT_COLOR = LIGHTBLUE;
- show_pic_rgb565(0,0,240,320, gImage_pic16);
-
- for(i=0; i<10; i++)
- LCD_Draw_Circle(100,180,i);
- RTC_Set_AlarmA(2,10,23,30); //设置闹钟时间(按星期闹铃,24小时制)
-
- //画圆
- LCD_Draw_Circle(CLOCK_X,CLOCK_Y,99);
- LCD_Draw_Circle(CLOCK_X,CLOCK_Y,100);
- LCD_Draw_Circle(CLOCK_X,CLOCK_Y,101);
- for(i=0;i<360;i+=6)
- {
- if(i%30)
- //画线 -->画任意角度的直线
- //x1,y1:起点坐标
- //x2,y2:终点坐标
- //void LCD_Draw_Line(u16 x1, u16 y1, u16 x2, u16 y2,u16 color)
- LCD_Draw_Line(CLOCK_X+95*sin(i*PI/180), CLOCK_Y-95*cos(i*PI/180), CLOCK_X+100*sin(i*PI/180), CLOCK_Y-100*cos(i*PI/180), WHITE);//小时的刻度
- else
- LCD_Draw_Line(CLOCK_X+85*sin(i*PI/180), CLOCK_Y-85*cos(i*PI/180), CLOCK_X+100*sin(i*PI/180), CLOCK_Y-100*cos(i*PI/180), WHITE);//分的刻度
-
- }
- printf("%s\t%s\r\n",__DATE__,__TIME__);
- //BEEP = 1;
- // GPIO_SetBits(GPIOF,GPIO_Pin_8); //BEEP引脚拉高, 等同BEEP=1;
- // delay_ms(300); //延时300ms
- while(1)
- {
- t++;
- if((t%10)==0) //每100ms更新一次显示数据
- {
- // lcd_show_time();
- RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
- sprintf((char *)sh,"Time:%02d:%02d:%02d",RTC_TimeStruct.RTC_Hours,RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds );
- LCD_ShowString(0,0,200,20,24,sh);
-
- RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
- sprintf((char *)ch,"Data:20%02d-%02d-%02d",RTC_DateStruct.RTC_Year,RTC_DateStruct.RTC_Month,RTC_DateStruct.RTC_Date);
- LCD_ShowString(0,24,200,20,24,ch);
- sprintf((char *)zh,"Week:%d",RTC_DateStruct.RTC_WeekDay);
- LCD_ShowString(0,48,200,20,24,zh);
- BEEP = 1;
- delay_xms(100);
- delay_xms(100);
-
- BEEP = 0;
-
- //_window_obj* twin=0;
-
- }
- }
- }
复制代码
所有程序51hei提供下载:
RTC.7z
(966.26 KB, 下载次数: 7)
|