端口分配 [英] Port Assignment

查看:121
本文介绍了端口分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经阅读了有关LED开/关的程序,并发现它很容易理解.我唯一困惑的是该命令:

"TRISB = 0xF0;//输入RB4:RB7;二进制二进制11110000"

我想知道您如何得知0xF0是RB4:RB7端口的正确值,以及如何知道每个端口的十六进制代码(如果需要).请帮助我,以便我可以将自己的引脚分配给输出以进行练习. :)

您可以给我回复[删除电子邮件地址] ..我期待收到答复..

Hello, I have read your program for the LED ON/OFF & found it to be pretty simple to understand. The only thing I am confused with is this command :

" TRISB=0xF0; // RB4:RB7 are input ; 11110000 in binary "

I want to know how did you find out that 0xF0 is the right value for the ports RB4:RB7, and how to know what is the hex code of each port if I want to. Kindly help me with that so that I can assign my own pin to the output just for practice. :)

You can reply me to [e-mail address removed] .. I am looking forward for a reply ..

推荐答案

bhai_kaju写道:
bhai_kaju wrote:

我唯一感到困惑的是...

The only thing I am confused with is ...



...我没有注意到文章末尾的论坛上应该发布问题或评论的地方.



... I did not notice the forum at the end of the article where questions or comments should be posted.


您似乎在回应 ^ ].您应该在该文章底部的论坛中发布有关该文章的问题.

就您的问题而言,寄存器中的每个位都指向端口引脚.当您阅读芯片文档中有关寄存器的文档时,会发现哪个引脚以及该引脚的位值代表什么.如果您没有该文档,则最好获取它.完成后,开始阅读. :)
You seem to be responding to this article[^]. You should post you questions about an article in the forum at the bottom of that article.

As far as your question goes, each bit in the register refers to a port pin. Which pin and what a value of the bit for that pin represents is something you would find out when you read the documentation for the register in the chip documentation. If you don''t have that documentation, you''d better get it. Once you do, start reading. :)


bhai_kaju写道:
bhai_kaju wrote:

我找不到任何类型的端口号分配或十六进制相等的.因此,我怎么知道该写什么代码,以及是否有人可以告诉我此代码的含义:

"#byte port_b = 6//IC = 16c84"

为什么port_b = 6,而不是4或5或其他.

I couldn''t find any kind of port number assignment or HEX equivalent. So, how do I know what to write in the code, and if anyone could tell me the meaning of this code :

" #byte port_b=6 // IC =16c84 "

why port_b = 6, not 4 or 5 or anything else.





bhai_kaju也写道:
bhai_kaju also wrote:

我在PIC16C84的存储器组织中发现了与此代码有关的一件事"#byte port_b = 6//IC = "16c84"是,将整个PORTB分配给"6h",这就是为什么给port_b赋予值6的原因.如果它是port_a,那么该值将改为5.是正确的还是我在某个地方犯了一些错误?

One thing I found out in the memory organisation of PIC16C84 in relation to this code " #byte port_b=6 // IC =16c84 " is that, the entire PORTB is assigned to "6h", that is why port_b has been given a value 6. If it had been port_a then the value would have been 5 instead. Is it correct or am I making some mistake somewhere ??



[已编辑-已更正]

是的,你是对的.当我第一次阅读本文时,我陷入了阅读我所期望的而不是所写内容的陷阱.对不起.这是一个特殊的指令.它指示编译器将字节变量" port_b定位在物理地址6上,正如您从文档中正确确定的那样. :thumbsup:给你.我得到了:thumbsdown:第一次误读它.正如DaveyM69所说,通常会在提供的文件中包含这些指令,而不是自己编写文件.该文件对其他寄存器也将具有类似的指令.

这使您可以在代码中使用符号"port_b"从寄存器中进行读取或写入,并影响端口.假设您使用的是C语言,则可以编写代码:





Yes, you are correct. When I first read this, I fell into the trap of reading what I expected, rather than what was written. Sorry. This is a special directive. It instructs the compiler to locate the byte "variable" port_b at physical address 6, exactly as you correctly determined it should be from the documentation. :thumbsup: for you. I get a :thumbsdown: for misreading it the first time through. As DaveyM69 said, you would generally include a provided file with these directives, rather that writing it yourself. That file would have similar directives for the other registers as well.

This lets you use the symbol "port_b" in your code to read or write from the register and affect the port. Presuming that you are working in C, you could then write in your code:

port_b = 4;



由于4是二进制的00000100,因此将配置为输出的所有端口B引脚(引脚2除外)设置为低电平.如果将引脚2配置为输出引脚,则会将其拉高.



Since 4 is 00000100 in binary, this would set all port B pins that are configured as outputs, except pin 2, low. If pin 2 was configured as an output pin, it would bring it high.


这篇关于端口分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆