MCU User Forum
  How to enable and Intialize UART 1 port on C8051F120

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   How to enable and Intialize UART 1 port on C8051F120
trc4000
Member
posted August 26, 2010 08:41 PM     Click Here to See the Profile for trc4000     Edit/Delete Message
I can easily get UART 0 working, not able to get UART 1 working on the C8051F120 development board.

I would like to use the Rx pin on UART 1, which will be P1^1 (Port1, bit 1).

Here is my Port Init code, which i am unsure about and UART1_Init code.


//------------------------------------------------------------------------------------
// PORT_Init
//------------------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports
//
void PORT_Init (void)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page

SFRPAGE = CONFIG_PAGE; // Set SFR page

//XBR0 = 0x04; // Enable UART0
// XBR1 = 0x00;
//XBR0 = 0x37; // UART1 on P1.0 and P1.1
//XBR2 |= 0xC4; // UART1 on P1.0 and P1.1; crossbar started
// XBR2 = 0x40; // Enable crossbar and weak pull-up

XBR0 = 0x00;
XBR1 = 0x00;
XBR2 = 0x44; // Enable crossbar and weak pull-up
// Enable UART1

P0MDOUT |= 0x01;
// P1MDOUT |= 0x01; // Set TX pin to push-pull
P1MDOUT |= 0x40; // Set P1.6(LED) to push-pull
//P1MDIN = 0x01;
SFRPAGE = SFRPAGE_SAVE; // Restore SFR page
}


void UART1_Init (void)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page

SFRPAGE = UART1_PAGE;
SCON1 = 0x10; // SCON1: mode 0, 8-bit UART, enable RX

SFRPAGE = TIMER01_PAGE;
TMOD &= ~0xF0;
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload


if (SYSCLK/BAUDRATE/2/256 < 1) {
TH1 = -(SYSCLK/BAUDRATE/2);
CKCON |= 0x10; // T1M = 1; SCA1:0 = xx
} else if (SYSCLK/BAUDRATE/2/256 < 4) {
TH1 = -(SYSCLK/BAUDRATE/2/4);
CKCON &= ~0x13; // Clear all T1 related bits
CKCON |= 0x01; // T1M = 0; SCA1:0 = 01
} else if (SYSCLK/BAUDRATE/2/256 < 12) {
TH1 = -(SYSCLK/BAUDRATE/2/12);
CKCON &= ~0x13; // T1M = 0; SCA1:0 = 00
} else {
TH1 = -(SYSCLK/BAUDRATE/2/48);
CKCON &= ~0x13; // Clear all T1 related bits
CKCON |= 0x02; // T1M = 0; SCA1:0 = 10
}

TL1 = TH1; // Initialize Timer1
TR1 = 1; // Start Timer1

SFRPAGE = UART1_PAGE;
TI1 = 1; // Indicate TX1 ready

SFRPAGE = SFRPAGE_SAVE; // Restore SFR page

}

Thankyou in Advance!!

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b