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
*/
hardware:sur terminal:
01zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA