![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
hi there, i am currently trying to use lookup table to simplify my program , below is the coding:- Code:
pcl equ 03h
movlw 0x00 ;get high 8 bits of Table address
movwf PCLATH ;save to PCLATH (may not be correct, yet)
movlw 0x80 ;get Table low address
addwf offset,W ;add value of offset, keep result in W
;if page is crossed, carry will be set
btfsc STATUS,C ;check page crossed? Skip next if NO
incf PCLATH ;yes, increment PCLATH
call Table ;call to table
org 0x50
Table:
movwf pcl
retlw 0x88
retlw 0x70
retlw 0x38
movwf PORTD
call DELAY
| |
| |
| | #2 |
|
You are using 0x80 as the table address instead of 0x50. Also the code will return after the call to table so you need something after the call. BTW, you can use movlw low(table) to load W with the low byte. Likewise, you can use movlw high(table) for the high byte. Mike. | |
| |
| | #3 |
|
Hi mike, thanks for your quick reply, i have tried as what u said Code: pcl equ 02h
movlw 0x00 ;get high 8 bits of Table address
movwf PCLATH ;save to PCLATH (may not be correct, yet)
movlw 0x50 ;get Table low address
addwf offset,w ;if page is crossed, carry will be set
btfsc STATUS,C
incf PCLATH
call Table
movwf PORTD
call DELAY
org 0x50
Table: movwf pcl
retlw 0x88
retlw 0x70
retlw 0x38
retlw 0xff
retlw 0xff
your help is much appreciated!! | |
| |
| | #4 |
|
Shouldnt you do "ADDWF PCL,f ... ... ..." You are just reseting the PCL not advancing it | |
| |
| | #5 |
|
If you post snippets of code then it is very difficult to help. If you post an example that can be assembled then it is easy to see what is wrong. In your code above I have no idea what is in location "offset" or if you have set the port to output etc. Mike. | |
| |
| | #6 |
|
hi mike , sorry for bringing you trouble here's the complete code , Code: #include "P16f877a.inc" __CONFIG 0x399A cblock 0x20 offset endc COUNT1 EQU 2DH COUNT2 EQU 2EH pcl equ 02h org 0x00 BSF STATUS,5 ; set bit 5 of STATUS to change to bank 1 BANKSEL TRISB clrf TRISB BCF STATUS,5 BANKSEL PORTB clrf PORTB movlw 0x00 ;get high 8 bits of Table address (Page 0) movwf PCLATH ;store into PCLATH movlw 0x50 addwf offset,w btfsc STATUS,C incf PCLATH call Table movwf PORTD call DELAY org 0x50 Table: movwf pcl retlw 0x88 retlw 0x70 retlw 0x38 retlw 0xff retlw 0xff DELAY ; common delay for all condition MOVLW d'200' MOVWF COUNT1 DELAY1 DECFSZ COUNT2,1 GOTO DELAY1 DECFSZ COUNT1,1 GOTO DELAY1 RETURN END | |
| |
| | #7 |
|
hi mike, i haven make the changes for addwf , i get back to you after i change it.. thanks... | |
| |
| | #8 |
|
You haven't put a valid value in offset. You are also setting PortB to output and then writing to PortD. This should get you started, Code: #include "P16f877a.inc" __config 0x399A cblock 0x20 offset endc COUNT1 equ 2DH COUNT2 equ 2EH pcl equ 02h org 0x00 bsf STATUS,5 ; set bit 5 of STATUS to change to bank 1 banksel TRISB clrf TRISB clrf TRISD ;set port D to output bcf STATUS,5 banksel PORTB clrf PORTB again movlw 1 ;start at entry 1 movwf offset Loop movlw 0x00 ;get high 8 bits of Table address (Page 0) movwf PCLATH ;store into PCLATH movlw 0x50 addwf offset,w btfsc STATUS,C incf PCLATH call Table movwf PORTD call DELAY incf offset,f ;move to next entry movlw 6 ;length of table xorwf offset,W btfss STATUS,Z ;reached the end? goto Loop ;no so keep going goto again ;yes so reset offset org 0x50 Table: movwf pcl retlw 0x88 retlw 0x70 retlw 0x38 retlw 0xff retlw 0xff DELAY ; common delay for all condition movlw d'200' movwf COUNT1 DELAY1 decfsz COUNT2,1 goto DELAY1 decfsz COUNT1,1 goto DELAY1 return end | |
| |
| | #9 |
|
Mike, are you sure MOVWF PCL is not a mistake, I would think it to be ADDWF PCL? From what I understand the way the table works is by adding to the program counter latch "PCL" you advance the program, if you add 3 it skips 3 instructions and goes to the 3rd item on the table. Do I misunderstand? | |
| |
| | #10 |
|
The way the code above is written it calculates the address in the table and so movwf is correct. You can use addwf but then the table cannot cross a page boundary. Try running the above code in the simulator to see the difference. Mike. | |
| |
| | #11 |
|
hi mike, thanks a lot...you are always so kind helping me...it's working , if i didnt set offset it will be 255 inside right?? and that cause an error?? regards tk | |
| |
| | #12 |
|
If you don't write a value it will just be a random number and jump to a random point in your code. This was why it was crashing. Mike. | |
| |
| | #13 |
|
hi mike , oh i get what you mean , thanks =).. Regards, TK | |
| |
|
| Tags |
| 877a, paging |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Debugging 877A with MPLAB | williB | Micro Controllers | 10 | 7th May 2007 04:53 PM |
| Pic 877A and boost converter | williB | Micro Controllers | 15 | 4th May 2007 03:14 AM |
| Help in paging 16F877 | TronicBrain | Micro Controllers | 6 | 2nd May 2007 03:16 PM |
| Difference between 877 and 877A? | liupengjian | Micro Controllers | 2 | 19th March 2004 02:13 AM |
| Plaese Help!! - Programming 877A using JDM | dy001 | Micro Controllers | 7 | 17th November 2003 02:38 PM |