搞了几天了,还没解决,头大啊!
我用的单片机型号: STC8G1K08-20/16PIN (QFN20)
固件版本号: 7.3.10U
板子用USB下载程序没问题, 用串口下载提示找不到目标单片机;
USB下载跑起来后IO可以输出高低电平,但串口乱码,试了串口1 RXD/P3.0, TXD/P3.1和RXD/P3.6, TXD/P3.7都一样。
其他坛友有遇到这种问题吗,请教解决方法? 是不是IC有bug。。。。
贴上官方代码:
#include "reg51.h"
#include "intrins.h"
#define FOSC 11059200UL
#define BRT (65536 - FOSC / 9600 / 4)
sfr AUXR = 0x8e;
sfr T2H = 0xd6;
sfr T2L = 0xd7;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
sfr P5 = 0xc8;
sfr P_SW1 = 0xa2;
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartIsr() interrupt 4
{
if (TI)
{
TI = 0;
busy = 0;
}
if (RI)
{
RI = 0;
buffer[wptr++] = SBUF;
wptr &= 0x0f;
}
}
void UartInit()
{
SCON = 0x50;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x15;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void UartSend(char dat)
{
while (busy);
busy = 1;
SBUF = dat;
}
void UartSendStr(char *p)
{
while (*p)
{
UartSend(*p++);
}
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0xFE; //TX ?????,RX?????
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
//P_SW1 =0x0;
P_SW1 &=0x3F;
P_SW1 |=0x40;
UartInit();
ES = 1;
EA = 1;
UartSendStr("uart Test!\r\n" );
while (1)
{
if (rptr != wptr)
{
UartSend(buffer[rptr++]);
rptr &= 0x0f;
}
}
}