搜索
bottom↓
回复: 11

以下程序更换一语句后程序模拟调试为何出现错误结果

[复制链接]

出0入0汤圆

发表于 2008-9-8 10:24:00 | 显示全部楼层 |阅读模式
;*******************************************************************************
;
;        NEC Electronics     78K0S/KB1+
;
;*******************************************************************************
;        78K0S/KB1+        Sample program
;*******************************************************************************
;        Initialization
;*******************************************************************************
;<<History>>
;        2007.4.--        Release
;*******************************************************************************
;
;<<Overview>>
;
; This sample program initializes the microcontroller by setting functions
; such as clock frequency and the port to the input or output.
; After the initialization, three LED lights are controlled by two switches.
;
; <Principal setting contents in initialization>
;
; - Set the vector table
; - Set the stack pointer
; - Stop the watchdog timer operation
; - Set the CPU clock frequency at 2 MHz
; - Stop the low-speed internal oscillator
; - Set the ports to the input or output mode
; - Set the connection of on-chip pull-up resistors (input port only)
; - Set the output latches of the output ports
;
;
; <Switch input and LED output>
;
;  +---------------------------------------+
;  |  SW1  |  SW2  |  LED1 |  LED2 |  LED3 |
;  | (P40) | (P43) | (P20) | (P21) | (P22) |
;  |---------------|-----------------------|
;  |  OFF  |  OFF  |  OFF  |  OFF  |  OFF  |
;  |  ON   |  OFF  |  ON   |  OFF  |  OFF  |
;  |  OFF  |  ON   |  OFF  |  ON   |  OFF  |
;  |  ON   |  ON   |  OFF  |  OFF  |  ON   |
;  +---------------------------------------+
;
;
;<<I/O port settings>>
;
;  Input:  P40, P43
;  Output: P00-03, P20-23, P30-33, P41, P42, P44-P47, P120-P123, P130
;  # All unused ports are set as the output mode.
;
;*******************************************************************************


;===============================================================================
;
;        Vector table
;
;===============================================================================
XVCT        CSEG        AT        0000H
        DW        RESET_START                ;(00)        RESET
        DW        RESET_START                ;(02)        --
        DW        RESET_START                ;(04)        --
        DW        RESET_START                ;(06)        INTLVI
        DW        RESET_START                ;(08)        INTP0
        DW        RESET_START                ;(0A)        INTP1
        DW        RESET_START                ;(0C)        INTTMH1
        DW        RESET_START                ;(0E)        INTTM000
        DW        RESET_START                ;(10)        INTTM010
        DW        RESET_START                ;(12)        INTAD
        DW        RESET_START                ;(14)        --
        DW        RESET_START                ;(16)        INTP2
        DW        RESET_START                ;(18)        INTP3
        DW        RESET_START                ;(1A)        INTTM80
        DW        RESET_START                ;(1C)        INTSRE6
        DW        RESET_START                ;(1E)        INTSR6
        DW        RESET_START                ;(20)        INTST6

;===============================================================================
;
;        Define the ROM data table
;
;===============================================================================
XTBL1        CSEG        AT        0100H      改动处////////
LEDDATA:
        DB        00000011B                ;00: SW1=ON, SW2=ON  -> LED3=ON
        DB        00000101B                ;01: SW1=OFF,SW2=ON  -> LED2=ON
        DB        00000111B                ;02: Dummy
        DB        00000111B                ;03: Dummy
        DB        00000111B                ;04: Dummy
        DB        00000111B                ;05: Dummy
        DB        00000111B                ;06: Dummy
        DB        00000111B                ;07: Dummy
        DB        00000110B                ;08: SW1=ON, SW2=OFF -> LED1=ON
        DB        00000111B                ;09: SW1=OFF,SW2=OFF -> LED1,2,3=OFF

;===============================================================================
;
;        Define the memory stack area
;
;===============================================================================
XSTK        DSEG        AT        0FEE0H
STACKEND:
        DS        20H                        ; Memory stack area = 32byte
STACKTOP:                                ; Start address of the memory stack area = FF00H


;*******************************************************************************
;
;        Initialization after RESET
;
;*******************************************************************************
XMAIN        CSEG        UNIT
RESET_START:

;-------------------------------------------------------------------------------
;        Initialize the stack pointer
;-------------------------------------------------------------------------------
        MOVW        AX,        #STACKTOP
        MOVW        SP,        AX                ; Set the stack pointer at FF00H

;-------------------------------------------------------------------------------
;        Initialize the watchdog timer
;-------------------------------------------------------------------------------
        MOV        WDTM,        #01110111B        ; Stop the watchdog timer operation

;-------------------------------------------------------------------------------
;        Initialize the clock generators
;-------------------------------------------------------------------------------
        MOV        PPCC,        #00000010B        ; The clock supplied to the peripheral hardware (fxp) = fx/4 (= 2MHz)
        MOV        PCC,        #00000000B        ; The clock supplied to the CPU (fcpu) = fxp (= 2MHz)
        MOV        LSRCM,        #00000001B        ; Stop the low-speed internal oscillator

;-------------------------------------------------------------------------------
;        Initialize the port 0
;-------------------------------------------------------------------------------
        MOV        PM0,        #11110000B        ; Set P00-P03 as output mode
        MOV        P0,        #00000000B        ; Set output latches of P00-P03 as low

;-------------------------------------------------------------------------------
;        Initialize the port 2
;-------------------------------------------------------------------------------
        MOV        PM2,        #11110000B        ; Set P20-P23 as output mode
        MOV        P2,        #00000111B        ; Set output latches of P20-P22 as high, P23 as low

;-------------------------------------------------------------------------------
;        Initialize the port 3
;-------------------------------------------------------------------------------
        MOV        PM3,        #11110000B        ; Set P30-P33 as output mode
        MOV        P3,        #00000000B        ; Set output latches of P30-P33 as low

;-------------------------------------------------------------------------------
;        Initialize the port 4
;-------------------------------------------------------------------------------
        MOV        PM4,        #00001001B        ; Set P40 and P43 as input mode, P41, P42 and P44-P47 as output mode
        MOV        PU4,        #00001001B        ; Connect on-chip pull-up resistors to P40 and P43
        MOV        P4,        #00000000B        ; Set output latches of P41, P42 and P44-P47 as low

;-------------------------------------------------------------------------------
;        Initialize the port 12
;-------------------------------------------------------------------------------
        MOV        PM12,        #11110000B        ; Set P120-P123 as output mode
        MOV        P12,        #00000000B        ; Set output latches of P120-P123 as low

;-------------------------------------------------------------------------------
;        Initialize the port 13
;-------------------------------------------------------------------------------
        MOV        P13,        #00000001B        ; Set output latch of P130 as high

;-------------------------------------------------------------------------------
;        Initialize the general-purpose register
;-------------------------------------------------------------------------------
        MOVW        HL,        #LEDDATA        ; Set the table address to the HL register

;*******************************************************************************
;
;        Main loop
;
;*******************************************************************************
MAIN_LOOP:
        MOV        A, P4                        ; Read switch-input status
        AND        A, #00001001B                ; Mask the data except the switch-input status
        MOV        L, A                        ; Set switch-input status to the lower 8 bits of the table address
        MOV        A, [HL]                        ; Read LED output data from the table
        MOV        P2, A                        ; Output the LED light
        BR        $MAIN_LOOP                ; Go to the MAIN_LOOP


end


改动的语句为  XTBL1 CSEG  AT 0100H    改为XTBL1  CSEG         AT 0088H

出0入0汤圆

发表于 2008-9-8 12:22:52 | 显示全部楼层
错误结果是怎么样的呢?
是不能编译还是运行结果不对呢?还是其他问题?

出0入0汤圆

 楼主| 发表于 2008-9-8 14:14:25 | 显示全部楼层
编译是正常,就是结果不对(查表结果不对)

总的说来就是数据段,代码段,表数据如何安排的问题

出0入0汤圆

发表于 2008-9-8 14:24:06 | 显示全部楼层
是执行哪步逻辑出了问题呢?

出0入0汤圆

 楼主| 发表于 2008-9-8 15:07:53 | 显示全部楼层
MOV        L, A                        ; Set switch-input status to the lower 8 bits of the table address
MOV        A, [HL]                        ; Read LED output data from the table

出0入0汤圆

发表于 2008-9-8 18:01:40 | 显示全部楼层
你是用软件仿真看结果的吧?

目前没有找到不能设置088H的资料,看你程序,[HL]的值是根据P4的值得到吧,可能问题出自这里,P4的值因为代码的位置而随机得到。

我再找下相关资料,希望能找到让你满意的资料。

出0入0汤圆

 楼主| 发表于 2008-9-9 08:18:41 | 显示全部楼层
(P4的值因为代码的位置而随机得到 )这句话你理解不对,它是读取键的值 .

出0入0汤圆

发表于 2008-9-9 11:45:51 | 显示全部楼层
你能将整个项目都传上来么?
因为修改地址是允许的  我们一起调试一下  看问题出自哪里/

出0入0汤圆

 楼主| 发表于 2008-9-9 13:57:52 | 显示全部楼层
重新上传
点击此处下载 ourdev_410608.rar(文件大小:15K) (原文件名:fyz.rar)

出0入0汤圆

发表于 2008-9-10 09:19:32 | 显示全部楼层
兄弟
你项目里面都没有东西

出0入0汤圆

 楼主| 发表于 2008-9-10 10:03:03 | 显示全部楼层
已重新上传

出0入0汤圆

发表于 2008-9-10 15:29:09 | 显示全部楼层
你程序的问题是逻辑问题
如果你定义XTBL1        CSEG        AT        0100H,那么你执行
MOV        L, A
MOV        A, [HL]
后,可以将正确的查表地址传到[HL],
如果你定义XTBL1        CSEG        AT        0088H
那么你执行
MOV        L, A
MOV        A, [HL]
显然没有将正确的地址传给[HL],比如你的P4值为9,经过MOV        L, A 后
[HL]的地址就等于9
所以结果不对。

如果你在MOV        L, A 处用加不用MOV的话,就可以解决这个问题了
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-3 10:09

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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