搜索
bottom↓
回复: 25

dspic延时函数再度升级,精确到us级,专为做单总线时序设计

[复制链接]

出0入0汤圆

发表于 2012-3-25 23:43:56 | 显示全部楼层 |阅读模式
你不必在为系统时钟更改,而重新计算时间!只要在头文件修改使用晶振频率即可!

=====文件名:utilities.h=====
<font color=#008000>//---------------------------------------------------------------------</font>
<font color=#008000>//    File:        utilities.h</font>
<font color=#008000>//    Written By:    Wang Qian hui</font>
<font color=#008000>//    Purpose:     delay</font>
<font color=#008000>//---------------------------------------------------------------------</font>
<font color=#800080>#include "inttypes.h"</font>
<font color=#800080>#include "processor_clock.h"</font>

<font color=#008000>/* n + 2 cycles</font>
<font color=#008000>   0 &lt;= n &lt;= 16383 */</font>
<font color=#800080>#define __DELAY_SHORT(n) do { \</font>
    __asm__ <font color=#0000FF>volatile</font> (<font color=#FF00FF>"repeat #%0"</font>::<font color=#FF00FF>"i"</font>(n));\
    __asm__ <font color=#0000FF>volatile</font> (<font color=#FF00FF>"clrwdt"</font>);\
} <font color=#0000FF>while</font>(0)

<font color=#008000>/* n microseconds</font>
<font color=#008000>   8/XTAL_FREQ &lt;= n &lt;= 65540/XTAL_FREQ */</font>
<font color=#800080>#define User_DelayUs(n) __DELAY_SHORT((n)*Fcy/1000000-2)</font>

<font color=#0000FF>void</font> User_DelayMs(uint8_t number);


不服你就来,欢迎大家测试!!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2012-3-25 23:47:20 | 显示全部楼层
怎么搞的网站不支持,代码颜色了吗?而且图片也小了许多,有点看不清。
先自己站个位!

出0入0汤圆

 楼主| 发表于 2012-3-25 23:52:12 | 显示全部楼层
这么快置酷了,谢谢莫老大!我还在找如何为自己发的帖子举荐呢?

出0入0汤圆

发表于 2012-3-25 23:54:41 | 显示全部楼层
试试mark

出0入0汤圆

发表于 2012-3-25 23:56:10 | 显示全部楼层
quick comments.

精确到us级,


precise software delays based on a high level language (like c) are always futile: they can be easily defeated.

they are useful if you need some quick / inprecise delays.

专为做单总线时序设计


that can be easily handled with something like F_CPU.

#include "device_config.h"


I manage my configuration bits that way as well. saves tons of time.

in my case, I set the fuse and also copy all the settings from the header file in case I need to switch to a different setting quickly.

出0入0汤圆

发表于 2012-3-26 00:29:51 | 显示全部楼层
多谢分享

出0入0汤圆

发表于 2012-3-26 08:21:26 | 显示全部楼层
CCSC的话本来就内置了...

出0入0汤圆

发表于 2012-3-26 10:07:05 | 显示全部楼层
多谢,正好用到

出0入0汤圆

 楼主| 发表于 2012-3-26 11:34:32 | 显示全部楼层
piccode 发表于 2012-3-26 08:21
CCSC的话本来就内置了...

ccsc是时钟周期数吧?而且你的时钟如果换成11.0592未必是你要的值,没用过CCSC不妄加评论。

出0入0汤圆

发表于 2012-3-26 14:31:41 | 显示全部楼层
Options may be any of the following separated by commas:
clock=speed speed is a constant 1-100000000 (1 hz to 100 mhz).
This number can contains commas. This number also supports the following denominations: M, MHZ, K, KHZ. This specified the clock the CPU runs at.  Depending on the PIC this is 2 or 4 times the instruction rate. This directive is not needed if the following type=speed is used and there is no frequency multiplication or division.

type=speed type defines what kind of clock you are using, and the following values are valid: oscillator, osc (same as oscillator), crystal, xtal (same as crystal), internal, int (same as internal) or rc. The compiler will automatically set the oscillator configuration bits based upon your defined type. If you specified internal, the compiler will also automatically set the internal oscillator to the defined speed. Configuration fuses are modified when this optio is used. Speed is the input frequency.   

  

restart_wdt will restart the watchdog timer on every delay_us() and delay_ms() use.



AUX: type=speed  Some chips have a second oscillator used by specific periphrials and when this is the case this option sets up that oscillator.

出0入0汤圆

 楼主| 发表于 2012-3-26 17:22:01 | 显示全部楼层
piccode 发表于 2012-3-26 14:31
Options may be any of the following separated by commas:
clock=speed speed is a constant 1-100000000 ...

那是福音啊,我用的是MCC的,刚开始调试的时候,是一点一点试形参值,后来发现如果时钟改了之后,这个值还得重新考虑,很麻烦,逼着没办法自己想辙!
之前也琢磨来着,之后碰壁,没弄好,放了一段时间接着又弄。才搞通!还是自己写的能领悟很多!

出0入0汤圆

发表于 2012-3-26 22:39:06 | 显示全部楼层
学习学习...

出0入0汤圆

发表于 2012-3-27 00:59:17 | 显示全部楼层
一大堆代码颜色设置。幸亏有附件可以下载。要不然看着太费劲了。

出0入0汤圆

发表于 2012-3-27 01:08:33 | 显示全部楼层
看不懂这句汇编代码:"repeat #%0"::"i"(n)

出0入0汤圆

 楼主| 发表于 2012-3-27 11:50:53 | 显示全部楼层
xizi 发表于 2012-3-27 01:08
看不懂这句汇编代码:"repeat #%0"::"i"(n)

无开销的程序循环结构,使用的行内汇编!
i 允许(具有常数值的)立即整型操作数。这包括其值仅在汇编时已知的符号常量。
%0只要一个操作数。
::无输出操作数!具体内如看C编译器用户指南!

这些东西,在读表写表中经常能用到。如自编程,或写内部EEPROM时。
头像被屏蔽

出0入0汤圆

发表于 2012-3-27 16:06:47 | 显示全部楼层
mark mark mark

出0入0汤圆

发表于 2012-3-28 21:32:15 | 显示全部楼层
回复提醒功能很好。一开始没注意,一直奇怪,进了论坛就一闪一闪的说有新提醒,却找不到在哪里。
谢谢15楼的回答。

出0入0汤圆

发表于 2012-3-28 23:47:14 | 显示全部楼层
收下了谢谢

出0入0汤圆

发表于 2012-3-29 00:12:01 | 显示全部楼层
GOOD 試試mark

出0入0汤圆

发表于 2012-4-1 14:11:05 | 显示全部楼层
想下载来学习楼主的方法,不怎么下载不了。

出0入0汤圆

发表于 2012-4-1 17:38:38 | 显示全部楼层
有没有用定时器作延时的例子呢?

出0入0汤圆

发表于 2012-4-2 21:13:30 | 显示全部楼层
学习学习

出0入0汤圆

发表于 2012-6-18 15:35:53 | 显示全部楼层
正好用到DS18B20上去,额滴神啊,一定要能用啊!

出0入0汤圆

 楼主| 发表于 2012-6-18 16:46:45 | 显示全部楼层
我开心 发表于 2012-6-18 15:35
正好用到DS18B20上去,额滴神啊,一定要能用啊!

放心使用,肯定没问题的.我就用在DS18B20上了.做的是三线驱动,官方的电路测试成功!距离可以达到500米.但是我没有那么长的线.

出5入42汤圆

发表于 2012-7-10 19:42:51 | 显示全部楼层
一直使用DSPIC
楼主多谢了

出0入0汤圆

发表于 2013-3-25 09:30:08 | 显示全部楼层
可否发到我邮箱?公司电脑不能下载东西。。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-2 22:01

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表