当前位置:网站首页>dsPIC33EP 时钟初始化程序
dsPIC33EP 时钟初始化程序
2022-07-05 10:13:00 【全栈程序员站长】
//文件名p33clk.h
#ifndef _P33CLK_H_
#define _P33CLK_H_
//#include "p33clk.h"
#define WDT_ENB _SWDTEN = 1
#define WDT_DIS _SWDTEN = 0
//时钟源选择
#define OSCLK0 0 //FRC
#define OSCLK1 1 //带PLL+N分频的FRC
#define OSCLK2 2 //HS MS LS 外部时钟
#define OSCLK3 3 //带PLL的HS MS LS 外部时钟
#define OSCLK4 4 //保留
#define OSCLK5 5 //LPRC
#define OSCLK6 6 //FRC/16
#define OSCLK7 7 //带N分频的FRC
//处理器与CPU时钟分频比
#define DOZEDIV1 (0<<12)
#define DOZEDIV2 (1<<12)
#define DOZEDIV4 (2<<12)
#define DOZEDIV8 (3<<12)
#define DOZEDIV16 (4<<12)
#define DOZEDIV32 (5<<12)
#define DOZEDIV64 (6<<12)
#define DOZEDIV128 (7<<12)
//------------------------------
//Fosc = (Fin/V_FRCDIV/N1/N2)*M
#define V_FRCDIV V_FRCDIV1 //FRC振荡分频系数
#define V_N1 V_N1DIV(2) //x = 2--33 N1 分频系数
#define V_N2 V_N2DIV2 //N2 分频系数
#define V_PLLFBD PLLMF(50) //(x=2--513)PLL 倍频比
//FRC 分频系数
#define V_FRCDIV1 0
#define V_FRCDIV2 1
#define V_FRCDIV4 2
#define V_FRCDIV8 3
#define V_FRCDIV16 4
#define V_FRCDIV32 5
#define V_FRCDIV64 6
#define V_FRCDIV256 7
//N1
#define V_N1DIV(x) (x-2)
//N2
#define V_N2DIV2 0
#define V_N2DIV4 1
#define V_N2DIV8 3
//PLL 倍频数 M
#define PLLMF(x) (x-2)
//================================
extern void Init_Clk(uint16 OsClk) ;
#endif
//文件名p33clk.c
#include "global.h"
#include "p33clk.h"
//***************************************
// 函数名称:InitClk
// 函数功能:初始化时钟
// 入口参数:时钟来源选择 FRC分频 pll倍频比
// 出口参数:无
// 返回值:无
// Fosc = (Fin/V_FRCDIV/N1/N2)*M
//***************************************
void Init_Clk(uint16 OsClk)
{
CLKDIV = 0X0000 ; //处理器与外设时钟比为1:1
_FRCDIV = V_FRCDIV ; //FRC分频系数
_PLLPOST = V_N2 ;//N2
_PLLPRE = V_N1 ;//N1
PLLFBD = V_PLLFBD ;// PLL倍频
OSCTUN = 0X0000 ; //振荡器调节寄存器 默认7.37M
REFOCON = 0X0000 ; //参考时钟=系统时钟
OSCCON = 0X0000 ;
_OSWEN = 1 ; //请求切换由NOSC指定的时钟
_NOSC = OsClk ; //切换 新的振荡器
while(_OSWEN) ;//等待时钟切换完成
if((_NOSC == OSCLK1) ||(_NOSC == OSCLK3))//带PLL
{
while(!_LOCK) ;//等待PLL锁定
}
REFOCON |= 0X8000 ; //参考时钟输出使能
}
//应用实例 -- 时钟初始化
//FRC 系统时钟1分频到CPU PLL倍频50
//Fin = 7.37M Fcpu = Fosc/2 = 46.0625M
Init_Clk(OSCLK1) ;发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/109983.html原文链接:https://javaforall.cn
边栏推荐
- The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
- LiveData 面试题库、解答---LiveData 面试 7 连问~
- Comparative learning in the period of "arms race"
- > Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
- Excerpt from "sword comes" (VII)
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- Zblogphp breadcrumb navigation code
- 学习笔记4--高精度地图关键技术(下)
- "Everyday Mathematics" serial 58: February 27
- @SerializedName注解使用
猜你喜欢

WorkManager學習一

Learning notes 5 - high precision map solution

Universal double button or single button pop-up
![[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems](/img/6c/5b14f47503033bc2c85a259a968d94.png)
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems

学习笔记5--高精地图解决方案

ConstraintLayout官方提供圆角ImageFilterView

B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...

【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...

Events and bubbles in the applet of "wechat applet - Basics"

How to judge that the thread pool has completed all tasks?
随机推荐
Zblogphp breadcrumb navigation code
各位大佬,我测试起了3条线程同时往3个mysql表中写入,每条线程分别写入100000条数据,用了f
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
Learning note 4 -- Key Technologies of high-precision map (Part 2)
5g NR system architecture
Glide advanced level
Interview: how does the list duplicate according to the attributes of the object?
A high density 256 channel electrode cap for dry EEG
官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
如何写出高质量的代码?
@JsonAdapter注解使用
SAP ui5 objectpagelayout control usage sharing
Qt实现json解析
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
How does redis implement multiple zones?
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
C语言实现QQ聊天室小项目 [完整源码]
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
uniapp + uniCloud+unipay 实现微信小程序支付功能
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo