Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how can i access to every bit of ADRESH

Status
Not open for further replies.

Jiadong Yao

Member level 1
Joined
Mar 19, 2014
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
278
Using the ADC
I want to display the result on RB0 to RB5 and RA2 to RA3.

How can i get every single bit in the ADRESH register then assign them to every port?

Thanks
 

Is your ADC result right justified or left justified ? If right justified then ADRESH only contains 2 bits (lower 2 bits of ADRESH) of data, other higher bits are cleared. Did you mean to say ADRES that is ADRESH and ADRESL ?

See if this works.


Code C - [expand]
1
2
3
LATB = (LATB & 0xC0) | (ADRESH & 0x3F)
LATAbits.LATA2 = ((ADREH & 0x40) >> 6)
LATAbits.LATA3 = ((ADREH & 0x80) >> 7)

 

Is your ADC result right justified or left justified ? If right justified then ADRESH only contains 2 bits (lower 2 bits of ADRESH) of data, other higher bits are cleared. Did you mean to say ADRES that is ADRESH and ADRESL ?

See if this works.


Code C - [expand]
1
2
3
LATB = (LATB & 0xC0) | (ADRESH & 0x3F)
LATAbits.LATA2 = ((ADREH & 0x40) >> 6)
LATAbits.LATA3 = ((ADREH & 0x80) >> 7)


Hi, nice to see you.
Well actually i dont understand your code. could you explain me what "|" and ">>" mean?
why you use LAT rather than PORT? is there any difference?? i am always confused about these two.

thank you
 

| means ORing and >> means right shift the bits. If you use PIC18F then you have to use LATx for output port.
 

| means ORing and >> means right shift the bits. If you use PIC18F then you have to use LATx for output port.

But i always write code in this way: e.g. PORTB = ADRESH;
Then the 8 bits will be shown on all RBs.
isn't it correct?

by the way, can i add you on facebook? if you don't mind, you can add me. my name is jiadong yao.
 

Yes, if you are assigning 8 bits of ADRESH to 8 bits of PORTB then it is correct but if you are using 18F devices then use LATB.
 

Yes, if you are assigning 8 bits of ADRESH to 8 bits of PORTB then it is correct but if you are using 18F devices then use LATB.

I am using 18F device. but when i assign, i still use PORTB rather than LAT. it seems that everything works fine.
what is the problem?? i really dont know.
 

In most cases both will work. PORTx is the same as on other PIC families, the LAT (LATch) instruction writes to a latched output pin and avoids the potential 'read modify write' problem. As LAT is always safe to use, it is the preferred method.

Brian.
 

In most cases both will work. PORTx is the same as on other PIC families, the LAT (LATch) instruction writes to a latched output pin and avoids the potential 'read modify write' problem. As LAT is always safe to use, it is the preferred method.

Brian.

I google the "read modify write" problem.
Now i completely understand. Thank you very much.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top