Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 19, 2024, 07:42:39 07:42


Login with username, password and session length


Pages: [1]
Print
Author Topic: 8051 UART using other timers other than timer 1  (Read 10188 times)
0 Members and 1 Guest are viewing this topic.
bugmike25
Junior Member
**
Offline Offline

Posts: 84

Thank You
-Given: 15
-Receive: 13


« on: May 04, 2008, 05:58:32 17:58 »

Hi does anyone have an example in C code how to set up a UART on an 8051 without using timer 1 but with another timer, example timer 2?
Logged
tienngoc
Junior Member
**
Offline Offline

Posts: 45

Thank You
-Given: 13
-Receive: 45


« Reply #1 on: May 05, 2008, 05:31:20 17:31 »

Hi does anyone have an example in C code how to set up a UART on an 8051 without using timer 1 but with another timer, example timer 2?
You can use my code to init your program in Keil.

  TMOD = 0x21;                
  //Use Timer 2 generate Baud Rate , T2CON  Registers.
  //equation:  Baud Rate=Oscillator Frequency/[32*(65536-RCAP2H,RCAP2L)]
  CP_RL2=0;//Reload
  C_T2 = 0;//Timer
  EXEN2= 0;
  TCLK = 1;
  RCLK = 1;
  EXF2 = 0;
  RCAP2L  =0xFD;//Baud Rate=115.200 ( RCAP2H,RCAP2L=0xFFFD)
  RCAP2H  =0xFF;
  TR2  = 1;//Start timer2.

Have fun.
Logged
JackProgrammer
Guest
« Reply #2 on: June 21, 2008, 02:52:35 02:52 »

This Code For ATMEL AT89C51RE2 Used Internal Baudrate

/* Start of Config AT89C51RE2:UART0,UART1 */
SCON = 0x50;       // UART0 = Mode 1 (N,8,1)                                                                       
SCON1 = 0x50;      // UART1 = Mode 1 (N,8,1)
                                             
/* Select Generate Baudrate By Internal-Baud */
TCLK = 0;      // Disable Timer2 Generate TX Baudrate
RCLK = 0;      // Disable Timer2 Generate RX Baudrate
BDRCON0 |= 0x0C;   // TBCK:RBCK=1:1 = Used Internal Buad Generate UART0 Baudrate
BDRCON1 |= 0x0C;   // TBCK:RBCK=1:1 = Used Internal Buad Generate UART1 Baudrate               
BDRCON0 &= ~0x01;  // SRC0=0 = Select Fosc to Baudrate
BDRCON1 &= ~0x01;  // SRC1=0 = Select Fosc to Baudrate

/* Setup Internal-Baud Generate Baudrate Fast Mode */   
/* Support Baudrate : 4800,9600,19200,...  ,115200 */   
PCON    |= 0x80;  // UART0:SMOD0 = 1 (Enable Double Baudrate)
BDRCON1 |= 0x80;  // UART1:SMOD1 = 1 (Enable Double Baudrate)
BDRCON0 |= 0x02;  // SPD0=1 = Fast Baudrate Generator
BDRCON1 |= 0x02;  // SPD1=1 = Fast Baudrate Generator
BRL0     = 0x88;  // Setup UART0 Baudrate 9600BPS 
BRL1     = 0x88;  // Setup UART1 Baudrate 9600BPS
BDRCON0 |= 0x10;  // BRR0=1 = Start Internal Baud1          
BDRCON1 |= 0x10;  // BRR1=1 = Start Internal Baud1
                           

/* Start Keil-C51 Transmit Function */
TI = 1;         // Set TI to send First char of UART
TI1 = 1;   
/* End of Config AT89C51RE2:UART0,UART1 */

/* Setup UART Interrupt Control */
ES = 0;      // Disable UART0 Interupt
EN1 &= ~0x08;   // Disable UART1 Interupt
                            
/* Print String to UART0 */
printf("Hello World From UART0\n");

Posted on: June 21, 2008, 03:43:07 03:43 - Automerged

This is Used Timer2 Generate For AT89C51ED2,RD2

/*--------------------------------------------
The main C function.  Program execution Here
---------------------------------------------*/
void main (void)
{     
    CKCON = 0x01;  // Initial X2 Mode (58.9824 MHz)
                    
    // Initial Timer2 to Gen Baudrate
    RCAP2H = 0xFF;  // Setup Timer2 Baudrate = 9600 / 58.9824MHz
    RCAP2L = 0x40;               
    RCLK = 1;       // Enable RXD Baudrate
    TCLK = 1;       // Enable TXD Baudrate
    ET2 = 0;        // Disable Timer2 Interrupt
    TR2 = 1;        // Start Timer2 Generate Baudrate
   
    // Initial MCS51 Serial Port                           
    SCON  =  0x50;  // Serial Port Mode 1 (N,8,1)
    ES    =  0;     // Disable Serial Interupt   
    PCON &=  0x7F;  // SMOD1 = 0 (Disable Double Baudrate)                                         
    TI    =  1;     // Set TI to send First Char of UART

    /* Print Message to RS232 */
    printf ("Hello World\n"); 

    while (1);        // Loop Continue       
}


Posted on: June 21, 2008, 03:46:24 03:46 - Automerged

This Code Used Internal Baudrate Generater For AT89C51ED2

/*--------------------------------------------
 The main C function.  Program execution Here
---------------------------------------------*/
void main (void)
{       
    /* Start of Config AT89C51ED2 Start-Up */
    CKCON0 = 0x01;    // Select Clock = X2 Mode (6-Cycle)
   
    /* Start of Config AT89C51ED2:UART */
    SCON = 0x50;      // UART = Mode 1 (N,8,1)
    ES = 0;           // Disable UART Interupt
                   
    /* Select Generate Baudrate By Internal Baud */
    TCLK = 0;         // Disable Timer2 Generate TX Baudrate
    RCLK = 0;         // Disable Timer2 Generate RX Baudrate
    BDRCON |= 0x0C;   // TBCK:RBCK=1:1 = Used Internal Buad Generate
                   
    /* Setup Internal Baudrate Fast Mode */
    /* Support Baudrate : 9600,..,115200 */
    PCON |= 0x80;     // UART:SMOD = 1 (Enable Double Baudrate)
    BRL   = 0x40;     // Setup UART Baudrate = 9600 (Fast Baud)
    BDRCON |= 0x02;   // SPD=1 = Fast Baudrate Generator
    BDRCON &= 0xFE;   // SRC=0 = Select Fosc to Baudrate
    BDRCON |= 0x10;   // BRR0=1 = Start Internal Baudrate
                       
    TI    =  1;       // Set TI to send First char of UART
    /* End of Config AT89C51ED2:UART */
                        
    /* Print String to UART */
    printf("Hello World\n\0");   
    while(1);   
}
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC