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