P89LPC952的亮點之一是有2個串口。最近我在試驗第一個串口UART0很順利地通過了。但在試驗第二個串口UART1時間很不順利。網(wǎng)上搜索發(fā)現(xiàn)也有人無法使UART1正常工作。經(jīng)過對952進行模擬調(diào)試,發(fā)現(xiàn)NXP公司的數(shù)據(jù)手冊中UART1的控制寄存器S1CON的地址和PCONA地址相同都是0B5H,而S1CON的正確地址是0B6H,改正之后UART1即可正常工作。另外要注意S1CON的各位不能位尋址,這和S0CON不同。下面是通過UART1發(fā)送一組數(shù)據(jù)的小程序,下載到952能夠正確運行。
$NOMOD51
$INCLUDE(REG952.INC)
RCOUNTEQU40H
ADDREQU41H
T_BUFFEQU70H
RCV_FLAGBIT01H
LEDCONBITP1.6
ORG0000H
AJMPMAIN
ORG0023H
;LJMPSVC_SCI;接收中斷入口
ORG0100H
;*****************************************************
MAIN:MOVR7,#20H
DJNZR7,$
MOVP1M1,#00H
MOVP1M2,#40H
MOVDPTR,#P4M1
MOVA,#00H
MOVX@DPTR,A
MOVDPTR,#P4M2
MOVA,#00H
MOVX@DPTR,A;設(shè)置P4.2(TXD1),P4.3(RXD1)為準雙向口
MOVP4,#0FFH
CLRLEDCON
LCALLD1S
SETBLEDCON
MOVS1CON,#50H;設(shè)置串口為工作方式1,允許串口接收MOVDPTR,#BRGCON_1;設(shè)置串口波特率:Fosc/((BRGR1,BRGR0)+16)
MOVA,#00H
MOVX@DPTR,A;關(guān)波特率發(fā)生器
MOVDPTR,#BRG1_1
MOVA,#02H
MOVX@DPTR,A;內(nèi)部RC振蕩器,波特率9600
MOVDPTR,#BRG0_1
MOVA,#0E0H
MOVX@DPTR,A
MOVDPTR,#BRGCON_1
MOVA,#03H
MOVX@DPTR,A;打開串口波特率發(fā)生器,使用串口波特率發(fā)生器
MOVIEN2,#00H;禁止UART1接收中斷
MOVADDR,#60H
MOVRCOUNT,#0DH
LCALLTRANSA
SJMP$
TRANSA:
MOVT_BUFF,#01H
MOVT_BUFF+1,#04H
MOVT_BUFF+2,#00H
MOVT_BUFF+3,#00H
MOVT_BUFF+4,#00H
MOVT_BUFF+5,#00H
MOVT_BUFF+6,#0F0H
MOVT_BUFF+7,#0AH;發(fā)送數(shù)據(jù)子程序010400000000F00A
MOVR3,#08H
MOVR0,#T_BUFF
TRANSA1:MOVA,@R0
MOVDPTR,#S1BUF
MOVX@DPTR,A
WAITHA:MOVA,S1CON
JNBACC.1,WAITHA;取TI_1位,判斷是否為1
ANLS1CON,#0FDH;TI_1=1,則該位清零(S1CON不能位尋址)
INCR0
DJNZR3,TRANSA1
MOVRCOUNT,#0DH
MOVADDR,#60H
MOVS1CON,#50H
MOVIEN2,#04H;開放UART1接收中斷
SETBEA;開放總中斷,等待接收測量數(shù)據(jù)
RET