我想編寫一個程序從dipswitch讀取一個號碼並使用rs232協議(串口)傳輸該號碼。這個程序是用匯編語言編寫的。我使用PORTB作爲輸入端口,並將其連接到撥動開關以獲取應該傳輸的號碼。我在proteus中模擬了這個協議,但它沒有顯示任何結果。怎麼了?使用串口傳輸號碼
Proteus仿真 -
這裏是代碼:
#include<p18f2550.inc>
; CONFIG1H
config FOSC =HS ; Oscillator Selection bits (HS oscillator (HS))
; CONFIG2H
config WDT = OFF ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
config WDTPS = 32768 ; Watchdog Timer Postscale Select bits (1:32768)
ORG 0X00
GOTO MAIN
MAIN:
MOVLW B'00100000' ;enable transmit and choose low baud
MOVWF TXSTA ;write to reg
MOVLW D'15' ;9600 bps
MOVWF SPBRG ;write to reg
BCF TRISC, TX ;make tx pin and output pin
BSF RCSTA, SPEN ;enable the serial port
SETF TRISB ;portb defined as input
OVER:
MOVFF PORTB,W ;move portb to wreg
CALL TRANS
TRANS:
S1
BTFSS PIR1, TXIF ;wait until last bit is gone
BRA S1 ;stay in loop
MOVWF TXREG ;load th value to e transmitted
CALL OVER
END
使用如此多的'CALL'會導致堆棧溢出。 – MikeCAT