c8051f310 uart
时间:10-02
整理:3721RD
点击:
#include <C8051F310.h>
void Oscillator_Init(); //ê±?ó3?ê??ˉ
void Port_Init(); //???ú3?ê??ˉ
void UART0_Init (void);
void Send_Char(unsigned char ch);
void main(void)
{
unsigned char c; // 1??×?·?
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable)
Oscillator_Init(); //ê±?ó3?ê??ˉ
Port_Init(); //???ú3?ê??ˉ
UART_Init(); //′??ú3?ê??ˉ
while(1)
{
Send_Char(c);//′??ú′??í1??×?·?
}
}
void Oscillator_Init() //ê±?ó3?ê??ˉ
{
OSCICN = 0x83;//?ú2???μ′?÷ê1?ü£??μí3ê±?ó2?·??μ£?×????μ?ê24.5M
RSTSRC = 0x04;//ê1?üê±?ó?aê§?ì2a?÷
}
void Port_Init() //???ú3?ê??ˉ
{
XBR0 = 0x01; // UART0 TX and RX pins enabled
XBR1 = 0xC0; //è?é?à-ê1?ü£???2??a1?ê1?ü
P0MDOUT |= 0x10; // Enable TX0 as a push-pull output P0.4
}
void UART0_Init (void)
{
SCON0 |= 0x10; //?óê??êDí
CKCON = 0x08; //?¨ê±?÷1ê1ó??μí3ê±?ó
TMOD = 0x20; //T11¤×÷·?ê?8??×??ˉ??×°??
TH1 = 0x96; //2¨ì??ê?a115200
TL1 = TH1;
TR1 = 1;
}
//·¢?íμ¥??×?·?
void Send_Char(unsigned char ch)
{
SBUF0 = ch; //?íè??o3???
while(TI0 == 0); //μè′y·¢?ííê?
TI0 = 0; //èí?t??á?
}
void Oscillator_Init(); //ê±?ó3?ê??ˉ
void Port_Init(); //???ú3?ê??ˉ
void UART0_Init (void);
void Send_Char(unsigned char ch);
void main(void)
{
unsigned char c; // 1??×?·?
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable)
Oscillator_Init(); //ê±?ó3?ê??ˉ
Port_Init(); //???ú3?ê??ˉ
UART_Init(); //′??ú3?ê??ˉ
while(1)
{
Send_Char(c);//′??ú′??í1??×?·?
}
}
void Oscillator_Init() //ê±?ó3?ê??ˉ
{
OSCICN = 0x83;//?ú2???μ′?÷ê1?ü£??μí3ê±?ó2?·??μ£?×????μ?ê24.5M
RSTSRC = 0x04;//ê1?üê±?ó?aê§?ì2a?÷
}
void Port_Init() //???ú3?ê??ˉ
{
XBR0 = 0x01; // UART0 TX and RX pins enabled
XBR1 = 0xC0; //è?é?à-ê1?ü£???2??a1?ê1?ü
P0MDOUT |= 0x10; // Enable TX0 as a push-pull output P0.4
}
void UART0_Init (void)
{
SCON0 |= 0x10; //?óê??êDí
CKCON = 0x08; //?¨ê±?÷1ê1ó??μí3ê±?ó
TMOD = 0x20; //T11¤×÷·?ê?8??×??ˉ??×°??
TH1 = 0x96; //2¨ì??ê?a115200
TL1 = TH1;
TR1 = 1;
}
//·¢?íμ¥??×?·?
void Send_Char(unsigned char ch)
{
SBUF0 = ch; //?íè??o3???
while(TI0 == 0); //μè′y·¢?ííê?
TI0 = 0; //èí?t??á?
}