专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
PIC单片机
如何用PIC的普通I/O口产生时钟信号?
2020-02-08 09:16
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
10060
17
17
请问如何用PIC的普通I/O口产生时钟信号?是通过编程产生一系列01信号还是普通IO口能够自行产生时钟信号?
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
17条回答
millwood0
2020-02-09 15:32
this works on a different pic24f chip but they are highly alike.
//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.
加载中...
查看其它17个回答
一周热门
更多
>
相关问题
PIC单片机不同的IO口驱动74HC573驱动共阴极的数码管,有的段不亮
1 个回答
一种简单精确的pic延时方法
21 个回答
谁熟悉PIC的产品发布时间的,帮看看PIC18F47K40啥版本IDE能开发
12 个回答
求AN1078对应的源代码下载地址
5 个回答
PIC单片机应用技巧
4 个回答
相关文章
一种用PIC单片机主时钟驱动的老式挂钟
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
PIC单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
- //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.一周热门 更多>