maiducphu
11-12-2010, 05:22 PM
Mình thử viết chương trình này, mục đích xem kỹ thuật tra bảng khi dùng thanh ghi PCL,
mình dùng con pic 18f4520, thạch anh 20MHZ, cho led chạy lần lượt từ RB7 đến RB0 rồi lặp lại. Nhưng khi nạp thử thì nó chỉ sáng từ rb7 về rb4 rồi lặp lại. Khi debug, mình thấy nó gọi cái table nhưng trả về giá trị không đúng. Mình tìm mà không biết lỗi chỗ nào. Mong mọi người giúp đỡ với. Cám ơn forum^^
list p=18f4520
#include "P18f4520.inc"
org 0x00
goto start
org 0x20
count1 res .2
counta res .2
countb res .2
count res .2
temp res .2
org 0x30
start
movlw 0x0e
movwf ADCON1
clrf PORTB
clrf TRISB
clrf STATUS
clrf count1
clrf counta
clrf countb
clrf count
clrf temp
loop1
clrf count
loop2
movff count, WREG
call table
movwf PORTB
call delay200ms
call delay200ms
call delay200ms
incf count
movf count, w
xorlw .8
btfsc STATUS, Z
goto loop1
goto loop2
table
addwf PCL
retlw b'10000000'
retlw b'01000000'
retlw b'00100000'
retlw b'00010000'
retlw b'00001000'
retlw b'00000100'
retlw b'00000010'
retlw b'00000001'
delay200ms
movlw .200
movwf count1
d1 ;delay 1ms
movlw .50
movwf counta
d2
movlw .25
movwf countb
delay_0
nop
decfsz countb
goto delay_0
decfsz counta
goto d2
decfsz count1
goto d1
retlw 0x00
end
mình dùng con pic 18f4520, thạch anh 20MHZ, cho led chạy lần lượt từ RB7 đến RB0 rồi lặp lại. Nhưng khi nạp thử thì nó chỉ sáng từ rb7 về rb4 rồi lặp lại. Khi debug, mình thấy nó gọi cái table nhưng trả về giá trị không đúng. Mình tìm mà không biết lỗi chỗ nào. Mong mọi người giúp đỡ với. Cám ơn forum^^
list p=18f4520
#include "P18f4520.inc"
org 0x00
goto start
org 0x20
count1 res .2
counta res .2
countb res .2
count res .2
temp res .2
org 0x30
start
movlw 0x0e
movwf ADCON1
clrf PORTB
clrf TRISB
clrf STATUS
clrf count1
clrf counta
clrf countb
clrf count
clrf temp
loop1
clrf count
loop2
movff count, WREG
call table
movwf PORTB
call delay200ms
call delay200ms
call delay200ms
incf count
movf count, w
xorlw .8
btfsc STATUS, Z
goto loop1
goto loop2
table
addwf PCL
retlw b'10000000'
retlw b'01000000'
retlw b'00100000'
retlw b'00010000'
retlw b'00001000'
retlw b'00000100'
retlw b'00000010'
retlw b'00000001'
delay200ms
movlw .200
movwf count1
d1 ;delay 1ms
movlw .50
movwf counta
d2
movlw .25
movwf countb
delay_0
nop
decfsz countb
goto delay_0
decfsz counta
goto d2
decfsz count1
goto d1
retlw 0x00
end