blob: a5c89631178a8208828f77dd003814a3ec6b335f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
Basic sample for BoostC++ compiler.
Use the 'Led Block' plugin to see
changing value on port B.
*/
#include <system.h>
// Set configuration word (sample only, ajust for your particular case)
#ifdef _PIC16
#pragma DATA 0x2007, _HS_OSC & _WDT_OFF
#endif //_PIC16
class CPort
{
public:
CPort();
void Toggle( void )
{
#ifdef _PIC16
portb++;
#else
latb++;
#endif
}
};
CPort::CPort()
{
trisb = 0; //configure port B
#ifdef _PIC16
portb = 0; //clear port B
#else
latb = 0; //clear port B
#endif
}
class CTimer
{
public:
CTimer();
};
CTimer::CTimer()
{
#ifdef _PIC16
option_reg = 7; //set prescaler
#else
// configure Timer0
set_bit( t0con, TMR0ON ); //enable timer
clear_bit( t0con, T08BIT ); //set 16-bit mode
clear_bit( t0con, T0CS ); // select internal clock
clear_bit( t0con, PSA ); // select prescaler
set_bit( t0con, T0PS0 ); // set 1:64 prescale ratio
clear_bit( t0con, T0PS1 );
set_bit( t0con, T0PS2 );
#endif
// enable interrupts
set_bit( intcon, T0IE ); //enable TMR0 overflow bit
}
class CPort port; //configure port
class CTimer timer; //configure prescaler
void interrupt( void )
{
port.Toggle();
clear_bit( intcon, T0IF ); //clear TMR0 overflow flag
}
void main()
{
// enable interrupts
set_bit( intcon, GIE );
while( 1 ); //endless loop
}
|