Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
The reset value for TMR1CS is zero. His issue is that he's not setting a preload value.
// Setting Timer 1 configuration register (T1CON) one bit at a time
T1CONbits.RD16 = 1; // 0 = R/W as 8 bits, 1 = R/W as 16 bits
//TMR1_OSC = T1CONbits.T1RUN = ; // read only: 1 = TMR1 OSC in use
T1CONbits.T1CKPS1 = 0; // 2 bit Prescale value: 00: PS = 1,
T1CONbits.T1CKPS0 = 0; // 01: PS = 2, 10: PS = 4, 11: PS = 8
T1CONbits.T1OSCEN = 0; // Timer 1 Osc Enable: 0 = off, 1 = on
T1CONbits.T1SYNC = 0; // Timer 1 Osc Sync: 0 = on, 1 = off
T1CONbits.TMR1CS = 0; // Clock Source: 0 = Fcy, 1 = TMR1_OSC
T1CONbits.TMR1ON = 1; // 0 = turn timer off, 1 = turn timer on
// Alternatively you could set the T1CON register as a single byte:
// RD16 CHK PS1 PS0 OSC SYNC SRC ON
T1CON = 0x81; // 1 0 0 0 0 0 0 1
TMR1H = 0xD1; // TMR1H must be written first
TMR1L = 0x20; // count up from D120h
PIR1bits.TMR1IF = 0; // reset the interrupt flag
while(!PIR1bits.TMR1IF) { // wait for the interrupt flag = 1 then break the loop
// turn something on or off - or just wait
};
T1CONbits.TMR1ON = 0; // 0 = turn timer off, 1 = turn timer on