新手入门
- 积分
- 10
- 金钱
- 10
- 注册时间
- 2018-4-17
- 在线时间
- 3 小时
|
10金钱
第一个程序
u8 RTC_Get(void)
{
static u16 daycnt=0;
u32 timecount=0;
u32 temp=0;
u16 temp1=0;
timecount=RTC->CNTH;//得到计数器中的值(秒钟数)
timecount<<=16;
timecount+=RTC->CNTL;
temp=timecount/86400; //得到天数(秒钟数对应的)
if(daycnt!=temp)//超过一天了
{
daycnt=temp;
temp1=1970; //从1970年开始
while(temp>=365)
{
if(Is_Leap_Year(temp1))//是闰年
{
if(temp>=366)temp-=366;//闰年的秒钟数
else break;
}
else temp-=365; //平年
temp1++;
}
calendar.w_year=temp1;//得到年份
temp1=0;
while(temp>=28)//超过了一个月
{
if(Is_Leap_Year(calendar.w_year)&&temp1==1)//当年是不是闰年/2月份
{
if(temp>=29)temp-=29;//闰年的秒钟数
else break;
}
else
{
if(temp>=mon_table[temp1])temp-=mon_table[temp1];//平年
else break;
}
temp1++;
}
calendar.w_month=temp1+1; //得到月份
calendar.w_date=temp+1; //得到日期
}
temp=timecount%86400; //得到秒钟数
calendar.hour=temp/3600; //小时
calendar.min=(temp%3600)/60; //分钟
calendar.sec=(temp%3600)%60; //秒钟
calendar.week=RTC_Get_Week(calendar.w_year,calendar.w_month,calendar.w_date);//获取星期
return 0;
}
第二个程序
void Paint_DrawCharAt(Paint* paint, int x, int y, char ascii_char, sFONT* font, int colored) {
int i, j;
unsigned int char_offset = (ascii_char - ' ') * font->Height * (font->Width / 8 + (font->Width % 8 ? 1 : 0));
const unsigned char* ptr = &font->table[char_offset];
for (j = 0; j < font->Height; j++) {
for (i = 0; i < font->Width; i++) {
if (*ptr & (0x80 >> (i % 8))) {
Paint_DrawPixel(paint, x + i, y + j, colored);
}
if (i % 8 == 7) {
ptr++;
}
}
if (font->Width % 8 != 0) {
ptr++;
}
各位大神哥哥们,第一个程序是正点原子的rtc示例程序中得一小段程序,正常用正点原子的lcd屏可以直接输出时间,但我用的是一个电子墨水屏,要用第二个程序中得函数 paint_drawcharat()输出,老师说得把时钟的那些数转成asc码才能输出,但我怎么转啊,求帮助
|
最佳答案
查看完整内容[请看2#楼]
u8 AsciiData[20];
AsciiData[0]=calendar.w_year/1000%10+48;
AsciiData[1]=calendar.w_year%1000/100+48;
AsciiData[2]=calendar.w_year%100/10+48;
AsciiData[3]=calendar.w_year%10+48;
AsciiData[4]=calendar.w_month%100/10+48;
AsciiData[5]=calendar.w_month%10+48;
AsciiData[6]=calendar.w_date%100/10+48;
AsciiData[7]=calendar.w_date%10+48;
AsciiData[8]=calendar.hour%100/10+48;
A ...
|