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

Sat Jul 21 2018, 06:21 AM
Dibakar Bhanja Chowdhury
By using a 555 timer how can I expand the range of the mobile phone jammer? Please reply me asap
Sun May 20 2018, 10:01 AM
justinb
how to write and execute a program that read the keypad button and display the number on 7 segment on intel8051 at89s52 in assembly language?
Thu May 17 2018, 06:36 AM
HAMZA TAJ
sir iwant to ask about controller of three phase supply by using back to back thyristor instead of triac....will u give me some guideline?
Sat Apr 28 2018, 12:54 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Fri Apr 27 2018, 08:09 PM
@kaiserslautern Post in forum
Wed Apr 25 2018, 07:09 AM
kaiserslautern
Hello everyone, using software uart is a very good idea for a second serial port. Thank you so much. I would kindly like to know how to connect this port to the PC?
ExperimenterUK
Sat Apr 21 2018, 07:50 PM
This is a community site. Feel free to help anyone needing advice
hareeshchamiyar
Thu Mar 29 2018, 10:47 AM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 10:45 AM
can any one using dspic30f2010.
Thu Mar 29 2018, 06:03 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]

Downloads

Comments

bdmehta
Tue May 22 2018, 02:30 AM
kmag1953
Sun Apr 29 2018, 07:09 PM
udiwonder
Sat Apr 28 2018, 12:41 PM
pirpiri
Sat Apr 21 2018, 03:35 PM
Pater
Fri Apr 20 2018, 02:38 PM
jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM

Online

Guests: 72, Members: 0 ...

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

Members: 37998
Newest member: bdmehta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 17 2018, 08:31 PM
Thank you.I'm happy it worked out for you.
LAMBO Avatar
Posted By LAMBO
Tue Jul 17 2018, 09:52 AM
hi sir sorry for the late reply thank u sir for he...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 12 2018, 08:27 PM
I'm glad we got there in the end :)>whats differen...
LAMBO Avatar
Posted By LAMBO
Thu Jul 12 2018, 06:51 AM
hi sir as u mentioned above to change crystal and ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 10 2018, 07:20 PM
I assume you meant a AT89S52.It seems to me that...
LAMBO Avatar
Posted By LAMBO
Tue Jul 10 2018, 06:06 AM
hi sir i have checked now much of the distortion ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 09 2018, 06:55 PM
Okay that is very interesting.I have attached two ...
LAMBO Avatar
Posted By LAMBO
Mon Jul 09 2018, 08:14 AM
hi sir as u mentioned above program i have tried ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jul 06 2018, 11:58 PM
Okay..That motor creates a lot of sparks which mig...
LAMBO Avatar
Posted By LAMBO
Fri Jul 06 2018, 01:33 PM
hi sir as u told >Try the original code againi hav...