终于买到STC8的板,可以进行四个串口的实验了,C语言没用过,只只能写个汇编的,有了上次的经验,这次写的很顺利,确定四个串口运作都很正常,但要同时开四个串口助手进行交叉实验实在觉得累,只能这样了。
;THIS FOR STC8 FOUR UART TESTING
;50H FOR UART1 WRITE POINTER
;51H FOR UART2 WRITE POINTER
;52H FOR UART3 WRITE POINTER
;53H FOR UART4 WRITE POINTER
;54H FOR UART1 READ POINTER
;55H FOR UART2 READ POINTER
;56H FOR UART3 READ POINTER
;57H FOR UART4 READ POINTER
;71H DELAY
;72H DELAY
;73H DELAY
;BIT
;40H FOR UART1 BUSY
;41H FOR UART2 BUSY
;42H FOR UART3 BUSY
;43H FOR UART4 BUSY
FIRSTBUFFER EQU 00H
LASTBUFFER EQU 0FFH
INTCLKO EQU 08FH
IE2 EQU 0AFH ;X, ET4, ET3, ES4, ES3, ET2, ESPI, ES2
S2CON EQU 9AH ;S2SM0, S2SM1, S2SM2, S2REN, S2TB8, S2RB8, S2TI, S2RI
S3CON EQU 0ACH ;SAME AS S2CON
S4CON EQU 84H
S2BUF EQU 9BH
S3BUF EQU 0ADH
S4BUF EQU 85H
T2H EQU 0D6H
T2L EQU 0D7H
P4 EQU 0C0H
P5 EQU 0C8H
P6 EQU 0E8H
P7 EQU 0F8H
AUXR EQU 8EH
AUXR2 EQU 08FH
AUXR1 EQU 0A2H
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP EXT_INT0 ;EXTERNAL INTERRUPT0
ORG 000BH
LJMP TIMER_0 ;TIMER0 INTERRUPT
ORG 0013H
LJMP EXT_INT1 ;EXTERNAL INTERRUPT1
ORG 001BH
LJMP TIMER_1 ;TIMER1 INTERRUPT
ORG 0023H
LJMP UART1
ORG 002BH
LJMP ADC
ORG 0033H
LJMP LVD
ORG 003BH
LJMP PCA
ORG 0043H
LJMP UART2
ORG 004BH
LJMP SPI
ORG 0053H
LJMP INT2
ORG 005BH
LJMP INT3
ORG 0063H
LJMP TIMER_2
ORG 0083H
LJMP INT4
ORG 008BH
LJMP UART3
ORG 0093H
LJMP UART4
ORG 009BH
LJMP TIMER_3
ORG 00A3H
LJMP TIMER_4
ORG 00ABH
LJMP CMP
MAIN:
MOV INTCLKO,#00000100B ;ENABLE T2(=4),T1(=2) T0(=1) HAVE CLOCK OUTPUT T2@P1.3 T1@P3.5 T0@P3.4
MOV TMOD, #00000000B ;TIMER_1 AS MOD0 (16BIT AUTO LOAD) ;TIMER_0 AS MOD0 MOD1=16BIT NOT AUTO LOAD
;GATE, C/T,M1,M0(T1) GATE, C/T,M1,MO(T0)
MOV AUXR,#00010101B ;T0x12,T1x12,UART_M0x6,T2RUN,T2C/T,T2x12,EXTRAM,S1ST2(UART1,0=T1 1=T2) ALL USE T2
MOV T2H, #0FFH ;18.432 38400 12T=FFF6 1T=FF88 T2 RUN AS 16BIT AUTO LOAD
MOV T2L, #88H
SETB ES ;ENABLE UART1 INTERRUPT
MOV IE2, #00011001B ;ENABLE UART4, UART3, UART2 INTERRUPT
LCALL INIT4UART ;ALL USE TIMER2 AS BAUD RATE GENERATER
SETB EA ;ENABLE ALL INTERRUPT
LOOP:
CPL P1.7
;LCALL DELAY3
LCALL READ1
LCALL READ2
LCALL READ3
LCALL READ4
JMP LOOP
READ4:
MOV A, 53H
CJNE A, 58H, READ4A
JMP READ4EXIT
READ4A:
MOV DPH, #4
MOV DPL, 58H
MOVX A, @DPTR
INC 58H
MOV DPH, #0
LCALL SENTONEBYTE4
READ4EXIT:
RET
READ3:
MOV A, 52H
CJNE A, 57H, READ3A
JMP READ3EXIT
READ3A:
MOV DPH, #3
MOV DPL, 57H
MOVX A, @DPTR
INC 57H
MOV DPH, #0
LCALL SENTONEBYTE3
READ3EXIT:
RET
READ2:
MOV A, 51H
CJNE A, 56H, READ2A
JMP READ2EXIT
READ2A:
MOV DPH, #2
MOV DPL, 56H
MOVX A, @DPTR
INC 56H
MOV DPH, #0
LCALL SENTONEBYTE2
READ2EXIT:
RET
READ1:
MOV A, 50H
CJNE A, 55H, READ1A
JMP READ1EXIT
READ1A:
MOV DPH, #1
MOV DPL, 55H
MOVX A, @DPTR
INC 55H
MOV DPH, #0
LCALL SENTONEBYTE1
READ1EXIT:
RET
SENTONEBYTE1: ;SENT OUT A
CHECKBUSY1:
JB 40H, CHECKBUSY1
SETB 40H
MOV SBUF, A
RET
SENTONEBYTE2: ;SENT OUT DATA IN A
CHECKBUSY2:
JB 41H, CHECKBUSY2
SETB 41H
MOV S2BUF, A
RET
SENTONEBYTE3: ;SENT OUT DATA IN A
CHECKBUSY3:
JB 42H, CHECKBUSY3
SETB 42H
MOV S3BUF, A
RET
SENTONEBYTE4: ;SENT OUT DATA IN A
CHECKBUSY4:
JB 43H, CHECKBUSY4
SETB 43H
MOV S4BUF, A
RET
UART1:
;/*----------------------------
;UART1 INTERRUPT SERVICE ROUTINE
;----------------------------*/
PUSH ACC
PUSH PSW
JNB RI, UART1CHECKTI
CLR RI
MOV A, SBUF ;READ THE CHARACTER FROM THE SERIAL PORT
MOV DPH, #1
MOV DPL, 50H
MOVX @DPTR, A
INC 50H ;POINT TO NEXT BUFFER
MOV DPH, #0
JMP UART1EXIT
UART1CHECKTI:
CLR TI
CLR 40H ;NOT BUSY
UART1EXIT:
POP PSW
POP ACC
RETI
UART2:
;/*----------------------------
;UART2 INTERRUPT SERVICE ROUTINE
;----------------------------*/
PUSH ACC
PUSH PSW
MOV A, S2CON ;READ UART2 CONTROL REGISTER
ANL A, #00000001B ;ANL, IF S2RI=0 THEN 0
JZ UART2CHECKTI
MOV A, S2BUF
MOV DPH, #2
MOV DPL, 51H
MOVX @DPTR, A
ANL S2CON, #11111110B ;CLEAR S2RI BIT
INC 51H ;POINT TO NEXT BUFFER
MOV DPH, #0
JMP UART2EXIT
UART2CHECKTI:
ANL S2CON, #11111101B ;CLEAR S2TI BIT
CLR 41H
UART2EXIT:
POP PSW
POP ACC
RETI
UART3:
;/*----------------------------
;UART3 INTERRUPT SERVICE ROUTINE
;----------------------------*/
PUSH ACC
PUSH PSW
MOV A, S3CON ;READ UART3 CONTROL REGISTER
ANL A, #00000001B ;ANL, IF S3RI=0 THEN 0
JZ UART3CHECKTI
MOV A, S3BUF
MOV DPH, #3
MOV DPL, 52H
MOVX @DPTR, A
ANL S3CON, #11111110B ;CLEAR S3RI BIT
INC 52H ;POINT TO NEXT BUFFER
MOV DPH, #0
JMP UART3EXIT
UART3CHECKTI:
ANL S3CON, #11111101B ;CLEAR S3TI BIT
CLR 42H
UART3EXIT:
POP PSW
POP ACC
RETI
UART4:
;/*----------------------------
;UART4 INTERRUPT SERVICE ROUTINE
;----------------------------*/
PUSH ACC
PUSH PSW
MOV A, S4CON ;READ UART4 CONTROL REGISTER
ANL A, #00000001B ;ANL, IF S4RI=0 THEN 0
JZ UART4CHECKTI
MOV A, S4BUF
MOV DPH, #4
MOV DPL, 53H
MOVX @DPTR, A
ANL S4CON, #11111110B ;CLEAR S4RI BIT
INC 53H ;POINT TO NEXT BUFFER
MOV DPH, #0
JMP UART4EXIT
UART4CHECKTI:
ANL S4CON, #11111101B ;CLEAR S4TI BIT
CLR 43H
UART4EXIT:
POP PSW
POP ACC
RETI
DELAY3:
MOV 72H, #255
SLOWDOWN0:
MOV 71H, #125 ;255
SLOWDOWN:
MOV 73H, #11 ;11=18M
SLOWDOWN2:
DJNZ 73H, SLOWDOWN2
DJNZ 71H, SLOWDOWN
DJNZ 72H, SLOWDOWN0
RET
INIT4UART:
MOV SCON, #01010000B ;x,MOD1(NOT SAME AS UART1),x,RECEIVE ENABLE
MOV S2CON, #01010000B ;MOD0,x,x,RECEIVE ENABLE
MOV S3CON, #00010000B ;MOD0,0=USE T2,x,RECEIVE ENABLE
MOV S4CON, #00010000B ;MOD0,0=USE T2,x,RECEIVE ENABLE
RET
EXT_INT0:
RETI
TIMER_0:
RETI
EXT_INT1:
RETI
TIMER_1:
RETI
;UART1:
;RETI
ADC:
RETI
LVD:
RETI
PCA:
RETI
;UART2:
;RETI
SPI:
RETI
INT2:
RETI
INT3:
RETI
TIMER_2:
RETI
INT4:
RETI
;UART3:
;RETI
;UART4:
;RETI
TIMER_3:
RETI
TIMER_4:
RETI
CMP:
RETI
END
|