2010年3月3日星期三

解密电路中的上拉和下拉电阻

上拉电阻:
1、当TTL电路驱动COMS电路时,如果TTL电路输出的高电平低于COMS电路的最低高电平(一般为3.5V),这时就需要在TTL的输出端接上拉电阻,以提高输出高电平的值。
2、OC门电路必须加上拉电阻,才能使用。
3、为加大输出引脚的驱动能力,有的单片机管脚上也常使用上拉电阻。
4、在COMS芯片上,为了防止静电造成损坏,不用的管脚不能悬空,一般接上拉电阻产生降低输入阻抗,提供泄荷通路。
5、芯片的管脚加上拉电阻来提高输出电平,从而提高芯片输入信号的噪声容限增强抗干扰能力。
6、提高总线的抗电磁干扰能力。管脚悬空就比较容易接受外界的电磁干扰。
7、长线传输中电阻不匹配容易引起反射波干扰,加上下拉电阻是电阻匹配,有效的抑制反射波干扰。

上拉电阻阻值的选择原则包括:
1、从节约功耗及芯片的灌电流能力考虑应当足够大;电阻大,电流小。
2、从确保足够的驱动电流考虑应当足够小;电阻小,电流大。
3、对于高速电路,过大的上拉电阻可能边沿变平缓。综合考虑
以上三点,通常在1k到10k之间选取。对下拉电阻也有类似道理

对上拉电阻和下拉电阻的选择应结合开关管特性和下级电路的输入特性进行设定,主要需要考虑以下几个因素:
1.
驱动能力与功耗的平衡。以上拉电阻为例,一般地说,上拉电阻越小,驱动能力越强,但功耗越大,设计是应注意两者之间的均衡。
2.
下级电路的驱动需求。同样以上拉电阻为例,当输出高电平时,开关管断开,上拉电阻应适当选择以能够向下级电路提供足够的电流。
3.
高低电平的设定。不同电路的高低电平的门槛电平会有不同,电阻应适当设定以确保能输出正确的电平。以上拉电阻为例,当输出低电平时,开关管导通,上拉电阻和开关管导通电阻分压值应确保在零电平门槛之下。
4.
频率特性。以上拉电阻为例,上拉电阻和开关管漏源级之间的电容和下级电路之间的输入电容会形成RC延迟,电阻越大,延迟越大。上拉电阻的设定应考虑电路在这方面的需求。

下拉电阻的设定的原则和上拉电阻是一样的。
OC门输出高电平时是一个高阻态,其上拉电流要由上拉电阻来提供,设输入端每端口不大于100uA,设输出口驱动电流约500uA,标准工作电压是5V,输入口的高低电平门限为0.8V(低于此值为低电平);2V(高电平门限值)。
选上拉电阻时:
500uA x 8.4K=
4.2即选大于8.4K时输出端能下拉至0.8V以下,此为最小阻值,再小就拉不下来了。如果输出口驱动电流较大,则阻值可减小,保证下拉时能低于0.8V即可。
当输出高电平时,忽略管子的漏电流,两输入口需200uA
200uA
x15K=3V即上拉电阻压降为3V,输出口可达到2V,此阻值为最大阻值,再大就拉不到2V了。选10K可用。COMS门的可参考74HC系列
设计时管子的漏电流不可忽略,IO口实际电流在不同电平下也是不同的,上述仅仅是原理,一句话概括为:输出高电平时要喂饱后面的输入口,输出低电平不要把输出口喂撑了(否则多余的电流喂给了级联的输入口,高于低电平门限值就不可靠了)

在数字电路中不用的输入脚都要接固定电平,通过1k电阻接高电平或接地。
1. 电阻作用:
接电组就是为了防止输入端悬空
减弱外部电流对芯片产生的干扰
保护cmos内的保护二极管,一般电流不大于10mA
上拉和下拉、限流
改变电平的电位,常用在TTL-CMOS匹配
在引脚悬空时有确定的状态
增加高电平输出时的驱动能力。
为OC门提供电流
要看输出口驱动的是什么器件,如果该器件需要高电压的话,而输出口的输出电压又不够,就需要加上拉电阻。
如果有上拉电阻那它的端口在默认值为高电平你要控制它必须用低电平才能控制如三态门电路三极管的集电极,或二极管正极去控制把上拉电阻的电流拉下来成为低电平。反之,
尤其用在接口电路中,为了得到确定的电平,一般采用这种方法,以保证正确的电路状态,以免发生意外,比如,在电机控制中,逆变桥上下桥臂不能直通,如果它们都用同一个单片机来驱动,必须设置初始状态.防止直通!

2、定义:
上拉就是将不确定的信号通过一个电阻嵌位在高电平!电阻同时起限流作用!下拉同理!
上拉是对器件注入电流,下拉是输出电流
弱强只是上拉电阻的阻值不同,没有什么严格区分
对于非集电极(或漏极)开路输出型电路(如普通门电路)提升电流和电压的能力是有限的,上拉电阻的功能主要是为集电极开路输出型电路输出电流通道。

3、为什么要使用拉电阻:
一般作单键触发使用时,如果IC本身没有内接电阻,为了使单键维持在不被触发的状态或是触发后回到原状态,必须在IC外部另接一电阻。
数字电路有三种状态:高电平、低电平、和高阻状态,有些应用场合不希望出现高阻状态,可以通过上拉电阻或下拉电阻的方式使处于稳定状态,具体视设计要求而定!
一般说的是I/O端口,有的可以设置,有的不可以设置,有的是内置,有的是需要外接,I/O端口的输出类似与一个三极管的C,当C接通过一个电阻和电源连接在一起的时候,该电阻成为上C拉电阻,也就是说,如果该端口正常时为高电平,C通过一个电阻和地连接在一起的时候,该电阻称为下拉电阻,使该端口平时为低电平,作用吗:
比如:当一个接有上拉电阻的端口设为输如状态时,他的常态就为高电平,用于检测低电平的输入。
上拉电阻是用来解决总线驱动能力不足时提供电流的。一般说法是拉电流,下拉电阻是用来吸收电流。

巴菲特再谈成功投资的秘密

近日,巴菲特发表一年一度的《致股东的一封信》,其中重申了让自己成功的投资"秘诀",本报摘编,以飨读者。
1.保持流动性充足。他写道,我们决不会对陌生人的好意产生依赖,我们对自己事务的安排,一定会让我们极有可能面临的任何现金要求在我们的流动性面前显得微不足道;另外,这种流动性还将被我们所投的多家、多样化的公司所产生的利润流不断刷新。
2.大家都抛时我买进。巴菲特写道,在过去两年的混乱中,我们把大量资金用起来;这段时间对于投资者来说是极佳时期,因为恐慌气氛是他们的最好朋友……重大机遇难得一见,当天上掉金时,要拿一个大桶而不是顶针去接。
3.大家都买时我不买。巴菲特写道,那些只在评论家都很乐观时才投资的人,最后都是用极高的代价去买一种没有意义的安慰。从他这句话推导,显然是要有耐心。如果人人都在买进时你做到了按兵不动,那么只有在人人都抛售时你才能买进。
4.价值,价值,价值。巴菲特写道,投资中最重要的是你为了什么而给一家公司投钱———通过在股市中购买它的一个小部分———以及这家公司在未来一二十年会挣多少。
5.别被高增长故事愚弄。巴菲特提醒投资者说,他和伯克希尔副董事长芒格(CharlieMunger)不投那些"我们不能评估其未来的公司",不管它们的产品可能多么让人兴奋。
多数在1910年押赌汽车业、1930年赌飞机或在1950年下注于电视机生产商的投资者,到头来输得一无所有,尽管这些产品确实改变了世界。"急剧增长"并不一定带来高利润率和高额资本回报。
6.理解你所持有的东西。巴菲特写道,根据媒体或分析师评论进行买卖的投资者不适合于我们。
7.防守好于进攻。巴菲特写道,虽然我们在某些市场上扬的年头里落后于标普指数,但在标普指数下跌的11个年头里,我们的表现一直好过这一指数;换句话说,我们的防守一直好于进攻,这种情况可能会继续下去。在动荡年代,巴菲特的这些建议都是符合时宜的。

2010年3月2日星期二

linux下类似Windows下的Everything的快速文件名搜索工具mlocate

Everything是我用过的最好的软件工具之一,"快、小、绿色",是我在windows下最留恋的软件。因为有它,我甚至可以不用totalcmd来文件夹切换查找操作了。
可惜的是linux下面并没有如此好用的软件,而locate查找软件的速度我实在不敢恭维,而且还建了那么大的文件索引列表,而索引更新又是如此之慢,令人诟病。
还好,有mlocate稍微缓解我内心的不快,速度比locate和slocate都要快,但还远不及everything,凑活用吧,已经是目前linux下面最差强人意的文件搜索工具了。


mlocate
About

mlocate is a new locate implementation. The 'm' stands for "merging":
updatedb reuses the existing database to avoid rereading most of the file
system, which makes updatedb faster and does not trash the system caches
as much.

The locate(1) utility is intended to be completely compatible to slocate.
It also attempts to be compatible to GNU locate, when it does not conflict
with slocate compatibility.
Availability

mlocate tarballs are available at fedorahosted.org.

Current version: 0.22.1

mlocate is also included in Fedora Core 6 and later.
Bugs

Please consider reporting the bug to your distribution's bug tracking
system.

Otherwise, report bugs at https://fedorahosted.org/mlocate/. Bug reports
with patches are especially welcome.
Performance

These measurements were obtained with mlocate-0.12 and slocate-2.7. Each
time, a computer was booted into single-user mode and after one updatedb
run data was collected using slabtop and free. The measurement method is
admittedly crude, but I think the numbers represent reality quite well.
Run: real user system dentry inode buffers cached
slocate 1m32.84 0.704 2.045 134337 170778 85972 8268
mlocate, 1st 1m11.65 0.214 0.908 17766 15642 78452 21340
mlocate, 2nd 37.64 0.105 0.289 17776 15639 33996 21336

real, user, system
as reported by time
dentry, inode
number of active objects in dentrycache and ext3inode_cache, as reported
by slabtop
buffers, cached
size of disk buffers and page cache, as reported by free


mlocate has two rows because the first run needs to scan the whole file
system, while the subsequent runs can reuse most of the original database.

2010年3月1日星期一

交换两个值,不用临时变量

例如:a=3,即11(2);b=4,即100(2)。
想将a和b的值互换,可以用以下赋值语句实现:
a=a∧b;
b=b∧a;
a=a∧b;
a=011(2)
(∧)b=100(2)
a=111(2)(a∧b的结果,a已变成7)
(∧)b=100(2)
b=011(2)(b∧a的结果,b已变成3)
(∧)a=111(2)


a=100(2)(a∧b的结果,a已变成4)
等效于以下两步:
① 执行前两个赋值语句:"a=a∧b;"和"b=b∧a;"相当于b=b∧(a∧b)。
② 再执行第三个赋值语句:
a=a∧b。由于a的值等于(a∧b),b的值等于(b∧a∧b),

因此,相当于a=a∧b∧b∧a∧b,即a的值等于a∧a∧b∧b∧b,等于b。
很神奇吧!
c语言源代码:
#include <stdio.h>
main()
{
int a=3;
int b = 4;
a=a^b;
b=b^a;
a=a^b;
printf("a=%d b=%d",a,b);
}

wget 下载整个网站,或者特定目录

需要下载某个目录下面的所有文件。命令如下

wget -c -r -np -k -L -p www.xxx.org/pub/path/

在下载时。有用到外部域名的图片或连接。如果需要同时下载就要用-H参数。

wget -np -nH -r --span-hosts www.xxx.org/pub/path/

-c 断点续传
-r 递归下载,下载指定网页某一目录下(包括子目录)的所有文件
-nd 递归下载时不创建一层一层的目录,把所有的文件下载到当前目录
-np 递归下载时不搜索上层目录,如wget -c -r www.xxx.org/pub/path/
没有加参数-np,就会同时下载path的上一级目录pub下的其它文件
-k 将绝对链接转为相对链接,下载整个站点后脱机浏览网页,最好加上这个参数
-L 递归时不进入其它主机,如wget -c -r www.xxx.org/
如果网站内有一个这样的链接:
www.yyy.org,不加参数-L,就会像大火烧山一样,会递归下载www.yyy.org网站
-p 下载网页所需的所有文件,如图片等
-A 指定要下载的文件样式列表,多个样式用逗号分隔
-i 后面跟一个文件,文件内指明要下载的URL

还有其他的用法,我从网上搜索的,也一并写上来,方便以后自己使用。

wget的常见用法

wget的使用格式
Usage: wget [OPTION]… [URL]…

* 用wget做站点镜像:
wget -r -p -np -k http://dsec.pku.edu.cn/~usr_name/
# 或者
wget -m http://www.tldp.org/LDP/abs/html/

* 在不稳定的网络上下载一个部分下载的文件,以及在空闲时段下载
wget -t 0 -w 31 -c http://dsec.pku.edu.cn/BBC.avi -o down.log &
# 或者从filelist读入要下载的文件列表
wget -t 0 -w 31 -c -B ftp://dsec.pku.edu.cn/linuxsoft -i filelist.txt -o
down.log &

上面的代码还可以用来在网络比较空闲的时段进行下载。我的用法是:在mozilla中将不方便当时下载的URL链接拷贝到内存中然后粘贴到文件filelist.txt中,在晚上要出去系统前执行上面代码的第二条。

* 使用代理下载
wget -Y on -p -k https://sourceforge.net/projects/wvware/

代理可以在环境变量或wgetrc文件中设定

# 在环境变量中设定代理
export PROXY=http://211.90.168.94:8080/
# 在~/.wgetrc中设定代理
http_proxy = http://proxy.yoyodyne.com:18023/
ftp_proxy = http://proxy.yoyodyne.com:18023/

wget各种选项分类列表

* 启动

-V, –version 显示wget的版本后退出
-h, –help 打印语法帮助
-b, –background 启动后转入后台执行
-e, –execute=COMMAND
执行`.wgetrc'格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc

* 记录和输入文件

-o, –output-file=FILE 把记录写到FILE文件中
-a, –append-output=FILE 把记录追加到FILE文件中
-d, –debug 打印调试输出
-q, –quiet 安静模式(没有输出)
-v, –verbose 冗长模式(这是缺省设置)
-nv, –non-verbose 关掉冗长模式,但不是安静模式
-i, –input-file=FILE 下载在FILE文件中出现的URLs
-F, –force-html 把输入文件当作HTML格式文件对待
-B, –base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀
–sslcertfile=FILE 可选客户端证书
–sslcertkey=KEYFILE 可选客户端证书的KEYFILE
–egd-file=FILE 指定EGD socket的文件名

* 下载

–bind-address=ADDRESS
指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用)
-t, –tries=NUMBER 设定最大尝试链接次数(0 表示无限制).
-O –output-document=FILE 把文档写到FILE文件中
-nc, –no-clobber 不要覆盖存在的文件或使用.#前缀
-c, –continue 接着下载没下载完的文件
–progress=TYPE 设定进程条标记
-N, –timestamping 不要重新下载文件除非比本地文件新
-S, –server-response 打印服务器的回应
–spider 不下载任何东西
-T, –timeout=SECONDS 设定响应超时的秒数
-w, –wait=SECONDS 两次尝试之间间隔SECONDS秒
–waitretry=SECONDS 在重新链接之间等待1…SECONDS秒
–random-wait 在下载之间等待0…2*WAIT秒
-Y, –proxy=on/off 打开或关闭代理
-Q, –quota=NUMBER 设置下载的容量限制
–limit-rate=RATE 限定下载输率

* 目录

-nd –no-directories 不创建目录
-x, –force-directories 强制创建目录
-nH, –no-host-directories 不创建主机目录
-P, –directory-prefix=PREFIX 将文件保存到目录 PREFIX/…
–cut-dirs=NUMBER 忽略 NUMBER层远程目录

* HTTP 选项

–http-user=USER 设定HTTP用户名为 USER.
–http-passwd=PASS 设定http密码为 PASS.
-C, –cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许).
-E, –html-extension 将所有text/html文档以.html扩展名保存
–ignore-length 忽略 `Content-Length'头域
–header=STRING 在headers中插入字符串 STRING
–proxy-user=USER 设定代理的用户名为 USER
–proxy-passwd=PASS 设定代理的密码为 PASS
–referer=URL 在HTTP请求中包含 `Referer: URL'头
-s, –save-headers 保存HTTP头到文件
-U, –user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION.
–no-http-keep-alive 关闭 HTTP活动链接 (永远链接).
–cookies=off 不使用 cookies.
–load-cookies=FILE 在开始会话前从文件 FILE中加载cookie
–save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中

* FTP 选项

-nr, –dont-remove-listing 不移走 `.listing'文件
-g, –glob=on/off 打开或关闭文件名的 globbing机制
–passive-ftp 使用被动传输模式 (缺省值).
–active-ftp 使用主动传输模式
–retr-symlinks 在递归的时候,将链接指向文件(而不是目录)

* 递归下载

-r, –recursive 递归下载--慎用!
-l, –level=NUMBER 最大递归深度 (inf 或 0 代表无穷).
–delete-after 在现在完毕后局部删除文件
-k, –convert-links 转换非相对链接为相对链接
-K, –backup-converted 在转换文件X之前,将之备份为 X.orig
-m, –mirror 等价于 -r -N -l inf -nr.
-p, –page-requisites 下载显示HTML文件的所有图片

* 递归下载中的包含和不包含(accept/reject)

-A, –accept=LIST 分号分隔的被接受扩展名的列表
-R, –reject=LIST 分号分隔的不被接受的扩展名的列表
-D, –domains=LIST 分号分隔的被接受域的列表
–exclude-domains=LIST 分号分隔的不被接受的域的列表
–follow-ftp 跟踪HTML文档中的FTP链接
–follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表
-G, –ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表
-H, –span-hosts 当递归时转到外部主机
-L, –relative 仅仅跟踪相对链接
-I, –include-directories=LIST 允许目录的列表
-X, –exclude-directories=LIST 不被包含目录的列表
-np, –no-parent 不要追溯到父目录

How To Install OpenOffice 3.2 In Ubuntu (.deb Download)

I initially wanted to wait for the PPA (OpenOffice Scribblers) to get
OpenOffice 3.2 but it seems that takes way too much time and I'm not going
to wait until Ubuntu Lucid Lynx (10.04) to install the latest OpenOffice
3.2 (even though Ubuntu uses OO-Go, an optimized version of OpenOffice),
so I decided to download and install OOo 3.2 on my Ubuntu Karmic from its
official website. The installation was very easy and fast so I wanted to
share the steps with any WebUpd8 readers who don't want to wait for the
PPA (which might take a long time) or Ubuntu Lucid to upgrade (well,
actually do a fresh install) to OpenOffice.org 3.2.


Before proceeding to the OpenOffice 3.2 installation (from its website),
please note that there are quite a few differences between this version of
OpenOffice.org and the OpenOffice.org version from the Ubuntu
repositories! Like I said above, Ubuntu uses an optimized version of
OpenOffice.org called OO-Go. Read more about OO-Go, HERE.

If you want to install Go-OO (from it's official website, not Ubuntu
repositories) 3.2 in Ubuntu, see: How To Install Go-OO 3.2 In Ubuntu Linux.

How to install OpenOffice 3.2 in Ubuntu

1. The first thing you need to do (very important) is completely remove
any OpenOffice packages you may have installed on your Ubuntu computer:
sudo apt-get remove openoffice*


2. Then, to download and install OpenOffice 3.2 in Ubuntu, simply copy &
paste the commands below in a terminal (what the commands do is download
the .tar.gz archive which includes Ubuntu .deb files, extract the files
and then install them all recursively):

Ubuntu 32bit:
wget
http://download.services.openoffice.org/files/stable/3.2.0/OOo_3.2.0_LinuxIntel_install_en-US_deb.tar.gz
tar -xvf OOo_3.2.0_LinuxIntel_install_en-US_deb.tar.gz
cd OOO320_m12_native_packed-1_en-US.9483/
sudo dpkg -iR DEBS/

Ubuntu 64bit:
wget
http://download.services.openoffice.org/files/stable/3.2.0/OOo_3.2.0_LinuxX86-64_install_en-US_deb.tar.gz
tar -xvf OOo_3.2.0_LinuxX86-64_install_en-US_deb.tar.gz
cd OOO320_m12_native_packed-1_en-US.9483/
sudo dpkg -iR DEBS/


If you want to manually download OpenOffice 3.2 .debs, get the archive
from HERE (chose either "Linux 32-bit DEB" or "Linux 64-bit DEB" depending
on your Ubuntu installed architecture).

Please note that the commands above are customized for the US language
OpenOffice.org. If you download OpenOffice 3.2 for a different language,
adjust the language in the file names in the commands!

How To Install Go-OO 3.2 In Ubuntu

Like you probably know, there are no official OpenOffice.org packages in
the Ubuntu repositories for the latest version (3.2) and also no packages
in the OpenOffice.org Scribblers PPA (for now at least).

We wrote about installing OpenOffice 3.2 in Ubuntu from it's official
website but that's not the same OpenOffice.org as the one in the Ubuntu
repositories because Ubuntu uses Go-OO, an optimized version of
OpenOffice. Well, here is how to install this optimized version called
Go-OO. You can learn more about Go-OO @ it's official website.


Before installing, please note:
Even though Ubuntu uses Go-OO, the version you will install by following
the instructions in this post is still not 100% the same as the one in the
Ubuntu repositories (obviously)
There are no Go-OO .deb files for Ubuntu so you will have to convert the
.rpm files to .deb. This is not an exactly proper way of installing Go-OO,
but it will work fine anyway.


This being said, you can proceed to installing Go-OO 3.2 in Ubuntu:


1. Remove the OpenOffice.org packages:

sudo apt-get remove openoffice.org*


2. Install alien to convert the .rpm files to .deb:

sudo apt-get install alien


3. Download Go-OO 3.2:
mkdir go-oo && cd go-oo
wget http://go-oo.org/download/download-go-oo.py
sudo chmod +x download-go-oo.py
./download-go-oo.py

The commands above will create a folder called "go-oo" and download a
script from the Go-OO website which will fetch all the Go-OO 3.2 .rpm
files for you.

Before running the last command above, please note that you can customize
it to download packages for a certain architecture or localisation
(language):

Usage: ./download-go-oo.py [--localization=] [--distribution=]
[--system= version=]

Options:
--localization - language to download (default: en_US)
--distribution - distribution for which the menus are dowloaded
(default: freedesktop)
--system - architecture to dowloaded (default: linux-i586)
--version - version to download (default: 3.2)

Supported languages:
af, ar, as, be, bg, bn, bn_BD, bn_IN, bo, br, brx, bs, by, ca, cs, cy, da,
de, dgo, dz, el, en_GB, en_US, en_ZA, eo, es, et, eu, fa, fi, fr, ga, gd,
gl, gu, gu_IN, he, hi, hr, hu, is, it, ja, ka, kid, kk, km, kn, ko, kok,
ks, ku, ky, lo, lt, lv, mai, mk, ml, mn, mni, mr, ms, my, nb, ne, nl, nn,
nr, ns, oc, om, or, pa, pap, pl, ps, pt, pt_BR, ro, ru, rw, sa, sat, sc,
sd, sh, si, sk, sl, sr, ss, st, sv, sw, sw_TZ, ta, te, tg, th, ti, tn, tr,
ts, ug, uk, ur, uz, ve, vi, xh, zh_CN, zh_TW, zu

Supported distributions:
freedesktop, mandriva, redhat, suse

Supported systems:
linux-i586, linux-x86, linux-x86_64


For Ubuntu 32bit and English language, you can just run the script as the
default options are enough.


4. Install Go-OO 3.2 in Ubuntu

You can either directly install the .rpm files using alien, or convert the
.rpm files to .deb so you can directly distribute them, etc.

method 1 -> directly install Go-OO 3.2
sudo alien -i *.rpm


method 2 -> convert the Go-OO 3.2 packages to .deb and then install them:
sudo alien -d *.rpm
sudo dpkg -i *.deb