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

Mon Oct 22 2018, 05:37 AM
Iris Spain
aaa快乐是大家的aaa
ExperimenterUK
Sat Sep 29 2018, 06:28 PM
Please post questions in the forum.
Sat Sep 29 2018, 11:26 AM
Ashfaq Ch
hi i have some AT89C51RC microcontrollers already programed. some one help us to how to download from AT89C51RC and after study and edit all corractions reload to AT89C51RC controller
shshistiem
Wed Sep 12 2018, 10:58 PM
hii!! some1 please let me know how i ll get rfid code to 8051 by WEIGAND mode
DrNossberg
Tue Sep 11 2018, 08:09 PM
is there anyone here?
Mon Aug 27 2018, 07:30 AM
bun
Hello everyone!
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

Downloads

Comments

PCBindex
Fri Sep 14 2018, 02:45 AM
sirkit
Thu Sep 13 2018, 04:46 AM
shshistiem
Wed Sep 12 2018, 10:36 PM
DrNossberg
Tue Sep 11 2018, 03:25 PM
ranjanvh
Thu Sep 06 2018, 02:28 PM
rbbhamre
Tue Sep 04 2018, 06:15 PM
Tressie
Sun Sep 02 2018, 02:20 PM
Sudhansudeep
Fri Aug 31 2018, 08:26 AM

Online

Guests: 53, Members: 0 ...

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

Members: 38006
Newest member: PCBindex
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Sep 13 2018, 08:39 PM
First of all, by reading your reply, I abandoned m...
DrNossberg Avatar
Posted By DrNossberg
Thu Sep 13 2018, 03:49 PM
Hi, thanks you for your reply ^^ First of all, by ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Sep 12 2018, 12:12 AM
HiThere are several issues here.The original 8051 ...
DrNossberg Avatar
Posted By DrNossberg
Tue Sep 11 2018, 08:08 PM
Hello everybody!First of all let me explain some s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Sep 07 2018, 05:08 AM
The compiler thinks the micro doesn't have enough...
Sudhansudeep Avatar
Posted By Sudhansudeep
Fri Sep 07 2018, 02:59 AM
this is the build output message
Sudhansudeep Avatar
Posted By Sudhansudeep
Fri Sep 07 2018, 01:38 AM
Change the mobile number as [number removed] in t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Sep 06 2018, 08:56 PM
I don't know what the problem is, I get no errors....
Sudhansudeep Avatar
Posted By Sudhansudeep
Thu Sep 06 2018, 01:12 PM
the code is Attachment ...
Sudhansudeep Avatar
Posted By Sudhansudeep
Thu Sep 06 2018, 12:48 PM
the code is same as u sent me for 16 chars