2020-02-08 09:16发布
millwood0 发表于 2012-4-20 20:47 this works on a different pic24f chip but they are highly alike.it configures timer2/3 into a 32-bit ...
不太清楚原因。。。。
最多设置5个标签!
- //reset the tmr
- void tmr23_init(void) {
- //_T2MD = 0; //enable power to tmr
- _T2ON = 0; //turn off rtc1
- TMR2 = TMR3 = 0; //reset the timer/counter
- //PR2=period; //minimum rtc resolution is 1ms
- _T2CS = 0; //use internal clock = Fosc / 4
- _T2_32 = 1; //clock as 1 32-bit timer/counter
- _T2CKPS=0; //set prescaler to 1:1
- _T2GE = 0; //rtc1 gate disabled
- _T3IF = 0; //reset the flag
- _T3IE = 0; //rtc1 interrupt off
- //_T2ON = 1; //turn on rtc1
- }
- //delay some time
- void tmr23_delay(unsigned long ps) {
- _T2ON = 0;
- _T3IF = 0;
- PR2 = ps; //load the period, lsb
- PR3 = ps >> 16; //load the period, msb
- _T2ON = 1; //turn on the timer
- while (_T3IF==0) continue; //wait for the cycle to complete
- //_T2ON = 0; //turn off the timer
- }
- int main(void) {
- mcu_init(); //reset the mcu
- tmr23_init(); //reset the tmr
- while (1) {
- tmr23_delay(F_CPU/4); //wait for 1/4 a second
- IO_FLP(OUT_PORT, OUT); //flip out
- }
- }
复制代码it configures timer2/3 into a 32-bit timer. You can certainly repurpose it for your application, quite easily, as the basic structure is the same.非常感谢你的程序。不过我很想知道我的程序错在哪儿。。。。我在做调试的时候发现更改定时器的初始值(TMR1=0x00)对时钟脉冲宽度没有影响。不太清楚原因。。。。
thus the need to read and understand the datasheet.
一周热门 更多>