本帖最后由 放晴的那天 于 2018-5-13 20:09 編輯
我用的是STC大學計劃實驗箱4的開發板(IAP15W4K58S4),開發板上的接口是USB接口,硬件已經調試好了,下載范例程序運行也有用。但是我準備自己寫一個最簡單的程序的時候,我按照視頻例程打出的代碼卻無法運行,代碼如下:
ORG 10
START: SETB P1.6
LCALL DELAY
CLR P1.6
LCALL DELAY
AJMP START
DELAY: MOV R7 , #250
D1:MOV R6 , #250
D2:DJNZ R6,D2
DJNZ R7,D1
RET
END
可以運行的范例程序代碼如下:
;************* 功能說明 **************
;程序使用P4.7 P4.6 P1.6 P1.7 來演示跑馬燈,輸出低驅動。
;******************************************
Fosc_KHZ EQU 22118 ;22118KHZ
STACK_POIRTER EQU 0D0H ;堆棧開始地質
;*******************************************************************
;*******************************************************************
P4 DATA 0C0H
P0M1 DATA 0x93 ; P0M1.n,P0M0.n =00--->Standard, 01--->push-pull
P0M0 DATA 0x94 ; =10--->pure input, 11--->open drain
P1M1 DATA 0x91 ; P1M1.n,P1M0.n =00--->Standard, 01--->push-pull
P1M0 DATA 0x92 ; =10--->pure input, 11--->open drain
P2M1 DATA 0x95 ; P2M1.n,P2M0.n =00--->Standard, 01--->push-pull
P2M0 DATA 0x96 ; =10--->pure input, 11--->open drain
P3M1 DATA 0xB1 ; P3M1.n,P3M0.n =00--->Standard, 01--->push-pull
P3M0 DATA 0xB2 ; =10--->pure input, 11--->open drain
P4M1 DATA 0xB3 ; P4M1.n,P4M0.n =00--->Standard, 01--->push-pull
P4M0 DATA 0xB4 ; =10--->pure input, 11--->open drain
P5M1 DATA 0xC9 ; P5M1.n,P5M0.n =00--->Standard, 01--->push-pull
P5M0 DATA 0xCA ; =10--->pure input, 11--->open drain
P6M1 DATA 0xCB ; P6M1.n,P6M0.n =00--->Standard, 01--->push-pull
P6M0 DATA 0xCC ; =10--->pure input, 11--->open drain
P7M1 DATA 0xE1 ;
P7M0 DATA 0xE2 ;
;*******************************************************************
;*******************************************************************
ORG 0000H ;reset
LJMP F_Main
ORG 0003H ;0 INT0 interrupt
RETI
LJMP F_INT0_Interrupt
ORG 000BH ;1 Timer0 interrupt
LJMP F_Timer0_Interrupt
ORG 0013H ;2 INT1 interrupt
LJMP F_INT1_Interrupt
ORG 001BH ;3 Timer1 interrupt
LJMP F_Timer1_Interrupt
ORG 0023H ;4 UART1 interrupt
LJMP F_UART1_Interrupt
ORG 002BH ;5 ADC and SPI interrupt
LJMP F_ADC_Interrupt
ORG 0033H ;6 Low Voltage Detect interrupt
LJMP F_LVD_Interrupt
ORG 003BH ;7 PCA interrupt
LJMP F_PCA_Interrupt
ORG 0043H ;8 UART2 interrupt
LJMP F_UART2_Interrupt
ORG 004BH ;9 SPI interrupt
LJMP F_SPI_Interrupt
ORG 0053H ;10 INT2 interrupt
LJMP F_INT2_Interrupt
ORG 005BH ;11 INT3 interrupt
LJMP F_INT3_Interrupt
ORG 0063H ;12 Timer2 interrupt
LJMP F_Timer2_Interrupt
ORG 0083H ;16 INT4 interrupt
LJMP F_INT4_Interrupt
;******************** 主程序 **************************/
ORG 0100H ;reset
F_Main:
CLR A
MOV P0M1, A ;設置為準雙向口
MOV P0M0, A
MOV P1M1, A ;設置為準雙向口
MOV P1M0, A
MOV P2M1, A ;設置為準雙向口
MOV P2M0, A
MOV P3M1, A ;設置為準雙向口
MOV P3M0, A
MOV P4M1, A ;設置為準雙向口
MOV P4M0, A
MOV P5M1, A ;設置為準雙向口
MOV P5M0, A
MOV P6M1, A ;設置為準雙向口
MOV P6M0, A
MOV P7M1, A ;設置為準雙向口
MOV P7M0, A
MOV SP, #STACK_POIRTER
MOV PSW, #0 ;選擇第0組R0~R7
L_MainLoop:
CLR P1.7
MOV A, #250
LCALL F_delay_ms ;延時250ms
LCALL F_delay_ms ;延時250ms
SETB P1.7
CLR P1.6
MOV A, #250
LCALL F_delay_ms ;延時250ms
LCALL F_delay_ms ;延時250ms
SETB P1.6
CLR P4.7
MOV A, #250
LCALL F_delay_ms ;延時250ms
LCALL F_delay_ms ;延時250ms
SETB P4.7
CLR P4.6
MOV A, #250
LCALL F_delay_ms ;延時250ms
LCALL F_delay_ms ;延時250ms
SETB P4.6
SJMP L_MainLoop
;*******************************************************************
;*******************************************************************
;========================================================================
; 函數: F_delay_ms
; 描述: 延時子程序。
; 參數: ACC: 延時ms數.
; 返回: none.
; 版本: VER1.0
; 日期: 2013-4-1
; 備注: 除了ACCC和PSW外, 所用到的通用寄存器都入棧
;========================================================================
F_delay_ms:
PUSH 02H ;入棧R2
PUSH 03H ;入棧R3
PUSH 04H ;入棧R4
我想問問我應該怎么改?
|