Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

strange behaviour of PORTA Register.

Status
Not open for further replies.

absfast123

New Member
I m using 18f97j60 with c18 compiler, I have configured in the start eth led off, then in the main i set trisa=0; then PORTA=255;
When i run this code under debugger and after some time i pause the program and read special function registers values there is
PORTA VALUES ARE 10010000
LATA VALUES ARE 00111111
and I am using leds on ra0, ra1, ra2 all three leds are on means lata value is matcing led status, but in porta reg all leds seems off(wrong value).

What is this and how is this?
Regards,
AB Sami.
 
You are overloading the port pins and so they read back as low. Add a series resistor to each LED to limit the current to 20mA.

Mike.
 
I have resistors in series

Hi Mike,
Thank you for your reply. I have already resisters of 470 ohm in series of all three leds. and supply voltage are 3.32 volts so, current for each led is limited upto maximum near about 7 miliamp.
is this 20miliamp is for single pin or whole port?
Regards,
AB Sami.
 
There is another strange behaviour if i set indivisual bits using PORTAbits.RAx of led ra1 and ra2 to 1 then only ra2 led is glowing. and lat value is correct as leds but PORTA register values are 0 for both of these.
but when i set indivisual values using LATAbits.LATAx then both leds glow and lat register values are correct and porta register values still remain zeros
. but my results are comming correct e.g both leds glow. but in upper case my results got wrong.
Thank you,
Regards.
AB Sami.
 
If you set individual bits of port A then it reads PortA, sets the bit and then writes it back. This is why you should use the latch register and not the port register. Can you measure the voltage you are getting on the pins that are reading zero?

Mike.
 
led that is off voltage are 0.00v glowing led has 3.32v. both in both pins i have used PORTAbits.bitx . but only 1 is glowing.
 
problem is solved problem as in adc config. but still i dont know one thing why with latabits leds work correctly but not work with portabits.
thank you very much.
 
That explains it, any pins set as analogue always read back as zero.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top