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
Tue Feb 20 2018, 09:31 PM
Join up.. and post your problem
Mon Feb 19 2018, 04:47 PM
ashishkumar
i needs help for my project
Mon Feb 19 2018, 04:46 PM
ashishkumar
can i join you guys
ExperimenterUK
Mon Feb 05 2018, 03:08 AM
Hi Dave. Good to see you.
DavesGarage
Wed Jan 10 2018, 01:25 AM
It's been a few years since I poked around here - Hi all...
ExperimenterUK
Tue Jan 09 2018, 12:49 AM
Hi TPS. it's been a while..
۞ TPS ۞
Mon Jan 08 2018, 12:12 AM
hello
Thu Jan 04 2018, 07:20 PM
sayyad affrid
its AT89S52
Thu Jan 04 2018, 07:20 PM
sayyad affrid
sir, i want embedded c code for ultrasonic sensor having buzzer interfaced with AT9S52
Tue Dec 19 2017, 01:42 AM
zafir
i am making digital voltmeter using AT89C51, ADC and LCD 16x2,,, kindly someone please send me hex file in assembly language

Downloads

Comments

Daro12_76
Wed Feb 21 2018, 05:01 PM
radhikanathani
Wed Feb 21 2018, 06:55 AM
Narayani
Wed Feb 21 2018, 04:10 AM
Parth09
Tue Feb 20 2018, 07:53 AM
goutham
Mon Feb 19 2018, 02:49 AM
kks
Sun Feb 18 2018, 05:59 PM
justotemon
Sat Feb 17 2018, 07:14 AM
nicolekristen
Fri Feb 16 2018, 12:19 PM

Online

Guests: 61, Members: 0 ...

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

Members: 37970
Newest member: Daro12_76
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 23 2018, 01:12 AM
Add pull- ups for EN and RS.change your defines t...
Ansh12 Avatar
Posted By Ansh12
Thu Feb 22 2018, 01:36 AM
Can you post your Proteus files.ExperimenterUKThan...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Feb 21 2018, 09:07 PM
The code you refer to is to drive the circuitshown...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Feb 21 2018, 05:41 PM
Can you post your Proteus files.You will need pull...
radhikanathani Avatar
Posted By radhikanathani
Wed Feb 21 2018, 02:39 PM
I want to design a system for vehicle tracking and...
Narayani Avatar
Posted By Narayani
Wed Feb 21 2018, 04:17 AM
Hello,Your tutorial really helped me understand st...
Ansh12 Avatar
Posted By Ansh12
Wed Feb 21 2018, 12:53 AM
while(1) { key = Get_key(); // Get p...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Feb 20 2018, 04:16 PM
Change .....while(1) { key = Get_key(...
kks Avatar
Posted By kks
Tue Feb 20 2018, 02:00 PM
UPDATE - It's working now, but after successfully ...
paulfjujo Avatar
Posted By paulfjujo
Tue Feb 20 2018, 09:21 AM
HelloAt least, i found myself the responseThis fol...