STC说516兼容AT89C51RD2,我从ATMEL的官方网上下了个程序测试毫无反应
晶振设置稍有不同测试代码用的是11.0592,我的板子是18.432
问题在STC的单片机里有没有BDRCON这个寄存器,波特率不对也应该有乱玛呀
#include "reg_c51.h"
char uart_data;
/** * FUNCTION_PURPOSE: This file set up uart in mode 1 (8 bits uart) with * internal baud rate generator. * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: void */ void main (void) { SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */ BDRCON &=0xEC; /* BRR=0; SRC=0; */ BDRCON |=0x0C; /* TBCK=1;RBCK=1; SPD=0 */ BRL=0xF6; /* 9600 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ BDRCON |=0x10; /* Baud rate generator run*/
while(1); /* endless */ }
/** * FUNCTION_PURPOSE: serial interrupt, echo received data. * FUNCTION_INPUTS: P3.0(RXD) serial input * FUNCTION_OUTPUTS: P3.1(TXD) serial output */ void serial_IT(void) interrupt 4 {
if (RI == 1) { /* if reception occur */ RI = 0; /* clear reception flag for next reception */ uart_data = SBUF; /* Read receive data */ SBUF = uart_data; /* Send back same data on uart*/ } else TI = 0; /* if emission occur */ /* clear emission flag for next emission*/ }
|