Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] Software UART on AT89C51 Using Embedded C

Status
Not open for further replies.

adyrn001

Newbie level 2
Joined
Jul 2, 2018
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
Please Help me by providing some kind of code to make Software UART on 8051
18.432MHZ crystal is there.... The baud Rate Required is 2400 and please provide code in C only....!
 

hello,

you can test with MikroC for 8051 ... available if code size <=2Kb

Code:
#define Version "180702"
#define Directory  " "
#define Project   " "
#define Source     " "
#define MCU  "AT89C2051"
#define FOSC  "18.432MHz"
#define POWER_Supply "5V"
#define XTAL 18432000
#define BAUDRATE
#define BitTimer (((XTAL/BAUDRATE)/12) - 5) / 2

#define Byte unsigned char
#define Word unsigned int

#define TRUE 1
#define FALSE 0
#define CR 13
#define LF 10

#define LED_Error P1.B4


#define ON 0
#define OFF 1

const char TH1_INIT = 0xB1; // Initial 20mS   at 12MHZ
const char TL1_INIT = 0xE0;

sbit Soft_Uart_RX at P3_0_bit;
sbit Soft_Uart_TX at P3_1_bit;

char TEXTE[64];
Word i,j,k;
volatile unsigned char Count1;
Byte char c1;
Byte Erreur=0;
Byte Dummy;




void main( void)
{
  j=0;
  P3=0xFF;
  P1=0xFF;
  Delay_ms(2000);

  Erreur= Soft_UART_Init(2400,1);
  while (Erreur>0)
  {
   LED_Error=!LED_Error;
   Delay_ms(1000);
  }

   Soft_UART_Write('A');
   Soft_UART_Write('B');
   Soft_UART_Write('C');
   Soft_UART_Write('D');
   Soft_UART_Write(CR);
   Soft_UART_Write(LF);
  
  Delay_ms(1000);
  
  while(1) 
  {
    c1 = Soft_UART_Read(&Erreur);
    if (Erreur)
      LED_Error=1;
    else
      Soft_UART_Write(c1);
    }
  }

compile OK for AT89C2051 18.432 MHz
use Software UART MikroC lib
but not tested in real world...
 

hello,

you can test with MikroC for 8051 ... available if code size <=2Kb

Code:
#define Version "180702"
#define Directory  " "
#define Project   " "
#define Source     " "
#define MCU  "AT89C2051"
#define FOSC  "18.432MHz"
#define POWER_Supply "5V"
#define XTAL 18432000
#define BAUDRATE
#define BitTimer (((XTAL/BAUDRATE)/12) - 5) / 2

#define Byte unsigned char
#define Word unsigned int

#define TRUE 1
#define FALSE 0
#define CR 13
#define LF 10

#define LED_Error P1.B4


#define ON 0
#define OFF 1

const char TH1_INIT = 0xB1; // Initial 20mS   at 12MHZ
const char TL1_INIT = 0xE0;

sbit Soft_Uart_RX at P3_0_bit;
sbit Soft_Uart_TX at P3_1_bit;

char TEXTE[64];
Word i,j,k;
volatile unsigned char Count1;
Byte char c1;
Byte Erreur=0;
Byte Dummy;




void main( void)
{
  j=0;
  P3=0xFF;
  P1=0xFF;
  Delay_ms(2000);

  Erreur= Soft_UART_Init(2400,1);
  while (Erreur>0)
  {
   LED_Error=!LED_Error;
   Delay_ms(1000);
  }

   Soft_UART_Write('A');
   Soft_UART_Write('B');
   Soft_UART_Write('C');
   Soft_UART_Write('D');
   Soft_UART_Write(CR);
   Soft_UART_Write(LF);
  
  Delay_ms(1000);
  
  while(1) 
  {
    c1 = Soft_UART_Read(&Erreur);
    if (Erreur)
      LED_Error=1;
    else
      Soft_UART_Write(c1);
    }
  }

compile OK for AT89C2051 18.432 MHz
use Software UART MikroC lib
but not tested in real world...



I have strict instruction to use Keil! I Have AT89V51RD2 or AT89C51!
Please suggest something good or provide code... any library i can explore...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top