• Mini2440裸机RTC时钟驱动转化为字符串显示


    已经将16进制转化为字符串,能直接在液晶屏上显示。

    // rtc.h
    // S3C2440 has rtc 
    // 2015.12.17 by Huangtao
    
    #ifndef __RTC_H__
    #define __RTC_H__
    
    //#define __BIG_ENDIAN
    // 测试发现是使用小端
    
    // RTC
    // 大端
    #ifdef __BIG_ENDIAN
    #define rRTCCON    (*(volatile unsigned char *)0x57000043)    //RTC control
    #define rTICNT     (*(volatile unsigned char *)0x57000047)    //Tick time count
    #define rRTCALM    (*(volatile unsigned char *)0x57000053)    //RTC alarm control
    #define rALMSEC    (*(volatile unsigned char *)0x57000057)    //Alarm second
    #define rALMMIN    (*(volatile unsigned char *)0x5700005b)    //Alarm minute
    #define rALMHOUR   (*(volatile unsigned char *)0x5700005f)    //Alarm Hour
    #define rALMDATE   (*(volatile unsigned char *)0x57000063)    //Alarm date   //edited by junon
    #define rALMMON    (*(volatile unsigned char *)0x57000067)    //Alarm month
    #define rALMYEAR   (*(volatile unsigned char *)0x5700006b)    //Alarm year
    #define rRTCRST    (*(volatile unsigned char *)0x5700006f)    //RTC round reset
    #define rBCDSEC    (*(volatile unsigned char *)0x57000073)    //BCD second
    #define rBCDMIN    (*(volatile unsigned char *)0x57000077)    //BCD minute
    #define rBCDHOUR   (*(volatile unsigned char *)0x5700007b)    //BCD hour
    #define rBCDDATE   (*(volatile unsigned char *)0x5700007f)    //BCD date  //edited by junon
    #define rBCDDAY    (*(volatile unsigned char *)0x57000083)    //BCD day   //edited by junon
    #define rBCDMON    (*(volatile unsigned char *)0x57000087)    //BCD month
    #define rBCDYEAR   (*(volatile unsigned char *)0x5700008b)    //BCD year
    #else //Little Endian
    #define rRTCCON    (*(volatile unsigned char *)0x57000040)    //RTC control
    #define rTICNT     (*(volatile unsigned char *)0x57000044)    //Tick time count
    #define rRTCALM    (*(volatile unsigned char *)0x57000050)    //RTC alarm control
    #define rALMSEC    (*(volatile unsigned char *)0x57000054)    //Alarm second
    #define rALMMIN    (*(volatile unsigned char *)0x57000058)    //Alarm minute
    #define rALMHOUR   (*(volatile unsigned char *)0x5700005c)    //Alarm Hour
    #define rALMDATE   (*(volatile unsigned char *)0x57000060)    //Alarm date  // edited by junon
    #define rALMMON    (*(volatile unsigned char *)0x57000064)    //Alarm month
    #define rALMYEAR   (*(volatile unsigned char *)0x57000068)    //Alarm year
    #define rRTCRST    (*(volatile unsigned char *)0x5700006c)    //RTC round reset
    #define rBCDSEC    (*(volatile unsigned char *)0x57000070)    //BCD second
    #define rBCDMIN    (*(volatile unsigned char *)0x57000074)    //BCD minute
    #define rBCDHOUR   (*(volatile unsigned char *)0x57000078)    //BCD hour
    #define rBCDDATE   (*(volatile unsigned char *)0x5700007c)    //BCD date  //edited by junon
    #define rBCDDAY    (*(volatile unsigned char *)0x57000080)    //BCD day   //edited by junon
    #define rBCDMON    (*(volatile unsigned char *)0x57000084)    //BCD month
    #define rBCDYEAR   (*(volatile unsigned char *)0x57000088)    //BCD year
    #endif 
    
    struct RTC_Date
    {
        unsigned short year;
        unsigned char month, week, day;
        unsigned char hour, minute, second;
    
    };
    
    void RTC_Time_Set(void);
    // 获得时间,BCD16进制和转化成字符串
    void RTC_Time_Get(struct RTC_Date *getDate, unsigned char dateString[]);
    
    
    #endif
    // rtc.c
    // S3C2440 has rtc 
    // 2015.12.17 by Huangtao
    
    #include "rtc.h"
    
    //char *week_name[7]={ "Sun","Mon", "Tues", "Wed", "Thu","Fri", "Sat" };
    
    void RTC_Time_Set(void)
    {
        struct RTC_Date setDate;
        setDate.year=0x15;        
        setDate.month=0x12;    
        setDate.day=0x18;    
        setDate.week=0x4;                    
        setDate.hour=0x15;        
        setDate.minute=0x054;        
        setDate.second=0x00;
    
        rRTCCON = 0x01 ;        //RTC read and write enable
    
        rBCDYEAR = setDate.year;        //
        rBCDMON  = setDate.month;        //
        rBCDDATE = setDate.day;            //
        rBCDDAY  = setDate.week;        // 星期
        rBCDHOUR = setDate.hour;        // 小时
        rBCDMIN  = setDate.minute;        //
        rBCDSEC  = setDate.second;        //
        
        rRTCCON = 0x00 ;        //RTC read and write disable
    }
    
    void RTC_Time_Get(struct RTC_Date *getDate, unsigned char *dateString)
    {
        rRTCCON = 0x01;        //RTC read and write enable
    
        getDate->year = 0x2000+rBCDYEAR;//
        getDate->month = rBCDMON;        //
        getDate->day = rBCDDATE;        //
        getDate->week = rBCDDAY;        // 星期    
        getDate->hour = rBCDHOUR;        // 小时
        getDate->minute = rBCDMIN;        //
        getDate->second = rBCDSEC;        //
        
        rRTCCON = 0x00;        //RTC read and write disable
    
    
        dateString[0] = ((getDate->year >> 12) & 0xf)%10 + '0';
        dateString[1] = ((getDate->year >> 8) & 0x0f)%10 + '0';
        dateString[2] = ((getDate->year >> 4) & 0x00f)%10 + '0';
        dateString[3] = (getDate->year & 0x000f)%10 + '0';
        dateString[4] = '/';
        dateString[5] = (((getDate->month >> 4) & 0xf)%10 + '0') > '0' ?'1':' ';
        dateString[6] = ((getDate->month >> 0) & 0x0f)%10 + '0';
        dateString[7] = '/';
        dateString[8] = (((getDate->day >> 4) & 0xf)%10 + '0') > '0' ?(((getDate->day >> 4) & 0xf)%10 + '0'):' ';
        dateString[9] = ((getDate->day >> 0) & 0x0f)%10 + '0';
        /*dateString[10] = ' ';
        dateString[11] = (getDate->week & 0xf)%10 + '0';
        dateString[12] = ' ';*/
        dateString[10] = ' ';
        dateString[11] = (((getDate->hour >> 4) & 0xf)%10 + '0') > '0' ?(((getDate->hour >> 4) & 0xf)%10 + '0'):' ';
        dateString[12] = ((getDate->hour >> 0) & 0x0f)%10 + '0';
        dateString[13] = ':';
        dateString[14] = (((getDate->minute >> 4) & 0xf)%10 + '0') > '0' ?(((getDate->minute >> 4) & 0xf)%10 + '0'):' ';
        dateString[15] = ((getDate->minute >> 0) & 0x0f)%10 + '0';
        dateString[16] = ':';
        dateString[17] = (((getDate->second >> 4) & 0xf)%10 + '0') > '0' ?(((getDate->second >> 4) & 0xf)%10 + '0'):' ';
        dateString[18] = ((getDate->second >> 0) & 0x0f)%10 + '0';
        dateString[19] = '';
    }
  • 相关阅读:
    MS SQL Sever数据库还原
    IIS 7.5 配置伪静态
    黑马程序员-out和ref
    黑马程序员-结构
    黑马程序员-ReadInt
    黑马程序员-hashtable
    黑马程序员-冒泡排序
    黑马程序员-快速排序
    黑马程序员-for和foreach
    黑马程序员-集合和索引器
  • 原文地址:https://www.cnblogs.com/ht-beyond/p/5057987.html
Copyright © 2020-2023  润新知