BlackOps
Full Member level 5
- Joined
- Jan 1, 2005
- Messages
- 279
- Helped
- 14
- Reputation
- 28
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- AZERBAIJAN
- Activity points
- 2,496
Hello, i am simulating simple circuit using PROTEUS on PIC16F84A.
i am loading number 5 to the w register.
then i display this number on LED display using RB0-RB6 pins of the chip.
but i dont fully understand this program.
here is the debug source code:
let me now describe the work of program, so that u know did i understood it correctly or no..
000c well here we just put number 5 to w register
000d we call segment, PC+1 goes to STACK (000e goes to stack)
000f we add: w(it has 5 now) + PCL (it must have 000F now yes?) = 14!!!
i wonder if 5+F=14, then now instruction with 0014 address must be executed, and it is: retlw 0x66
but instruction 0015 is executed, retlw 0x6d, and then 0x6d is loaded to w register, and Top of the STack (000e) returns to PC...
then number 5 is displayed! well, everything works correct!
i just dont understand... if value of PCL is 000f and w is 5 then why instruction with address 0015 loaded?
a also tried to use watch window during debug for PCL, and PCLATH but it displayed nothing....why?...
thanks
i am loading number 5 to the w register.
then i display this number on LED display using RB0-RB6 pins of the chip.
but i dont fully understand this program.
here is the debug source code:
Code:
,,,org 0 ; start at address
00000000,2808,goto,goto main
,,,; Space for interrupt handlers
00000008,,org,org 0x08
00000008,,main:,main:
00000008,,Start,Start
00000008,1683,, bsf STATUS,RP0
00000009,3000,, movlw b'00000000'
0000000A,0086,, movwf TRISB
0000000B,1283,, bcf STATUS,RP0
0000000C,3005,, movlw b'00000101' ;putting number 5 to w reg
0000000D,200F,, call segment
0000000E,0086,, movwf PORTB
,,,
,,,
,,,
0000000F,,segment:,segment:
0000000F,0782,addwf,addwf PCL,1 ; F + 5 = 0x14, why it gets 0x6d but not 0x66?
00000010,343F,retlw,retlw 0x3f ; 0 code
00000011,3406,retlw,retlw 0x06 ; 1
00000012,345B,retlw,retlw 0x5b ; 2
00000013,344F,retlw,retlw 0x4f ; 3
00000014,3466,retlw,retlw 0x66 ; 4
00000015,346D,retlw,retlw 0x6d ; 5
00000016,347D,retlw,retlw 0x7d ; 6
00000017,3407,retlw,retlw 0x07 ; 7
00000018,347F,retlw,retlw 0x7f ; 8
00000019,346F,retlw,retlw 0x6f ; 9
0000001A,3477,retlw,retlw 0x77 ; A
0000001B,347C,retlw,retlw 0x7c ; B
0000001C,3439,retlw,retlw 0x39 ; C
0000001D,345B,retlw,retlw 0x5b ; D
0000001E,3479,retlw,retlw 0x79 ; E
0000001F,3471,retlw,retlw 0x71 ; F
00000020,347F,retlw,retlw 0x7f ; Just in case all on
let me now describe the work of program, so that u know did i understood it correctly or no..
000c well here we just put number 5 to w register
000d we call segment, PC+1 goes to STACK (000e goes to stack)
000f we add: w(it has 5 now) + PCL (it must have 000F now yes?) = 14!!!
i wonder if 5+F=14, then now instruction with 0014 address must be executed, and it is: retlw 0x66
but instruction 0015 is executed, retlw 0x6d, and then 0x6d is loaded to w register, and Top of the STack (000e) returns to PC...
then number 5 is displayed! well, everything works correct!
i just dont understand... if value of PCL is 000f and w is 5 then why instruction with address 0015 loaded?
a also tried to use watch window during debug for PCL, and PCLATH but it displayed nothing....why?...
thanks