1 |   //***************************************************************************** |
2 |   // |
3 |   //  File  Name    :  'Main.c' |
4 |   //  Title                :  Itronove  hodiny  |
5 |   #define  __PIC18F8720A__ |
6 |   //  Author              :  http://www.prochazka.zde.cz  -&rsaquo   hacesoft  2017 |
7 |   //  Created            :  24-12-2016,  15:00 |
8 |   //  Revised            :  11-05-2017,  10:22 |
9 |   //  Version            :  1.0 |
10 |   //  Target  MCU   :  PIC  18F8720 |
11 |   // |
12 |   //  This  code  is  distributed  under  the  GNU  Public  License |
13 |   //  Vsechny  informace  jsou  zahrnuty  pod  GPL  licenci,  pokud  není  explicitne  uveden  jiný  typ  licence. |
14 |   //  Pouzivání  techto  stránek  ke  komercním  úcelum  lze  jen  se  souhlasem  autora. |
15 |   //  Vsechna  práva  vyhrazena  (c)  1997  -  2017  hacesoft. |
16 |   // |
17 |   |
18 |   //***************************************************************************** |
19 |   //  https://gputils.sourceforge.io/html-help/PIC18F8720-conf.html |
20 |   /**  C  O  N  F  I  G  U  R  A  T  I  O  N    B  I  T  S  ************   config  bits  is  0x  21BA   ******************/ |
21 |   //  PIC18F8720  Configuration  Bit  Settings |
22 |   |
23 |   //  'C'  source  line  config  statements |
24 |   |
25 |   //  CONFIG1H |
26 |   #pragma  config  OSC  =  ECIO        //  Oscillator  Selection  bits  (EC  oscillator  w/  OSC2  configured  as  RA6) |
27 |   #pragma  config  OSCS  =  OFF        //  Oscillator  System  Clock  Switch  Enable  bit  (Oscillator  system  clock  switch  option  is  disabled  (main  oscillator  is  source)) |
28 |   |
29 |   //  CONFIG2L |
30 |   #pragma  config  PWRT  =  OFF        //  Power-up  Timer  Enable  bit  (PWRT  disabled) |
31 |   #pragma  config  BOR  =  OFF         //  Brown-out  Reset  Enable  bit  (Brown-out  Reset  disabled) |
32 |   #pragma  config  BORV  =  25         //  Brown-out  Reset  Voltage  bits  (VBOR  set  to  2.7V) |
33 |   |
34 |   //  CONFIG2H |
35 |   #pragma  config  WDT  =  OFF         //  Watchdog  Timer  Enable  bit  (WDT  disabled  (control  is  placed  on  the  SWDTEN  bit)) |
36 |   #pragma  config  WDTPS  =  128       //  Watchdog  Timer  Postscale  Select  bits  (1:128) |
37 |   |
38 |   //  CONFIG3L |
39 |   #pragma  config  MODE  =  MC         //  Processor  Mode  Select  bits  (Microcontroller  mode) |
40 |   #pragma  config  WAIT  =  OFF        //  External  Bus  Data  Wait  Enable  bit  (Wait  selections  unavailable  for  table  reads  and  table  writes) |
41 |   |
42 |   //  CONFIG3H |
43 |   #pragma  config  CCP2MUX  =  OFF     //  CCP2  Mux  bit  (CCP2  is  multiplexed  with  RB3  in  Extended  Microcontroller,  Microprocessor  or  Microprocessor  with  Boot  Block  mode.  Or  with  RE7  in  Microcontroller  mode.) |
44 |   |
45 |   //  CONFIG4L |
46 |   #pragma  config  STVR  =  OFF        //  Stack  Full/Underflow  Reset  Enable  bit  (Stack  full/underflow  will  not  cause  Reset) |
47 |   #pragma  config  LVP  =  OFF         //  Low-Voltage  ICSP  Enable  bit  (Low-voltage  ICSP  disabled) |
48 |   #pragma  config  DEBUG  =  OFF        //DEBUG:  Background  Debugger  Enable  bit |
49 |                                        //1  =  Background  debugger  disabled.  RB6  and  RB7  configured  as  general  purpose  I/O  pins. |
50 |                                        //0  =  Background  debugger  enabled.  RB6  and  RB7  are  dedicated  to  In-Circuit  Debug. |
51 |   |
52 |   |
53 |   //  CONFIG5L |
54 |   #pragma  config  CP0  =  OFF         //  Code  Protection  bit  (Block  0  (000200-003FFFh)  not  code-protected) |
55 |   #pragma  config  CP1  =  OFF         //  Code  Protection  bit  (Block  1  (004000-007FFFh)  not  code-protected) |
56 |   #pragma  config  CP2  =  OFF         //  Code  Protection  bit  (Block  2  (008000-00BFFFh)  not  code-protected) |
57 |   #pragma  config  CP3  =  OFF         //  Code  Protection  bit  (Block  3  (00C000-00FFFFh)  not  code-protected) |
58 |   #pragma  config  CP4  =  OFF         //  Code  Protection  bit  (Block  4  (010000-013FFFh)  not  code-protected) |
59 |   #pragma  config  CP5  =  OFF         //  Code  Protection  bit  (Block  5  (014000-017FFFh)  not  code-protected) |
60 |   #pragma  config  CP6  =  OFF         //  Code  Protection  bit  (Block  6  (018000-01BFFFh)  not  code-protected) |
61 |   #pragma  config  CP7  =  OFF         //  Code  Protection  bit  (Block  7  (01C000-01FFFFh)  not  code-protected) |
62 |   |
63 |   //  CONFIG5H |
64 |   #pragma  config  CPB  =  OFF         //  Boot  Block  Code  Protection  bit  (Boot  Block  (000000-0001FFh)  not  code-protected) |
65 |   #pragma  config  CPD  =  OFF         //  Data  EEPROM  Code  Protection  bit  (Data  EEPROM  not  code-protected) |
66 |   |
67 |   //  CONFIG6L |
68 |   #pragma  config  WRT0  =  OFF        //  Write  Protection  bit  (Block  0  (000200-003FFFh)  not  write-protected) |
69 |   #pragma  config  WRT1  =  OFF        //  Write  Protection  bit  (Block  1  (004000-007FFFh)  not  write-protected) |
70 |   #pragma  config  WRT2  =  OFF        //  Write  Protection  bit  (Block  2  (008000-00BFFFh)  not  write-protected) |
71 |   #pragma  config  WRT3  =  OFF        //  Write  Protection  bit  (Block  3  (00C000-00FFFFh)  not  write-protected) |
72 |   #pragma  config  WRT4  =  OFF        //  Write  Protection  bit  (Block  4  (010000-013FFFh)  not  write-protected) |
73 |   #pragma  config  WRT5  =  OFF        //  Write  Protection  bit  (Block  5  (014000-017FFFh)  not  write-protected) |
74 |   #pragma  config  WRT6  =  OFF        //  Write  Protection  bit  (Block  6  (018000-01BFFFh)  not  write-protected) |
75 |   #pragma  config  WRT7  =  OFF        //  Write  Protection  bit  (Block  7  (01C000-01FFFFh)  not  write-protected) |
76 |   |
77 |   //  CONFIG6H |
78 |   #pragma  config  WRTC  =  OFF        //  Configuration  Register  Write  Protection  bit  (Configuration  registers  (300000-3000FFh)  not  write-protected) |
79 |   #pragma  config  WRTB  =  OFF        //  Boot  Block  Write  Protection  bit  (Boot  Block  (000000-0001FFh)  not  write-protected) |
80 |   #pragma  config  WRTD  =  OFF        //  Data  EEPROM  Write  Protection  bit  (Data  EEPROM  not  write-protected) |
81 |   |
82 |   //  CONFIG7L |
83 |   #pragma  config  EBTR0  =  OFF       //  Table  Read  Protection  bit  (Block  0  (000200-003FFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
84 |   #pragma  config  EBTR1  =  OFF       //  Table  Read  Protection  bit  (Block  1  (004000-007FFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
85 |   #pragma  config  EBTR2  =  OFF       //  Table  Read  Protection  bit  (Block  2  (008000-00BFFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
86 |   #pragma  config  EBTR3  =  OFF       //  Table  Read  Protection  bit  (Block  3  (00C000-00FFFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
87 |   #pragma  config  EBTR4  =  OFF       //  Table  Read  Protection  bit  (Block  4  (010000-013FFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
88 |   #pragma  config  EBTR5  =  OFF       //  Table  Read  Protection  bit  (Block  5  (014000-017FFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
89 |   #pragma  config  EBTR6  =  OFF       //  Table  Read  Protection  bit  (Block  6  (018000-01BFFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
90 |   #pragma  config  EBTR7  =  OFF       //  Table  Read  Protection  bit  (Block  7  (01C000-01FFFFh)  not  protected  from  table  reads  executed  in  other  blocks) |
91 |   |
92 |   //  CONFIG7H |
93 |   #pragma  config  EBTRB  =  OFF       //  Boot  Block  Table  Read  Protection  bit  (Boot  Block  (000000-0001FFh)  not  protected  from  table  reads  executed  in  other  blocks) |
94 |   |
95 |   //  #pragma  config  statements  should  precede  project  file  includes. |
96 |   //  Use  project  enums  instead  of  #define  for  ON  and  OFF. |
97 |   |
98 |   //#pragma  config  SOSCSEL  =  DIG |
99 |   |
100 |   #include &lsaquo xc.h&rsaquo |
101 |   //  #pragma  config  statements  should  precede  project  file  includes. |
102 |   //  Use  project  enums  instead  of  #define  for  ON  and  OFF. |
103 |   //*****************************************************************************  |
104 |   |
105 |   /* |
106 |     *  Excellent  CRC  code. |
107 |   |
108 |   //  Update  the  CRC  for  transmitted  and  received  data  using |
109 |   //  the  CCITT  16bit  algorithm  (X^16  +  X^12  +  X^5  +  1). |
110 |   unsigned  char  ser_data; |
111 |   static  unsigned  int  crc; |
112 |   crc  =  (unsigned  char)(crc &rsaquo &rsaquo   8)  |  (crc &lsaquo &lsaquo   8);  |
113 |   crc  ^=  ser_data; |
114 |   crc  ^=  (unsigned  char)(crc  &  0xff) &rsaquo &rsaquo   4; |
115 |   crc  ^=  (crc &lsaquo &lsaquo   8) &lsaquo &lsaquo   4; |
116 |   crc  ^=  ((crc  &  0xff) &lsaquo &lsaquo   4) &lsaquo &lsaquo   1; |
117 |     *  |
118 |     *  */ |
119 |   //***************************************************************************** |
120 |   #include &lsaquo string.h&rsaquo |
121 |   #include &lsaquo stdio.h&rsaquo |
122 |   #include &lsaquo stdlib.h&rsaquo |
123 |   #include &lsaquo stdint.h&rsaquo   //uint8_t,  uint16_t,  uint32_t |
124 |   |
125 |   #include  "Main.h" |
126 |   #include  "hsv.h" |
127 |   #include  "display.h" |
128 |   #include  "keyboard.h" |
129 |   #include  "rtc.h" |
130 |   #include  "ledI2C.h" |
131 |   #include &lsaquo time.h&rsaquo |
132 |   #include  "i2c.h" |
133 |   #include  "eeprom.h" |
134 |   |
135 |   #ifdef  __PIC18F8720A__ |
136 |        #include &lsaquo pic18f8720.h&rsaquo |
137 |        #warning  including  .....   -&rsaquo &rsaquo   PIC18F8720A |
138 |   #endif |
139 |   //***************************************************************************** |
140 |   |
141 |   void  main(){ |
142 |        TTL_GLOW_off(); |
143 |        _init_display(); |
144 |        ReadEEprom(); |
145 |        InitMasterPort(_HW); |
146 |        InitMasterPort(_SW); |
147 |        InitIO_PCA9633_HW(adress_LED_IC3); |
148 |        srand  (TMR0);     |
149 |        InitIO_PCA9633_HW(adress_LED_IC4); |
150 |        InitIO_PCA9633_HW(adress_LED_IC5); |
151 |        InitIO_PCA9633_HW(adress_LED_IC2);     |
152 |        InitIO_PCA9633_SW(adress_LED_IC6); |
153 |        InitIO_PCA9633_SW(adress_LED_IC7); |
154 |        SetLightHua(); |
155 |        _dtLeft_UP(_CLEAR); |
156 |        _dtLeft_DOWN(_CLEAR); |
157 |        _dtRight_UP(_CLEAR); |
158 |        _dtRight_DOWN(_CLEAR); |
159 |        init_RTC(); |
160 |        init_keyboard_PCA955PW(); |
161 |        _initInterrupt(); |
162 |        |
163 |        __delay_ms(100); |
164 |        PrintPomlcka(_ALL); |
165 |        __delay_ms(5000); |
166 |        _dtLeft_UP(_SET); |
167 |        _dtLeft_DOWN(_SET); |
168 |        _dtRight_UP(_SET); |
169 |        _dtRight_DOWN(_SET); |
170 |        |
171 |        //Edit_Podsvetleni(); |
172 |        for(;;)  { |
173 |            ReadRTC(); |
174 |            _hour_raw  (decode_segment(_DateTimeDS3231.Hour_10),decode_segment(_DateTimeDS3231.Hour)); |
175 |            _minut_raw  (decode_segment(_DateTimeDS3231.Minutes_10),decode_segment(_DateTimeDS3231.Minutes)); |
176 |            //BitClear(TTL_SecondLoC_LAT,  TTL_Segment_DT_C); |
177 |            _second_raw  (decode_segment(_DateTimeDS3231.Seconds_10),decode_segment(_DateTimeDS3231.Seconds)); |
178 |            Menu_Keyboard();           |
179 |        } |
180 |   } |
181 |   |
182 |   |
183 |   |