大家帮我看看这个程序哪儿有问题,谢谢了
#include<c8051f020.h>
unsigned char flag,a;
void main()
{
TMOD=0x20;//设置定时器1为工作方式2
TH1=0xfa;//晶振22.1184MHz,波特率9600
TL1=0xfa;
TR1=1;
SCON0=0x50;//串口工作方式1
EA=1;
ES0=1;
while(1)
{
if(flag==1)
{
ES0=0;
flag=0;
SBUF0=a;
while(!TI0);
TI0=0;
ES0=1;
}
}
}
void ser() interrupt 4
{
RI0=0;
a=SBUF0;
flag=1;
}
在串口调试助手里面发送一个数据之后接收区没有反应,不知道是什么问题。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
楼主还是多看看C8051的资料吧,和普通的8051不是一样的
-----------------------------------------------------------------------
谢谢哦,看来得慢慢看了。。。
2、未选择外部时钟22.1184MHz;
3、未禁止看门狗;
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F020.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Timer_Init()
{
CKCON = 0x10;
TCON = 0x40;
TMOD = 0x20;
TH1 = 0xB8;
}
void UART_Init()
{
SCON0 = 0x50;
}
void Port_IO_Init()
{
// P0.0 - TX0 (UART0), Open-Drain, Digital
// P0.1 - RX0 (UART0), Open-Drain, Digital
// P0.2 - Unassigned, Open-Drain, Digital
// P0.3 - Unassigned, Open-Drain, Digital
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Open-Drain, Digital
// P3.5 - Unassigned, Open-Drain, Digital
// P3.6 - Unassigned, Open-Drain, Digital
// P3.7 - Unassigned, Open-Drain, Digital
XBR0 = 0x04;
XBR2 = 0x40;
}
void Oscillator_Init()
{
OSCICN = 0x0C;
}
void Interrupts_Init()
{
IE = 0x90;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
Timer_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}
一周热门 更多>