Hello All, This PCLATH problem is driving me mad !, I am going round in circles and still can't seem to 'reliably' cross the 256 byte page boundaries. For some reason my program crashes every time I try to return a value from beyond address 0x100; the program works perfectly up to and including address 0x100 but beyond that - no chance. I am now using the PIC16C84 since I got tired of keep erasing and re-programming the 16C65 which I ultimately intend to employ once I have got round this PCLATH problem. I have incorporated the page boundary cross detection routine which I thought would solve the problem. Am I correct with the way I understand the PCLATH and page memory: Since I have placed the base address of the first look-up table (string_0) at address 0x74, then counting the characters from string_0 through to string_3 results in a page cross occurring at address 0xFF. - (i.e. the text "From" in the latter part of string_3 is assigned to successive addresses: "F"=0x0FE, "r"=0x0FF, "o"=0x100 and "m"=0x101). Now, the program displays strings 0, 1 and 2 with no problem, but will only display the text in string 3 up to the letter "o" in the word "From". Obviously there is a problem when the lower byte (PCL) of the program counter overflows from FF to 00, but why does the INCF PCLATH,F instruction not correct this upon detection of the carry being set by the overflow of PCL ? - this does not make any sense to me since the INCF PCLATH,F instruction must have been executed in order to return the letter "o" (address 0x100) in the word "From", but for some reason on the second pass the letter "m" and indeed all other letters in all other text strings fails to be returned. Am I doing something really stupid here ?, am I missing something really simple ?, or both ?. -Please have a quick look at my listing and see if you can spot the fault as I am sure many other people on the list will also benefit from the outcome of this problem. Thank you all so much: Lee Hewitt (Manchester ENGLAND) TITLE "Nightmare On PCLATH Street Version 36 (yes honestly)" SUBTITLE "Won't try this again in a hurry" LIST P=16c84, R=HEX include "p16c84.inc" include "a:\defs\lcd_defs.h" ERRORLEVEL -302 ;Supress incorrect bank selection message __config _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ;LCD Message Equates message_1 equ 0x00 message_2 equ 0x01 message_3 equ 0x02 message_4 equ 0x03 message_5 equ 0x04 message_6 equ 0x05 message_7 equ 0x06 ;LCD File Marker Equates EOMSG equ 0x04 EOLN equ 0x0D ;Other Equates RAM_BASE equ 0xC0 RAM_TOP equ 0x2F ;Defines #define ZERO STATUS,Z #define CARRY STATUS,C #define RPAGE STATUS,5 #define E_LINE PORTB,4 #define RS_LINE PORTB,5 #define RBPU 0X01,7 ;Bank switching defines #define PAGE_1 bsf STATUS,RP0 #define PAGE_0 bcf STATUS,RP0 ;Macro definitions pulse_e macro bsf E_LINE call short_delay bcf E_LINE endm ;variables cblock 0x0C ;Start code block at 0x30 to prevent USART corruption msg_ptr char_ptr dly_cnt_1 dly_cnt_2 dly_cnt_3 temp temp1 endc ;----------------------------------------------------------------------------- ; reset vector ;----------------------------------------------------------------------------- org 00h goto reset ;----------------------------------------------------------------------------- ; program entry point ;----------------------------------------------------------------------------- reset bcf STATUS,RP1 ;Always maintain this bit clear for PIC16Cxx movlw 0x00 ;Initial set-up of I/O ports movwf PORTA ;Set-up of registers in Bank 1 PAGE_1 ;Select bank 1 movlw 0x00 movwf TRISA ;Port A - all pins unused, output 0 movwf TRISB ;Port B - all pins outputs (LCD Module) bsf RBPU PAGE_0 ;Select bank 0 movlw b'00001111' movwf PORTB clrf INTCON ;**** Dissable ALL interupts **** movlw b'10000000' ;Disable weak pull-ups on Port B ?? option ;Set-up LCD Module and display the initial Power Up message start call init_lcd ;Initialise LCD module call long_delay ;Wait for LCD to reliably initialise call long_delay ;Wait for LCD to reliably initialise movlw message_1 ;Display: "Power On Reset" message call write_string ;Call subroutine to write text srting to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_2 ;Display: "Waiting For SOH" message call write_string ;Call subroutine to write text string to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_3 ;Display: "Connection Established" message call write_string ;Call subroutine to write text string to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_4 ;Display: "Waiting For STX" message call write_string ;Call subroutine to write text srting to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_5 ;Display: "Receiving Config Data" message call write_string ;Call subroutine to write text srting to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_6 ;Display: "Waiting For EOT" message call write_string ;Call subroutine to write text string to LCD call long_delay call long_delay movlw CLR_DISP ;Clear the disply ready for next message call send_lcd_cmd call long_delay call long_delay movlw message_7 ;Display: "Data Transfer Complete" message call write_string ;Call subroutine to write text srting to LCD call long_delay call long_delay call long_delay call long_delay call long_delay call long_delay goto start ;Subroutine write_string clrf char_ptr ;Clear character pointer to zero movwf msg_ptr ;Load message pointer with message number clrc ;Clear carry 'flag in status registe r' ws1: rlf msg_ptr,w ;Multiply by two to prevent pointing to go to addwf PCL,f ;Computed GOTO < msg_ptr == string point er > call string0 ;Get next character in the string goto ws2 ;Upon return call ws2 to step through ch aracters call string1 goto ws2 call string2 goto ws2 call string3 goto ws2 call string4 goto ws2 call string5 goto ws2 call string6 ;fall into ws2 upon return ws2: movwf temp1 ;store char returned from table in temp1 xorlw EOMSG ;test for end of message marker (0x04) btfsc ZERO ;Zero set iff EOM is detected return ;End Of Message marker detec ted, thus return movf temp1,w xorlw EOLN ;Test for EOL marker btfsc ZERO goto new_line_1 movf temp1,w call send_lcd_char tst incf char_ptr,f goto ws1 new_line_1 movlw NW_LINE ;send new line command to display call send_lcd_cmd call short_delay goto tst ;Text string look-up tables string0 movlw 0x00 ;Load HIGH byte movwf PCLATH movlw 0x74 ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,f movwf PCL org 0x74 dt "*** Power On ***",EOLN," Master Reset ",EOMSG string1 movlw 0x00 ;Load HIGH byte movwf PCLATH movlw 0x9D ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,f movwf PCL dt "Waiting For SOH",EOLN,"From Host PC ...",EOMSG ;Start at A9 string2 movlw 0x00 ;Load HIGH byte movwf PCLATH movlw 0xC5 ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,f movwf PCL dt " Connection Has ",EOLN,"Been Established",EOMSG ;Start at D1 string3 bcf PCLATH,0 movlw 0x00 ;Load HIGH byte movwf PCLATH movlw 0xEE ;Load LOW byte addwf char_ptr,w btfsc STATUS,C bsf PCLATH,0 INCF PCLATH,f movwf PCL dt "Waiting For STX",EOLN,"From Host PC ...",EOMSG ;start at 1FA string4 movlw 0x01 ;Load HIGH byte movwf PCLATH movlw 0x16 ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,F movwf PCL dt "Receiving Config",EOLN," Data From Host ",EOMSG ;Start at 122 string5 movlw 0x01 ;Load HIGH byte movwf PCLATH movlw 0x3F ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,f movwf PCL dt "Waiting For EOT",EOLN,"From Host PC ...",EOMSG ;Start at 14B string6 movlw 0x01 ;Load HIGH byte movwf PCLATH movlw 0x67 ;Load LOW byte addwf char_ptr,w btfsc STATUS,C INCF PCLATH,f movwf PCL dt " Data Transfer ",EOLN," *** Complete ***",EOMSG ;Start at 173 ****** END OF PROGRAM **** =================================================== Lee Hewitt Manchester ENGLAND Home E-Mail: LHewitt104@aol.com University E-Mail: L.Hewitt@eee.salford.ac.uk ===================================================