2015-12-25 34 views
0

我想編寫一個程序從dipswitch讀取一個號碼並使用rs232協議(串口)傳輸該號碼。這個程序是用匯編語言編寫的。我使用PORTB作爲輸入端口,並將其連接到撥動開關以獲取應該傳輸的號碼。我在proteus中模擬了這個協議,但它沒有顯示任何結果。怎麼了?使用串口傳輸號碼

Proteus仿真 -

Screenshot

這裏是代碼:

#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 
+0

使用如此多的'CALL'會導致堆棧溢出。 – MikeCAT

回答

0

使用CALL太多次不RETURN會導致堆棧溢出,這將導致設備復位爲消息提示除非STVRENCONFIG4L寄存器設置爲0.

未經測試,請嘗試使用GOTO而不是CALL s。

#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 
GOTO TRANS ; **change "CALL" to "GOTO" here** 


TRANS: 
S1 
BTFSS PIR1, TXIF ;wait until last bit is gone 
BRA S1 ;stay in loop 
MOVWF TXREG ;load th value to e transmitted 
GOTO OVER ; **change "CALL" to "GOTO" here** 

END 
+0

現在沒有警告,但窗口中沒有顯示任何結果。其空的 – nazila

+0

IDK PIC asm,但是你不能從'OVER'結尾刪除GOTO,並且只是進入'TRANS'?我假設'GOTO'是一個無條件跳轉。 –

+0

「PORTB」的輸入是什麼?該程序將以字符形式發送輸入,而不是十進制數字。例如,如果您發送'NUL'(0),它不會出現在終端上。 – MikeCAT