51單片機(jī)串行口速率設(shè)置
/*
51單片機(jī)速率設(shè)置公式
波特率=SYSclk/(32*12*(256-TH1)
*/
#ifndef MONITOR51SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */TR1 = 1; /* TR1: timer 1 run */TI = 1; /* TI: set TI to send first char of UART */#endif
評(píng)論