⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clock.lst

📁 利用热释红外传感器、12C887和PIC单片机制作的智能电子时钟
💻 LST
字号:
     1: #include <pic.h>

     2: #include "lcd.h";

     3: #include "delay.h";

     4: 

     5: /////////////   SUNROUTINE DECLARE   /////////////

     6: extern  _12c887_write(unsigned char ADDRESS,unsigned char DATA);

     7: extern  _12c887_read(unsigned char ADDRESS);

     8: void mcu_init(void);

     9: void ReadKey(void);

    10: void GetTimeDate(void);

    11: 

    12: ////////////   VARIABLE DEFINITIONS   ////////////

    13: unsigned static char second,minute,hour,weekday,monthday,month,year;

    14: extern SECOND,SECOND_ALARM,MINUTE,MINUTE_ALARM,HOUR,HOUR_ALARM,DayOfWeek,DayOfMonth,MONTH,YEAR,CENTURY,REGA,REGB,REGC,REGD;

    15: unsigned static char TimeShow[11];

    16: unsigned static char DateShow[11];

    17: 

    18: //////////// SUBSTITUTION DEFINITIONS  ///////////

    19:         // input substitution

    20: #define Menu_in      RB3

    21: #define Up_in        RB4

    22: #define Down_in      RB5

    23: ////////////   VARIABLE DEFINITIONS   ////////////

    24:         // input,used for signal switch or operation key  read

    25: static unsigned char   Menu_Value;

    26: static unsigned char   Up_Value;

    27: static unsigned char   Down_Value;

    28: static bit             Menu;

    29: static bit             Menu_USED;

    30: static bit             Up;

    31: static bit             Up_USED;

    32: static bit             Down;

    33: static bit             Down_USED;

    34: /////////////////// SUBROUTINE ///////////////////

    35: void mcu_init()

    36: {

    37:     // initialize I/O port

    38:     ADCON1=0x07;

    39:     TRISA=0x00;         // PORTA as DO

    40:     RBPU=0x00;          // enable portB weak up

    41:     TRISB=0xff;         // PORTB as DI

    42:     TRISC=0x00;         // PORTC as D0

    43:     TRISD=0x00;         // PORTD as D0

    44:     PORTA=0x00;         // clear port A,B,C

    45:     PORTB=0x00;

    46:     PORTC=0x00;

    47:     PORTD=0x00;

    48:     // initialize timer1

    49:     T1CON=0x01;         // Prescale value is 1:1; internal clock,start TMR1

    50:     TMR1IE=1;           // enable TMR1 interrupt

    51:     // initialize general interrupt

    52:     GIE=1;              // enables all unmasked interrupts

    53:     PEIE=1;             // enables all unmasked peripheral interrupts

    54: }

    55: 

    56: void interrupt TMR1_INT(void)

    57:         // TMR1 or INT interrupt

    58: {

    59: 

    60:     if  (TMR1IF&&TMR1IE)

    61:         {

    62:                 // TMR1 interrupt

    63:             TMR1IF=0;

    64:             TMR1H=216;                                  // 10ms per TMR1 interrupt

    65:             TMR1ON=1;                                   // TMR1 start to work

    66:             ReadKey();                                  // read the key of operation

    67:         }

    68: }

    69: 

    70: 

    71: void ReadKey(void)

    72:         // read keys

    73: {

    74:     Menu_Value<<=1;     // read menu key

    75:     if (Menu_in==0) Menu_Value=Menu_Value|0x01;

    76:     Menu_Value=Menu_Value&0xff;

    77:     if (Menu_Value==0xff) Menu=1;

    78:         else if (Menu_Value==0x00) Menu=0,Menu_USED=0;

    79: 

    80:     Up_Value<<=1;     // read up key

    81:     if (Up_in==0) Up_Value=Up_Value|0x01;

    82:     Up_Value=Up_Value&0xff;

    83:     if (Up_Value==0xff) Up=1;

    84:         else if (Up_Value==0x00) Up=0,Up_USED=0;

    85: 

    86:     Down_Value<<=1;     // read down key

    87:     if (Down_in==0) Down_Value=Down_Value|0x01;

    88:     Down_Value=Down_Value&0xff;

    89:     if (Down_Value==0xff) Down=1;

    90:         else if (Down_Value==0x00) Down=0,Down_USED=0;

    91: }

    92: //////////////////////////////////////////////////

    93: /*void mcu_init(void)

    94: {

    95:     ADCON1=0x07;

    96:     TRISA=0x00;         // PORTA as DO

    97:     TRISB=0x00;         // PORTB as D0

    98:     TRISC=0x00;         // PORTC as D0

    99:     TRISD=0x00;         // PORTD as D0

   100:     PORTA=0x00;         // clear port A,B,C

   101:     PORTB=0x00;

   102:     PORTC=0x00;

   103:     PORTD=0x00;

   104: }*/

   105: 

   106: void GetTimeDate(void)

   107: {

   108:     second=_12c887_read(0x00);

   109:     minute=_12c887_read(0x02);

   110:     hour=_12c887_read(0x04);

   111:     weekday=_12c887_read(0x06);

   112:     monthday=_12c887_read(0x07);

   113:     month=_12c887_read(0x08);

   114:     year=_12c887_read(0x09);

   115: }

   116: 

   117: void Change(void)

   118: {

   119:     TimeShow[0]=((hour>>4)+0x30);

   120:     TimeShow[1]=((hour&0x0f)+0x30);

   121:     TimeShow[2]=':';

   122:     TimeShow[3]=' ';

   123:     TimeShow[4]=((minute>>4)+0x30);

   124:     TimeShow[5]=((minute&0x0f)+0x30);

   125:     TimeShow[6]=':';

   126:     TimeShow[7]=' ';

   127:     TimeShow[8]=((second>>4)+0x30);

   128:     TimeShow[9]=((second&0x0f)+0x30);

   129:     TimeShow[10]=' ';

   130: 

   131:     DateShow[0]=((year>>4)+0x30);

   132:     DateShow[1]=((year&0x0f)+0x30);

   133:     DateShow[2]='.';

   134:     DateShow[3]=((month>>4)+0x30);

   135:     DateShow[4]=((month&0x0f)+0x30);

   136:     DateShow[5]='.';

   137:     DateShow[6]=((monthday>>4)+0x30);

   138:     DateShow[7]=((monthday&0x0f)+0x30);

   139:     DateShow[8]=',';

   140:     DateShow[9]=((weekday&0x0f)+0x30);

   141:     DateShow[10]=' ';

   142: }

   143: 

   144: main()

   145: {

   146:     DelayMs(50);

   147:     mcu_init();                     // initialize MCU

   148:     _12c887_init();               // initialize RTC 12c887

   149:     lcd_init();                     // initialize LCD

   150:     lcd_puts("TIME");

   151:     lcd_goto(0xc0);

   152:     lcd_puts("DATE");

   153: while(1)

   154:     {

   155:     if (Menu==1&&Menu_USED==0)

   156:         {

   157:             Menu_USED=1;

   158: 

   159:         }

   160:     else {;}

   161:     if (Up==1&&Down==1&&Up_USED==0&&Down_USED==0)

   162:         {

   163:             Up_USED=1;

   164:             Down_USED=1;

   165:         }

   166:     else {;}

   167:     GetTimeDate();

   168:     if (minute==0x00||minute==0x30) lcd_light();

   169:     else lcd_dark();

   170:     Change();

   171:     lcd_goto(0x85);

   172:     lcd_puts(TimeShow);

   173:     lcd_goto(0xc5);

   174:     lcd_puts(DateShow);

   175:     }

   176: }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -