我有ATMEL的两个串口例程,要转到STC的实验板上晶振18.432 而例程是11.0592,,波特率改成9600,我对寄存器不太熟悉
那位兄弟能改一下,函数的功能是串口把接收到的字符再发回去
DEMO1:
include "reg_c51.h"
char uart_data;
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=0xFD; /* 9600 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ BDRCON |=0x10; /* Baud rate generator run*/
while(1); /* endless */ }
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*/ }
//////////////////////////////////////////////////////////////////////
DEMO2:
#include "reg_c51.h"
char uart_data;
/void main (void) { SCON = 0x50; /*uart in mode 1 (8 bit), REN=1 */ T2CON &= 0xF0; /* EXEN2=0; TR2=0;C/T2#=0;CP/RL2#=0;*/ T2CON |= 0x30; /* RCLK = 1; TCLK=1; */ TH2=0xFF; /* init value */ TL2=0xFD; /* init value */ RCAP2H=0xFF; /* reload value, 115200 Bds at11.059MHz */ RCAP2L=0xFD; /* reload value, 115200 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ TR2 = 1; /* Timer 2 run */
while(1); /* endless */ }
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*/ }
|