Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ..
Posted
Updated 18-Mar-10 4:24am
v3

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.
 
Share this answer
 
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. :)
 
Share this answer
 
v2
bhai_kaju wrote:
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 also wrote:
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 ??


[Edited - corrected]

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;


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.
 
Share this answer
 
v3
In a PIC uC, TRISX means Tristate-Port.

When a TRIS bit is set to 0 it's port pin is set to be an output, when 1 it is set to be an input.

So if you have for example portB which has pins RB0:RB7 you can set the individual pins as inputs or outputs by either writing a complete value to the corresponding TRIS, in this case TRISB or individually setting the bits to 1 or 0 by using BSET or BCLR e.g.BSET TRISB, 0.

The rest is straight forward binary to Hex. A byte (8 bits) can be split evenly into two halves of 4 bits (2 nibbles) - this can be represented by a 2 character hexadecimal number. Each nibble looks like this:
Binary   Hex
MSn LSn
00000000 0x00
00000001 0x01
00000010 0x02
00000011 0x03
00000100 0x04
00000101 0x05
00000110 0x06
00000111 0x07
00001000 0x08
00001001 0x09
00001010 0x0A
00001011 0x0B
00001100 0x0C
00001101 0x0D
00001110 0x0E
00001111 0x0F
00010000 0x10
-------------
11111111 0xFF
The rightmost bit in our example is RB0 and the leftmost is RB7
 
Share this answer
 
v2
I have the complete datasheet of the CHIP but 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.

Thanks in advance !! :-D
 
Share this answer
 
Many many thanks to all of you who spared some time from you busy schedule to clarify my doubts. I am clear now and my concepts just got better upon reading the answers, hats off to you guys !! :thumbsup: :-D


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 ??
 
Share this answer
 
v2
Yes, in that case it is referring to the actual address of the port as listed in the register file map in the datasheet[^] on page 12.

Normally you wouldn't define this yourself but instead include the file for the device that Microchip provide (installed along with MPLAB IDE) as everything is corrctly defined for you. For 16C84 it can be found in C:\Program Files\Microchip\MPASM Suite\P16C84.INC
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900