Discussion in "8051 Discussion Forum" started by    paulfjujo    Feb 13, 2018.
Tue Feb 13 2018, 12:28 PM
#1
hello,


i tried this litle code with MikroC for 8051
declare MCU as AT89C2051 FOSC=12MHz
i put R=2,7K as pull up on P2.0 & P3.1 (RX & TX pins)
A led on P3.7 and on P1.7

When i initialise UART_Init (9600); i get error=1 must be 0 if OK ..
Even this status , i pass over it ...then just display the error in hexadecimal after UART_Init
and UART works fine
Displaying correct datas , and able to get data from Keyboard and and display it.
My probleme is on the led P1.7 .. Allways "ON "
.. and all othe P1 pins are "ON"
P3.7 led works fine .

May i forget something ?
Why MikroC tell me Error on UART , even it is working fine ?
Data analyser show UART TX bit width = 106µS instead of 104µS at 9600bds ..so a few baud rate error
(i don't get any answer from MikroC 8051 !)

my cMikroC projetc in zip :







[ Edited Tue Feb 13 2018, 12:30 PM ]
Tue Feb 13 2018, 09:38 PM
#2
>When i initialise UART_Init (9600); i get error=1 must be 0 if OK ..

error=1 is baud rate too high.
Software uarts are slower than those in hardware. Try 4800.

"Why MikroC tell me Error on UART , even it is working fine ?"

It may be close enough to work most of the time.

"My problem is on the led P1.7 .. Allways "ON ".. and all othe P1 pins are "ON"

High is the default setting, so you need to set them low.
P1.7 is set high by the error, but not set low again in your code.

8051 pins don't have an "Input" mode like most micros.
They are also only weakly high, they can't source much current.

It is normal to set the pin high and have inputs pull it low.
Because pins are only weakly high, but can sink more current,
it is common to use low as 'on' and arrange the circuit to suit
Wed Feb 14 2018, 02:25 PM
#3
hello,

Thank for your answer,

but today i wrote this short code , to test only P17 and P35 P37
without additional as UART ..
with a led + 390 ohms pull down resistor on this 3 pins.
Led on PORT P1 never react ..
if i initilaise P1=0xFF LedR is allways ON
if in initialise P1=0 LedR is allways OFF
it seems tha Bit command doesnt work .. or where is my mistake ?


#define MCU "AT89C2051"
#define Version "180214"
#define Directory "D:\\_MikroC PRO for 8051\\_MesProjets\\_Test_1er\\"
#define Project "Test_1er_AT89C2051.mcp51"
#define Source "Test3_AT89C2051_3leds.c"


sbit LedV at P3.B7;
sbit LedR at P1.B7;
sbit LedY at P3.B5;

int j;

void main() 
{
//P1=0xFF;   // =>
 LedR allways ON !!
P1=0x00;   // =>
 LedR NEVER  ON !!
P3=0;
do
{

 LedV=0;
 LedR=0;
 LedY=0;
 Delay_ms(1000);
  for (j=0;j<10;j++)
  {
     LedV=1;
     LedR=0;
     LedY=1;
     Delay_ms(1000);
     LedV=0 ;
     LedR=1;
     LedY=0;
     Delay_ms(1000);
     LedY=1 ;
     LedR=0;
     LedV=1;
     Delay_ms(1000);
     LedV=0 ;
     LedY=0;
     LedR=1;
     Delay_ms(1000);
     LedV=1 ;
     LedY=1;
     LedR=1;
      LedV=0 ;
     LedY=0;
     LedR=0;
     Delay_ms(1000);
  }
 }while(1);
}



i am not familiar with this MCU ( i know PIC family)
and find very strange to don't define the way Write or Read..for the MCU Pins
does it means
Write on a pin => pin is an Output
Reading a pin => s pin is an input
maybe too simple to understand .

I just did another test, with a similar aplication, but written is ASM
I used ASM51 to get the *.hex file .. load into AT89C2051
and now , it WORKS FINE .. ( with same hardware ).
asm Program test
;14-02-2018
;Flash_3_LEDS_b.asm
START:  CPL P3.5
		CPL P3.7
		CPL P1.7
ICI:    ACALL WAIT  
        CPL P3.5
		CPL P3.7
		CPL P1.7
        ACALL WAIT
        CPL P1.7
 		ACALL WAIT
 		CPL P3.5
		ACALL WAIT
 		CPL P3.7
        SJMP ICI

WAIT:   MOV R4,#05H
WAIT1:  MOV R3,#00H
WAIT2:  MOV R2,#00H
WAIT3:  DJNZ R2,WAIT3
        DJNZ R3,WAIT2
        DJNZ R4,WAIT1
        RET
        END


so ??? about C version ? or the probleme is ME ?




[ Edited Wed Feb 14 2018, 03:49 PM ]
Wed Feb 14 2018, 08:43 PM
#4
>strange to don't define the way Write or Read..for the MCU Pins

Yes it is strange.
The 8051 is the only type without an "Input" mode that I know of.
Probably because the design is so old.

>does it means
>Write on a pin => pin is an Output
>Reading a pin => s pin is an input

The pin can only be in output mode,
but you can read the level on the pin at any time.

So,set the pin high.
Read the pin, you get 1
Force the pin low.. by connecting to ground.
Read the pin, you get 0

8051 pins use internal pull-ups,
so shorting to ground is okay.
Warning .. setting the pin low and forcing high, is not okay.

> just did another test
>...but written is ASM
>...it WORKS FINE
>...so ??? about C version ? or the probleme is ME ?

Really the problem is with the Mikroc compiler.
They decide how to define pins and how to access them.
It may even vary between versions of the same compiler.
In this case the correct way to define a bit is..

sbit LedV at P3_7_bit;



[ Edited Thu Feb 15 2018, 06:46 AM ]
Tue Feb 20 2018, 09:21 AM
#5
Hello

At least, i found myself the response
This following initialisation mode is OK

replace sbit ..
by
#define Switch P3.B4
#define Led P3.B5
and use as output or as input is OK

Then, i successfully build my "Horloge 6 digits" with MikroC for 8051.

Thank's for your answers .

Cordialement
Paul

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Mon Jan 07 2019, 09:01 AM
@REVOCATUS please post in the AVR forum
Mon Dec 24 2018, 02:55 PM
REVOCATUS MATEMU
sorry I mean referee boards for player substitution
Mon Dec 24 2018, 02:54 PM
REVOCATUS MATEMU
hi am.looking how to build referee by using Atmega 328 and its codes
Sat Dec 15 2018, 07:15 PM
Arslan ayoub
Hii ,, can I get the simulation of numeric keypad lock on proteus
ExperimenterUK
Mon Dec 03 2018, 10:47 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 12:13 PM
help!me!
help! I don't understand busy flag!
Mon Dec 03 2018, 01:31 AM
ile
hello
Mon Nov 12 2018, 11:28 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....
bgk3678
Tue Nov 06 2018, 08:06 PM
kindly any one give solution for my problem
ExperimenterUK
Tue Nov 06 2018, 03:18 AM
Pins high is the normal state. You need a program to set them low

Downloads

Comments

garfield0929
Sun Jan 20 2019, 12:48 AM
servprov
Thu Jan 17 2019, 06:44 AM
marcomilazzo
Wed Jan 16 2019, 04:21 PM
sandhyashree
Wed Jan 16 2019, 04:04 PM
SONACHAI1234
Sun Jan 06 2019, 08:14 AM
manan.gulyaani
Tue Jan 01 2019, 07:58 AM
etech
Sun Dec 30 2018, 07:44 PM
NeilC
Sun Dec 23 2018, 07:39 PM

Online

Guests: 67, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38039
Newest member: garfield0929
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Jan 06 2019, 10:37 PM
Which 8051 chip are you using ?
SONACHAI1234 Avatar
Posted By SONACHAI1234
Sun Jan 06 2019, 08:21 AM
Hi,By mistakenly i burn rx program in my 8051 micr...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Dec 19 2018, 06:27 PM
Nobody knows?sifirsekizThe problem is that you are...
sifirsekiz Avatar
Posted By sifirsekiz
Wed Dec 19 2018, 12:15 PM
sifirsekiz Avatar
Posted By sifirsekiz
Sun Dec 16 2018, 11:13 PM
Guys pleaseeeee :((
sifirsekiz Avatar
Posted By sifirsekiz
Sat Dec 15 2018, 07:09 PM
HiThe pulse-sensor-amped has an analogue output.Th...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Dec 15 2018, 07:01 PM
HiThe pulse-sensor-amped has an analogue output.Th...
sifirsekiz Avatar
Posted By sifirsekiz
Sat Dec 15 2018, 09:02 AM
and ı have pulse sensor one out but anolog use 805...
sifirsekiz Avatar
Posted By sifirsekiz
Sat Dec 15 2018, 08:56 AM
HiMembers can supply code and diagrams if they wan...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Dec 14 2018, 11:54 PM
HiMembers can supply code and diagrams if they wan...