PORT3 issues

General discussion on mikroC PRO for 8051.
Post Reply
Author
Message
fkay13
Posts: 2
Joined: 08 Mar 2012 18:56
Location: Brazil

PORT3 issues

#1 Post by fkay13 » 08 Mar 2012 19:16

Hello,

i was trying do compile very simple programs to learn and get used to mikroc to migrate from assembler. I get some unusual behave when accessing bits from PORT3 and others PORTS.

example:
this code

Code: Select all

#define LED P3.B4

void main()  {
   while(1) {
       LED = !LED;
       delay(50);
   }
}
and then looking at the list file i found

Code: Select all

;Teste.c,15 :: 		LED = !LED;
0x0048	0xE5B0    	MOV A, P3
0x004A	0xA2E4    	MOV C, ACC.B4
0x004C	0xB3      	CPL C
0x004D	0xE5B0    	MOV A, P3
0x004F	0x92E4    	MOV #224.B4, C
0x0051	0xF5B0    	MOV P3, A
the compiler is accessing PORT3 as 8bits register and not bit addressable register.

Then i try doing this

Code: Select all

bdata volatile sfr unsigned char PORTA3 absolute 0xB0;
#define LED PORTA3.B4

void main()  {
   while(1) {
       LED = !LED;
       delay(50);
   }
}
then i get this on list

Code: Select all

;Teste.c,15 :: 		LED = !LED;
0x0048	0xA2B4    	MOV C, P3.B4
0x004A	0xB3      	CPL C
0x004B	0x92B0    	MOV P3, C
still bad. The compiler write the wrong bit.
then i try this:

Code: Select all

bdata volatile sfr unsigned char PORTA3 absolute 0xB0;
sbit LED at PORTA3.B4;

void main()  {
   while(1) {
       LED = !LED;
       delay(50);
   }
then i get this:

Code: Select all

;Teste.c,15 :: 		LED = !LED;
0x0048	0xA2B8    	MOV C, 180.B4
0x004A	0xB3      	CPL C
0x004B	0x92B4    	MOV 180, C
now the compiler read the wrong bit but write the correct one.

How other way to solve this?

Regards,
Fabricio K.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: PORT3 issues

#2 Post by janko.kaljevic » 09 Mar 2012 14:51

Hello,

Thanks for reporting this.
I have confirmed it and forwarded to our developers, it will be fixed as soon as possible.

At the moment I can only suggest to use first method, which is working fine.

Best regards.

fkay13
Posts: 2
Joined: 08 Mar 2012 18:56
Location: Brazil

Re: PORT3 issues

#3 Post by fkay13 » 09 Mar 2012 18:29

Hi,

thanks for the answer. The first method is ok, but when you combine outputs with inputs eventually you get problems too, because the processor will read the port and if the input was ´0´ at this time he will write back ´0´. This in fact was my first problem, and whne i start investigate what was happening i found the others issues.

Regards.

am_unir
Posts: 6
Joined: 23 May 2016 17:25

Re: PORT3 issues

#4 Post by am_unir » 23 May 2016 17:36

Hi,

I have a similar Problem and wondering if this Problem is still unchanged or if I did something wrong...

I have a button on Port P3.B4 and a LED on Port P3.B5

Code: Select all

sbit mybutton at P3_4_bit;
sbit myled at P3_5_bit;
if the button will be pushed I would like to set the LED Bit to 0:

Code: Select all

if(mybutton==0) myled=0;
This works just sometimes. In the other cases it will set the Input (!) mybutton to 0....? In the assembly it seems that the Compiler still uses a Byte Access...

If I use

Code: Select all

if(mybutton==0) asm clr P3.5;
Everything works fine...

Is the bug still valid or did I something wrong?
Alex

djolea
Posts: 24
Joined: 15 Oct 2011 11:56

Re: PORT3 issues

#5 Post by djolea » 20 Jun 2016 21:03

Definitely, it is a bug. And only for P3. If u use P3.5 as output, and P3.4 as input, when output is Lo, if input is set low, input stays low (latches) even if button released – input act as output. Use asm instruction, or write whole port:

Code: Select all

 
 P3 |= 0b01000000;
 Delay_us(1);
 P3 &= 0b10111111;
 Delay_us(1);
in this way, other port pins are not affected

Post Reply

Return to “mikroC PRO for 8051 General”