找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1716|回复: 4
打印 上一主题 下一主题
收起左侧

点亮LED程序出问题

[复制链接]
跳转到指定楼层
楼主
ID:272142 发表于 2018-5-12 23:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 放晴的那天 于 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

我想问问我应该怎么改?

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:326783 发表于 2018-5-13 00:18 | 只看该作者
#include "IAP15W4K58S4.h"
void Delay(uint Dtime)
{
      uchar i;

}
回复

使用道具 举报

板凳
ID:155507 发表于 2018-5-13 07:21 | 只看该作者

  1.         ORG    0000H     ;reset
  2.         LJMP   START
  3.         ORG    100H

  4. START:  SETB P1.0
  5.         LCALL DELAY
  6.         CLR  P1.0
  7.         LCALL DELAY
  8.         AJMP   START
  9. DELAY:  MOV R7 , #250
  10.      D1:MOV R6 , #250
  11.      D2:DJNZ R6,D2
  12.         DJNZ R7,D1
  13.         RET
  14.         END
  15.                                
复制代码
回复

使用道具 举报

地板
ID:272142 发表于 2018-5-13 08:46 | 只看该作者
LanSeXinQing 发表于 2018-5-13 00:18
#include "IAP15W4K58S4.h"
void Delay(uint Dtime)
{

我用的是汇编,请问能说说汇编怎么改吗
回复

使用道具 举报

5#
ID:381625 发表于 2019-4-15 14:26 | 只看该作者
我也不知道为什么我要回复一个快一年的帖子)
设定P1口为双向即可使用
P1M0=0
P1M1=0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表