i remove folowing line from the initialization code above:
MOVLB 0xF ; Set BSR for banked SFRs
Then register RXTEMP at location 070h also starts working as expected. But Then another problem happens (USARTdoes not receive characters)
There is a conflict between this code and your UART routines. It may be due to the UART code not setting BSR, or trying to use the same memory location for some other purpose (can't tell without seeing all your code).
In any case, assigning RAM locations with EQU is not good practice. You should use CBLOCK and ENDC to allocate RAM space, that way each variable automatically gets its own address and there is less chance of a conflict between different parts of your program. For example:-
; initialization
CBLOCK 0x70 ; my variables start at 0x70
RXTEMP ; RXTEMP at 0x70 (1 byte)
TMP16:2 ; TMP16 at 0x71 (2 bytes)
ENDC ; next CBLOCK starts at 0x73
.
.
.
; UART variables
CBLOCK ; continues from last CBLOCK
UART_VAR ; UART_VAR at 0x73 (1 byte)
UART_BUFFER:8 ; buffer at 0x74 (8 bytes)
ENDC
Instead of MOVLB use the directive BANKSEL {SFR name or bank#}, which avoids having to remember which bank an SFR is in and is more portable between different PICs.
RAM below 0x60 can be accessed directly by instructions that have the 'ACCESS' option, so you should allocate your variables in this area if possible. SFRs between 0x60 and 0xFF are also in the 'access' bank (unfortunately this does
not include certain UART registers). The less you fiddle with the BSR the more efficient your code will be. However in assembler it is easy to lose track of which bank you are in, so for safety it is best to set it before any SFR access
except when you need the tightest possible code.
Avoid using 'magic' numbers, and write your code so that it can be easily modified without the risk of making silly mistakes. For example, instead of:-
MOVLW 0E0h ; Configure I/O
MOVWF ANSELA ; for digital inputs
MOVLW B'00100100' ; Value used to
; initialize data
MOVWF TRISA ; direction
do this:-
#define LED_1 RA0 ; pin 2 Red LED output
#define LED_2 RA1 ; pin 3 Green LED output
#define SW_1 RA2 ; pin 4 switch input
; RA3 ; pin 5 (unused output)
; RA4 ; pin 6 (unused output)
#define ADC_IN RA5 ; pin 7 battery voltage input
MOVLW (1<<ADC_IN) ; bit = 1 for analog input, else digital
BANKSEL ANSELA
MOVWF ANSELA ; set PORTA analog inputs
MOVLW (1<<SW1)|(1<<ADC_IN) ; bit = 1 for input, else output
BANKSEL TRISA
MOVWF TRISA ; set PORTA digital I/O
It may seem like a lot more work initially, but will make your program a lot easier to expand and maintain. You can easily reallocate pin functions without having to hunt down and change a bunch of 'magic' numbers, and the code is much easier to read and understand.