Rev 193 Rev 195
1 //////// Standard Header file for the PIC16F628 device //////////////// 1 //////// Standard Header file for the PIC16F628 device ////////////////
2 #device PIC16F819 2 #device PIC16F819
3 #nolist 3 #nolist
4 //////// Program memory: 2048x14 Data RAM: 224 Stack: 8 4 //////// Program memory: 2048x14 Data RAM: 224 Stack: 8
5 //////// I/O: 16 Analog Pins: 0 5 //////// I/O: 16 Analog Pins: 0
6 //////// Data EEPROM: 112 6 //////// Data EEPROM: 112
7 //////// C Scratch area: 20 ID Location: 2000 7 //////// C Scratch area: 20 ID Location: 2000
8 //////// Fuses: LP,XT,HS,EC,NOWDT,WDT,NOPUT,PUT,PROTECT,PROTECT_50% 8 //////// Fuses: LP,XT,HS,EC,NOWDT,WDT,NOPUT,PUT,PROTECT,PROTECT_50%
9 //////// Fuses: PROTECT_75%,NOPROTECT,NOBROWNOUT,BROWNOUT,MCLR,NOMCLR,LVP 9 //////// Fuses: PROTECT_75%,NOPROTECT,NOBROWNOUT,BROWNOUT,MCLR,NOMCLR,LVP
10 //////// Fuses: NOLVP,ER_IO,INTRC_IO,ER,INTRC,CPD,NOCPD 10 //////// Fuses: NOLVP,ER_IO,INTRC_IO,ER,INTRC,CPD,NOCPD
11 //////// 11 ////////
12 ////////////////////////////////////////////////////////////////// I/O 12 ////////////////////////////////////////////////////////////////// I/O
13 // Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(), 13 // Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
14 // PORT_B_PULLUPS(), INPUT(), 14 // PORT_B_PULLUPS(), INPUT(),
15 // OUTPUT_LOW(), OUTPUT_HIGH(), 15 // OUTPUT_LOW(), OUTPUT_HIGH(),
16 // OUTPUT_FLOAT(), OUTPUT_BIT() 16 // OUTPUT_FLOAT(), OUTPUT_BIT()
17 // Constants used to identify pins in the above are: 17 // Constants used to identify pins in the above are:
18   18  
19 #define PIN_A0 40 19 #define PIN_A0 40
20 #define PIN_A1 41 20 #define PIN_A1 41
21 #define PIN_A2 42 21 #define PIN_A2 42
22 #define PIN_A3 43 22 #define PIN_A3 43
23 #define PIN_A4 44 23 #define PIN_A4 44
24 #define PIN_A5 45 24 #define PIN_A5 45
25 #define PIN_A6 46 25 #define PIN_A6 46
26 #define PIN_A7 47 26 #define PIN_A7 47
27   27  
28 #define PIN_B0 48 28 #define PIN_B0 48
29 #define PIN_B1 49 29 #define PIN_B1 49
30 #define PIN_B2 50 30 #define PIN_B2 50
31 #define PIN_B3 51 31 #define PIN_B3 51
32 #define PIN_B4 52 32 #define PIN_B4 52
33 #define PIN_B5 53 33 #define PIN_B5 53
34 #define PIN_B6 54 34 #define PIN_B6 54
35 #define PIN_B7 55 35 #define PIN_B7 55
36   36  
37 ////////////////////////////////////////////////////////////////// Useful defines 37 ////////////////////////////////////////////////////////////////// Useful defines
38 #define FALSE 0 38 #define FALSE 0
39 #define TRUE 1 39 #define TRUE 1
40   40  
41 #define BYTE int 41 #define BYTE int
42 #define BOOLEAN short int 42 #define BOOLEAN short int
43   43  
44 #define getc getch 44 #define getc getch
45 #define fgetc getch 45 #define fgetc getch
46 #define getchar getch 46 #define getchar getch
47 #define putc putchar 47 #define putc putchar
48 #define fputc putchar 48 #define fputc putchar
49 #define fgets gets 49 #define fgets gets
50 #define fputs puts 50 #define fputs puts
51   51  
52 ////////////////////////////////////////////////////////////////// Control 52 ////////////////////////////////////////////////////////////////// Control
53 // Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE() 53 // Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
54 // Constants returned from RESTART_CAUSE() are: 54 // Constants returned from RESTART_CAUSE() are:
55 #define WDT_FROM_SLEEP 0 55 #define WDT_FROM_SLEEP 0
56 #define WDT_TIMEOUT 8 56 #define WDT_TIMEOUT 8
57 #define MCLR_FROM_SLEEP 16 57 #define MCLR_FROM_SLEEP 16
58 #define NORMAL_POWER_UP 24 58 #define NORMAL_POWER_UP 24
59   59  
60   60  
61 ////////////////////////////////////////////////////////////////// Timer 0 61 ////////////////////////////////////////////////////////////////// Timer 0
62 // Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(), 62 // Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(),
63 // SET_TIMER0() or SET_RTCC(), 63 // SET_TIMER0() or SET_RTCC(),
64 // GET_TIMER0() or GET_RTCC() 64 // GET_TIMER0() or GET_RTCC()
65 // Constants used for SETUP_TIMER0() are: 65 // Constants used for SETUP_TIMER0() are:
66 #define RTCC_INTERNAL 0 66 #define RTCC_INTERNAL 0
67 #define RTCC_EXT_L_TO_H 32 67 #define RTCC_EXT_L_TO_H 32
68 #define RTCC_EXT_H_TO_L 48 68 #define RTCC_EXT_H_TO_L 48
69   69  
70 #define RTCC_DIV_1 8 70 #define RTCC_DIV_1 8
71 #define RTCC_DIV_2 0 71 #define RTCC_DIV_2 0
72 #define RTCC_DIV_4 1 72 #define RTCC_DIV_4 1
73 #define RTCC_DIV_8 2 73 #define RTCC_DIV_8 2
74 #define RTCC_DIV_16 3 74 #define RTCC_DIV_16 3
75 #define RTCC_DIV_32 4 75 #define RTCC_DIV_32 4
76 #define RTCC_DIV_64 5 76 #define RTCC_DIV_64 5
77 #define RTCC_DIV_128 6 77 #define RTCC_DIV_128 6
78 #define RTCC_DIV_256 7 78 #define RTCC_DIV_256 7
79   79  
80   80  
81 #define RTCC_8_BIT 0 81 #define RTCC_8_BIT 0
82   82  
83 // Constants used for SETUP_COUNTERS() are the above 83 // Constants used for SETUP_COUNTERS() are the above
84 // constants for the 1st param and the following for 84 // constants for the 1st param and the following for
85 // the 2nd param: 85 // the 2nd param:
86   86  
87 ////////////////////////////////////////////////////////////////// WDT 87 ////////////////////////////////////////////////////////////////// WDT
88 // Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above) 88 // Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
89 // RESTART_WDT() 89 // RESTART_WDT()
90 // 90 //
91 #define WDT_18MS 8 91 #define WDT_18MS 8
92 #define WDT_36MS 9 92 #define WDT_36MS 9
93 #define WDT_72MS 10 93 #define WDT_72MS 10
94 #define WDT_144MS 11 94 #define WDT_144MS 11
95 #define WDT_288MS 12 95 #define WDT_288MS 12
96 #define WDT_576MS 13 96 #define WDT_576MS 13
97 #define WDT_1152MS 14 97 #define WDT_1152MS 14
98 #define WDT_2304MS 15 98 #define WDT_2304MS 15
99   99  
100 ////////////////////////////////////////////////////////////////// Timer 1 100 ////////////////////////////////////////////////////////////////// Timer 1
101 // Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1 101 // Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
102 // Constants used for SETUP_TIMER_1() are: 102 // Constants used for SETUP_TIMER_1() are:
103 // (or (via |) together constants from each group) 103 // (or (via |) together constants from each group)
104 #define T1_DISABLED 0 104 #define T1_DISABLED 0
105 #define T1_INTERNAL 0x85 105 #define T1_INTERNAL 0x85
106 #define T1_EXTERNAL 0x87 106 #define T1_EXTERNAL 0x87
107 #define T1_EXTERNAL_SYNC 0x83 107 #define T1_EXTERNAL_SYNC 0x83
108   108  
109 #define T1_CLK_OUT 8 109 #define T1_CLK_OUT 8
110   110  
111 #define T1_DIV_BY_1 0 111 #define T1_DIV_BY_1 0
112 #define T1_DIV_BY_2 0x10 112 #define T1_DIV_BY_2 0x10
113 #define T1_DIV_BY_4 0x20 113 #define T1_DIV_BY_4 0x20
114 #define T1_DIV_BY_8 0x30 114 #define T1_DIV_BY_8 0x30
115   115  
116 ////////////////////////////////////////////////////////////////// Timer 2 116 ////////////////////////////////////////////////////////////////// Timer 2
117 // Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2 117 // Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
118 // Constants used for SETUP_TIMER_2() are: 118 // Constants used for SETUP_TIMER_2() are:
119 #define T2_DISABLED 0 119 #define T2_DISABLED 0
120 #define T2_DIV_BY_1 4 120 #define T2_DIV_BY_1 4
121 #define T2_DIV_BY_4 5 121 #define T2_DIV_BY_4 5
122 #define T2_DIV_BY_16 6 122 #define T2_DIV_BY_16 6
123   123  
124 ////////////////////////////////////////////////////////////////// CCP 124 ////////////////////////////////////////////////////////////////// CCP
125 // CCP Functions: SETUP_CCPx, SET_PWMx_DUTY 125 // CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
126 // CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH 126 // CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
127 // Constants used for SETUP_CCPx() are: 127 // Constants used for SETUP_CCPx() are:
128 #define CCP_OFF 0 128 #define CCP_OFF 0
129 #define CCP_CAPTURE_FE 4 129 #define CCP_CAPTURE_FE 4
130 #define CCP_CAPTURE_RE 5 130 #define CCP_CAPTURE_RE 5
131 #define CCP_CAPTURE_DIV_4 6 131 #define CCP_CAPTURE_DIV_4 6
132 #define CCP_CAPTURE_DIV_16 7 132 #define CCP_CAPTURE_DIV_16 7
133 #define CCP_COMPARE_SET_ON_MATCH 8 133 #define CCP_COMPARE_SET_ON_MATCH 8
134 #define CCP_COMPARE_CLR_ON_MATCH 9 134 #define CCP_COMPARE_CLR_ON_MATCH 9
135 #define CCP_COMPARE_INT 0xA 135 #define CCP_COMPARE_INT 0xA
136 #define CCP_COMPARE_RESET_TIMER 0xB 136 #define CCP_COMPARE_RESET_TIMER 0xB
137 #define CCP_PWM 0xC 137 #define CCP_PWM 0xC
138 #define CCP_PWM_PLUS_1 0x1c 138 #define CCP_PWM_PLUS_1 0x1c
139 #define CCP_PWM_PLUS_2 0x2c 139 #define CCP_PWM_PLUS_2 0x2c
140 #define CCP_PWM_PLUS_3 0x3c 140 #define CCP_PWM_PLUS_3 0x3c
141 long CCP_1; 141 long CCP_1;
142 #byte CCP_1 = 0x15 142 #byte CCP_1 = 0x15
143 #byte CCP_1_LOW= 0x15 143 #byte CCP_1_LOW= 0x15
144 #byte CCP_1_HIGH= 0x16 144 #byte CCP_1_HIGH= 0x16
145 ////////////////////////////////////////////////////////////////// COMP 145 ////////////////////////////////////////////////////////////////// COMP
146 // Comparator Variables: C1OUT, C2OUT 146 // Comparator Variables: C1OUT, C2OUT
147 // Constants used in setup_comparators() are: 147 // Constants used in setup_comparators() are:
148 #define A0_A3_A1_A2 4 148 #define A0_A3_A1_A2 4
149 #define A0_A2_A1_A2 3 149 #define A0_A2_A1_A2 3
150 #define NC_NC_A1_A2 5 150 #define NC_NC_A1_A2 5
151 #define NC_NC_NC_NC 7 151 #define NC_NC_NC_NC 7
152 #define A0_VR_A1_VR 2 152 #define A0_VR_A1_VR 2
153 #define A3_VR_A2_VR 10 153 #define A3_VR_A2_VR 10
154 #define A0_A2_A1_A2_OUT_ON_A3_A4 6 154 #define A0_A2_A1_A2_OUT_ON_A3_A4 6
155 #define A3_A2_A1_A2 9 155 #define A3_A2_A1_A2 9
156   156  
157 #bit C1OUT = 0x1f.6 157 #bit C1OUT = 0x1f.6
158 #bit C2OUT = 0x1f.7 158 #bit C2OUT = 0x1f.7
159   159  
160 ////////////////////////////////////////////////////////////////// VREF 160 ////////////////////////////////////////////////////////////////// VREF
161 // Constants used in setup_vref() are: 161 // Constants used in setup_vref() are:
162 #define VREF_LOW 0xa0 162 #define VREF_LOW 0xa0
163 #define VREF_HIGH 0x80 163 #define VREF_HIGH 0x80
164 #define VREF_A2 0x40 164 #define VREF_A2 0x40
165   165  
166 ////////////////////////////////////////////////////////////////// INT 166 ////////////////////////////////////////////////////////////////// INT
167 // Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(), 167 // Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
168 // EXT_INT_EDGE() 168 // EXT_INT_EDGE()
169 // 169 //
170 // Constants used in EXT_INT_EDGE() are: 170 // Constants used in EXT_INT_EDGE() are:
171 #define L_TO_H 0x40 171 #define L_TO_H 0x40
172 #define H_TO_L 0 172 #define H_TO_L 0
173 // Constants used in ENABLE/DISABLE_INTERRUPTS() are: 173 // Constants used in ENABLE/DISABLE_INTERRUPTS() are:
174 #define GLOBAL 0x0BC0 174 #define GLOBAL 0x0BC0
175 #define INT_RTCC 0x0B20 175 #define INT_RTCC 0x0B20
176 #define INT_RB 0x0B08 176 #define INT_RB 0x0B08
177 #define INT_EXT 0x0B10 177 #define INT_EXT 0x0B10
178 #define INT_TBE 0x8C10 178 #define INT_TBE 0x8C10
179 #define INT_RDA 0x8C20 179 #define INT_RDA 0x8C20
180 #define INT_TIMER1 0x8C01 180 #define INT_TIMER1 0x8C01
181 #define INT_TIMER2 0x8C02 181 #define INT_TIMER2 0x8C02
182 #define INT_CCP1 0x8C04 182 #define INT_CCP1 0x8C04
183 #define INT_LCD 0x8C80 183 #define INT_LCD 0x8C80
184 #define INT_COMP 0x8C40 184 #define INT_COMP 0x8C40
185 #define INT_EEPROM 0x0B40 185 #define INT_EEPROM 0x0B40
186 #define INT_TIMER0 0x0B20 186 #define INT_TIMER0 0x0B20
187   187  
188 // Definice reistru pro pristup k EEPROM 188 // Definice reistru pro pristup k EEPROM
189 #define EEDATA 0x010C 189 #define EEDATA 0x010C
190 #define EEADR 0x010D 190 #define EEADR 0x010D
191 #define EEDATAH 0x010E 191 #define EEDATAH 0x010E
192 #define EEADRH 0x010F 192 #define EEADRH 0x010F
193 #define EECON1 0x018C 193 #define EECON1 0x018C
194 #define EECON1_RD 0 194 #define EECON1_RD 0
195 #define EECON1_WR 1 195 #define EECON1_WR 1
196 #define EECON1_WREN 2 196 #define EECON1_WREN 2
197 #define EECON1_WRERR 3 197 #define EECON1_WRERR 3
198 #define EECON1_FREE 4 198 #define EECON1_FREE 4
199 #define EECON1_EEPGD 7 199 #define EECON1_EEPGD 7
200 #define EECON2 0x018D 200 #define EECON2 0x018D
201 #define PIR2 0x000D 201 #define PIR2 0x000D
202 #define PIR2_EEIF 4 202 #define PIR2_EEIF 4
203 #define PIE2 0x008D 203 #define PIE2 0x008D
204 #define PIR2_EEIE 4 204 #define PIR2_EEIE 4
205   205  
206 #list 206 #list