Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
T2CON
TOUTP
S3
TOUTP
S2
TOUTP
S1
TOUTP
S0
TMR2
ON
T2CKP
S1
T2CKP
S0
0x4F
start/stop
Timer 2
PR2
C7
C6
C5
C4
C3
C2
C1
C0
0xF9
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
B
1
4
16
16
Tic =
4
f osc
T2CON
PR2
PIR1
TOUT
PS3
TOUT
PS2
TOUT
PS1
TOUT
PS0
TMR2
ON
T2CK
PS1
T2CK
PS0
C7
C6
C5
C4
C3
C2
C1
C0
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1
TMR2
TMR1
IF
IF
IF
#include <p18F252.h>
void delay(void)
{
// set the Timer 2 to produce certain delay
// by loading T2CON and PR2 registers
T2CON = 0x49;
// loading to achieve
PR2 = 0x7C;
// 1 ms delay at 20 MHz
T2CONbits.TMR2ON = 1;
//
//
//
while(1)
{
PORTBbits.RB0 = 1;
PORTB = 0b00000001;
PORTB = 0x01;
PORTB = 1;
delay();
PORTBbits.RB0 = 0;
delay();
}
//
//
//
//
//
//
//
set RB0 to 1
alternative ways to do the
same thing but all pins
of Port B will be affected
wait
set RB0 to 0
wait again and loop back