MikroC 8051 and AT89C2051 problem on P1.X output

General discussion on mikroC PRO for 8051.
Post Reply
Author
Message
paulfjujo
Posts: 1550
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

MikroC 8051 and AT89C2051 problem on P1.X output

#1 Post by paulfjujo » 12 Feb 2018 21:09

Hello,
it is my first project with a AT89C2051
Q=12MHz

started from an mikroE example

Impossible to work with UART if i take care about ther Error returned by UART Init..
In fact , UART works very well .. Transmit and receive also .
But I connected one led (Green) on PORT P3.7
and another (Red Led) on P1.7
Only the Green Led on P3.7 is working..
The other is allways at status ON ..
in fact all pin PORT1 are ON ???

I wrote a litle program in ASM to blink this 2 output leds .. it's works fine .

What is the problem .. a bug MikroC 8051 ?

Code: Select all

// ATTENTION : fichier HEX cree contient <CR><LF> en fin de ligne
  // Notepad++ Macro :  ENLEVE_CR_Laisse_LF
 // probleme : Led Rouge sur P1_7 toujours ON ?????
 // led Verte OK
 // UART OK
#define MCU "AT89C2051"
#define Version "180212"
#define Directory "D:\\_MikroC PRO for 8051\\_MesProjets\\"
#define Project "Test_1er_AT89C2051.mcp51"
#define Source "_Test_1er\Test3_AT89C2051_180212.c"   // avec led rouge sur P16

// Soft UART pins connections

    //ac:AT89_Pinout_

sbit  Soft_Uart_RX at P3_0_bit;
sbit  Soft_Uart_TX at P3_1_bit;
sbit LedV at P3_7_bit;
//sbit LedR at P1_7_bit;   //Test1_AT89C2051_180212.c"
sbit LedR at P1_6_bit;
//sbit Led_Dir at TRISC7_bit;

char  i, error, byte_read;
int j;
char CRam1[7];

void Print(char *px)
{
 while (*(px)>0)  Soft_UART_Write(*px++);
 

}

void main() 
{

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

//2 - error, requested baud rate is too low
//1 - error, requested baud rate is too high
//0 - successful initialization
error=Soft_UART_Init(9600,0);
ByteToHex(error,CRam1);
Print(CRam1);
if (error >0)
{
 for (j=0;j<10;j++)
{
 LedV=~LedV;
 LedR=0;
 
 //LedV=0     //P3_7
  Delay_ms(400);
 LedV=~LedV;
 LedR=1;
 Delay_ms(400);
 }
 }
 else   LedV=1;
 
Delay_ms(1000);
LedV=0;

  for (j = 'z'; j >= 'A'; j--)
   {          // Send bytes from 'z' downto 'A'
    Soft_UART_Write((char)j);
    Delay_ms(100);
    LedV=~LedV;
  }
  LedV=0;
  LedR=0;
   while(1)
   {                              // Endless loop
    byte_read = Soft_UART_Read(&error);   // Read byte, then test error flag
    if (error>0)                            // If error was detected
     {
      LedR=~LedR;
      Delay_ms(1000);
      }
    else
    {
      Soft_UART_Write(byte_read);         // If error was not detected, return byte read
      LedR=0;
      LedV=~LedV;
    }
   }
}

/*

===============================================
MCU pastille VERTE => problemo

clignotement led OK,
mais sortie sur retour init UART à 9600bds error = 01  (avec FOSC=12MHz) !

=>modif programme
voir Resultat_programmation_AT89_Bleu_180212.log

Clignotement Led verte OK
mais Led Rouge reste en permmanence à l'etat 1 ???
Par contre en passant Outre error UART=01 , l'UART est OK
affichage correct de l'alphabet

sur terminal:
01zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA

La reception est OK aussi, char by Char,
si envoi de string => telescopage et fin du string bouffée.
La Pin P1_7  sortie Led Rouge semble HS ..sortie toujours à 1 ???

=====================================================
MCU pastille VIOLETTE:      idem probleme

=================================================
MCU Bleu avec sortie sur P1_6  .. idem
en fait TOUTES LES PIN P1 sont à 1
=====================================================

0 1 mikroc8051.exe -MSF -DBG -pAT89C2051 -ES -RA -C -O11111014 -fo12 -N"D:\_MikroC PRO for 8051\_MesProjets\_Test_1er\Test1_AT89C2051.mcp51" -SP"D:\_MikroC PRO for 8051\defs\" -SP"D:\_MikroC PRO for 8051\_MesProjets\_Test_1er\" -SP"D:\_MikroC PRO for 8051\Uses\ATMEL\" -SP"D:\_MikroC PRO for 8051\_MesProjets\" "Test3_AT89C2051_180212.c" "
_lib_Math.mcl" "
_lib_MathDouble.mcl" "
_lib_System.mcl" "
_lib_Delays.mcl" "
_lib_Conversions.mcl" "
_lib_SoftUART.mcl"
0 122 Compilation Started
_lib_Delays.c
418 123 Compiled Successfully
_lib_Delays.c
0 122 Compilation Started Test3_AT89C2051_180212.c
107 123 Compiled Successfully Test3_AT89C2051_180212.c
0 127 All files Compiled in 63 ms
0 1144 Used BDATA RAM (bytes): 9 (56%) Free BDATA RAM (bytes): 7 (44%) Used BDATA RAM (bytes): 9 (56%) Free BDATA RAM (bytes): 7 (44%)
0 1144 Used DATA RAM (bytes): 23 (22%) Free DATA RAM (bytes): 81 (78%) Used DATA RAM (bytes): 23 (22%) Free DATA RAM (bytes): 81 (78%)
0 1144 Used ROM (bytes): 1424 (70%)  Free ROM (bytes): 624 (30%) Used ROM (bytes): 1424 (70%)  Free ROM (bytes): 624 (30%)
0 125 Project Linked Successfully Test1_AT89C2051.mcp51
0 128 Linked in 16 ms
0 129 Project 'Test1_AT89C2051.mcp51' completed: 157 ms
0 103 Finished successfully: 12 févr. 2018, 20:09:42 Test1_AT89C2051.mcp51


*/

Result on diplay terminal is OK, even wit error=01h
sur terminal:
01zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA
hardware:
at89c2051_1er_Schema_180112.jpg

paulfjujo
Posts: 1550
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: MikroC 8051 and AT89C2051 problem on P1.X output

#2 Post by paulfjujo » 14 Feb 2018 15:15

even with this short code
impossible to drive a led on port P1 (LedR) ?
Please, could you tell me where is my mistake ?

Ok for Leds on P3.

led + pull down resistor 390 ohms

Code: Select all


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);
}

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: MikroC 8051 and AT89C2051 problem on P1.X output

#3 Post by lana.arsic » 14 Feb 2018 17:34

Hi,

Unfortunately, I cannot test AT89C2051 at this moment,
since it is not supported in mikroProg for 8051 yet.

But I have tested your code on AT89S8253 and it seems to work properly.

When you test with AT89C2051, do the diodes turn on and off
at the beginning of the main program, i.e. does it least that part of code work properly?

Kind regards,
Lana

paulfjujo
Posts: 1550
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: MikroC 8051 and AT89C2051 problem on P1.X output

#4 Post by paulfjujo » 15 Feb 2018 10:48

Hello Lana ,
Unfortunately, I cannot test AT89C2051 at this moment,
since it is not supported in mikroProg for 8051 yet.
On mikroC for 8051 , i can choose AT89C2051 as MCU ...

Only led on port P3 is working ..
Nothing on port P1.

i wrote a similar program (100% ASM) with ASEM51 to check it
The 3 leds are workink .....OK.

Code: Select all

;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

i did another test with Mikro Basic for 8051
.. same problem ,no reaction on port P1


Why this so simple program doesn't work ,written in C ?
what i understund with this MCU :
write on a pin ,make this pin as an output
Read on a pin make this pin as an input

paulfjujo
Posts: 1550
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: MikroC 8051 and AT89C2051 problem on P1.X output

#5 Post by paulfjujo » 16 Feb 2018 14:59

Hello,

french proverb:
"On est jamais aussi bien servi que par soi-même ..."

After testing another C compiler : uc51
and getting a good behavior with 3 leds and one UART ...
starting from one example delivered
where #define was used for pin MCU.

so today i replaced all sbit by #define
and it 's WORK FINE !

Code: Select all

// 16-02-2018
// modif sbit par define

//14-02-2018
 // BAD behavior on Hardware ...
 // probleme : Led Rouge sur P1_7 toujours ON ou tojours OFF ?????
 // led Verte OK
 // UART OK
#define MCU "AT89C2051"
#define Version "180216"
#define Directory "D:\\_MikroC PRO for 8051\\_MesProjets\\_Test_1er\\"
#define Project "Test_1er_AT89C2051.mcp51"
#define Source "Test3_AT89C2051_3leds.c"


#define LedV  P3.B7
#define LedR  P1.B7
#define LedY  P3.B5
#define SQA   P3.B4

/*
sbit LedV at  P3.B7;
sbit LedR at  P1.B7;
sbit LedY at  P3.B5;
sbit SQA  at  P3.B4;
*/
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);
 SQA=1;
  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);
}


Post Reply

Return to “mikroC PRO for 8051 General”