#include<c8051f120.h>
#define uchar unsigned char
#define systemclock 24500000
#define baudrate 115200
sbit P0_6=P0^6;
sbit P2_3=P2^3;
uchar code tab[]="0x52,0x20,0x30,0xAA,0x05";
void OSCILLATOR_init()
{
int i;
char SFRPAGE_SAVE=SFRPAGE;
SFRPAGE=CONFIG_PAGE;
OSCICN=0x83;
/*OSCXCN=0x67;
for (i = 0; i < 256; i++);
while (!(OSCXCN & 0x80));*/
SFRPAGE=LEGACY_PAGE;
FLSCL|=0x30;
if(systemclock<=25000000)
{
FLSCL&=~0x30;
}
else if(systemclock<=50000000)
{
FLSCL&=~0x20;
}
else if(systemclock<=75000000)
{
FLSCL&=~0x10;
}
else
{
FLSCL&=~0x00;
}
SFRPAGE = CONFIG_PAGE;
CLKSEL=0x00;
SFRPAGE = SFRPAGE_SAVE;
}
void port_init()
{
char SFRPAGE_SAVE=SFRPAGE;
SFRPAGE=CONFIG_PAGE;
XBR0=0x04;
XBR1=0x80;
XBR2=0x44;
P0MDOUT=0xf5;
P1MDOUT=0xff;
P2MDOUT=0xff;
P3MDOUT=0xff;
SFRPAGE = SFRPAGE_SAVE;
}
void uart1_init()
{
char SFRPAGE_SAVE=SFRPAGE;
SFRPAGE=
tiMER01_PAGE;
TCON=0x00;
TMOD=0x20;
CKCON=0x10;
TL1=256-(systemclock/(2*baudrate));
TH1=256-(systemclock/(2*baudrate));
TR1=1;
SFRPAGE=SFRPAGE_SAVE;
SFRPAGE=UART1_PAGE;
SCON1=0x00;
TI1=0;
SFRPAGE = SFRPAGE_SAVE;
}
void senddata(unsigned char i)
{
char SFRPAGE_SAVE=SFRPAGE;
SFRPAGE = UART1_PAGE;
P0_6=1;
SBUF1=i;
while(TI1==0);
TI1=0;
P0_6=0;
SFRPAGE = SFRPAGE_SAVE;
}
void main()
{
char SFRPAGE_SAVE = SFRPAGE;
int x,t=0;
SFRPAGE = CONFIG_PAGE;
WDTCN=0xde;
WDTCN=0xad;
OSCILLATOR_init();
port_init();
uart1_init();
EA=1;
SFRPAGE = SFRPAGE_SAVE;
for(t=0;t<5;t++)
{
senddata(tab[t]);
for(x=0;x<4;x++);
}
}
收到的数据
-
全部有规律 但是不正确
一周热门 更多>