Maker Pro
Maker Pro

Need help with PIC16F676

U

uuuuu

Jan 1, 1970
0
I want to switch on PORTA pins RA4 & RA5 but the problem is that pin RA2
seems to go on as well (by on I mean low). Attached my code, I was
wondering if anyone can help to find the problem. BTW I have 3 warnings
when compiling that the wrong bank is selected, why am I getting these
warnings, I used the BANKSEL macro ?

Tia.


list p=16F676 ; list directive to define processor
#include <p16f676.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

;******************************************************************************
;Defines
;******************************************************************************

#define Bank0 0x00
#define Bank1 0x80

;******************************************************************************
;Reset Vector
;******************************************************************************
ORG 0x000 ; processor reset vector
nop ; required by in circuit debugger
goto Init ; go to beginning of program

;******************************************************************************
;Interrupt Vector
;******************************************************************************
ORG 0x004
return ; interrupt trap - returns without re-enabling
;******************************************************************************
;Initialization
;******************************************************************************
Init
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
BANKSEL Bank1 ; BANK1
movwf OSCCAL ; update register with factory cal value
movlw B'00000000' ;
movwf TRISA ;
clrf ANSEL ; configure A/D I/O as digital
banksel Bank0 ; change back to PORT memory bank
movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O
movwf CMCON ;

;******************************************************************************
;Main
;******************************************************************************
Main
movlw B'11001111' ; RA4, RA5 will be low (= on in my circuit)
movwf PORTA
main1
goto main1

;******************************************************************************
;Subroutines & Functions
;******************************************************************************


END ; directive 'end of program'
 
G

Guest

Jan 1, 1970
0
uuuuu said:
I want to switch on PORTA pins RA4 & RA5 but the problem is that pin RA2
seems to go on as well (by on I mean low). Attached my code, I was
wondering if anyone can help to find the problem. BTW I have 3 warnings
when compiling that the wrong bank is selected, why am I getting these
warnings, I used the BANKSEL macro ?

Tia.


list p=16F676 ; list directive to define processor
#include <p16f676.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
& _CPD_OFF

;******************************************************************************
;Defines
;******************************************************************************

#define Bank0 0x00
#define Bank1 0x80

;******************************************************************************
;Reset Vector
;******************************************************************************
ORG 0x000 ; processor reset vector
nop ; required by in circuit debugger
goto Init ; go to beginning of program

;******************************************************************************
;Interrupt Vector
;******************************************************************************
ORG 0x004
return ; interrupt trap - returns without re-enabling
;******************************************************************************
;Initialization
;******************************************************************************
Init
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
BANKSEL Bank1 ; BANK1
movwf OSCCAL ; update register with factory cal value
movlw B'00000000' ;
movwf TRISA ;
clrf ANSEL ; configure A/D I/O as digital
banksel Bank0 ; change back to PORT memory bank
movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O
movwf CMCON ;

;******************************************************************************
;Main
;******************************************************************************
Main
movlw B'11001111' ; RA4, RA5 will be low (= on in my circuit)
movwf PORTA
main1
goto main1

;******************************************************************************
;Subroutines & Functions
;******************************************************************************


END ; directive 'end of program'
 
G

Guest

Jan 1, 1970
0
uuuuu said:
I want to switch on PORTA pins RA4 & RA5 but the problem is that pin RA2
seems to go on as well (by on I mean low). Attached my code, I was
wondering if anyone can help to find the problem. BTW I have 3 warnings
when compiling that the wrong bank is selected, why am I getting these
warnings, I used the BANKSEL macro ?

Tia.


list p=16F676 ; list directive to define processor
#include <p16f676.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
& _CPD_OFF

;******************************************************************************
;Defines
;******************************************************************************

#define Bank0 0x00
#define Bank1 0x80

;******************************************************************************
;Reset Vector
;******************************************************************************
ORG 0x000 ; processor reset vector
nop ; required by in circuit debugger
goto Init ; go to beginning of program

;******************************************************************************
;Interrupt Vector
;******************************************************************************
ORG 0x004
return ; interrupt trap - returns without re-enabling
;******************************************************************************
;Initialization
;******************************************************************************
Init
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
BANKSEL Bank1 ; BANK1
movwf OSCCAL ; update register with factory cal value
movlw B'00000000' ;
movwf TRISA ;
clrf ANSEL ; configure A/D I/O as digital
banksel Bank0 ; change back to PORT memory bank
movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O
movwf CMCON ;

;******************************************************************************
;Main
;******************************************************************************
Main
movlw B'11001111' ; RA4, RA5 will be low (= on in my circuit)
movwf PORTA
main1
goto main1

;******************************************************************************
;Subroutines & Functions
;******************************************************************************


END ; directive 'end of program'
 
S

strill

Jan 1, 1970
0
uuuuu said:
I want to switch on PORTA pins RA4 & RA5 but the problem is that pin RA2
seems to go on as well (by on I mean low). Attached my code, I was
wondering if anyone can help to find the problem. BTW I have 3 warnings
when compiling that the wrong bank is selected, why am I getting these
warnings, I used the BANKSEL macro ?

Tia.


list p=16F676 ; list directive to define processor
#include <p16f676.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
& _CPD_OFF

;******************************************************************************
;Defines
;******************************************************************************

#define Bank0 0x00
#define Bank1 0x80

;******************************************************************************
;Reset Vector
;******************************************************************************
ORG 0x000 ; processor reset vector
nop ; required by in circuit debugger
goto Init ; go to beginning of program

;******************************************************************************
;Interrupt Vector
;******************************************************************************
ORG 0x004
return ; interrupt trap - returns without re-enabling
;******************************************************************************
;Initialization
;******************************************************************************
Init
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
BANKSEL Bank1 ; BANK1
movwf OSCCAL ; update register with factory cal value
movlw B'00000000' ;
movwf TRISA ;
clrf ANSEL ; configure A/D I/O as digital
banksel Bank0 ; change back to PORT memory bank
movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O
movwf CMCON ;

;******************************************************************************
;Main
;******************************************************************************
Main
movlw B'11001111' ; RA4, RA5 will be low (= on in my circuit)
movwf PORTA
main1
goto main1

;******************************************************************************
;Subroutines & Functions
;******************************************************************************


END ; directive 'end of program'
Hi Tia

This may be redundant but try putting a BANKSEL macro at the beginning of
init.
The assembler/PIC may be defaulting to the wrong bank.

Strill
 
U

uuuuu

Jan 1, 1970
0
Hi Tia
This may be redundant but try putting a BANKSEL macro at the beginning of
init.
The assembler/PIC may be defaulting to the wrong bank.

The bank select command was there, where were you looking ?
I'll simplify it:
To set RA2 as an output pin with low output what do I do?
Here is what I did (but it did not work as RA2 stayed high all the time)

BANKSEL Bank1
bsf TRISA,2
clrf ANSEL

banksel Bank0
movlw CM2 | CM1 | CM0
movwf CMCON
bcf PORTA,2 ; set output low

Thanks.
 
uuuuu said:
The bank select command was there, where were you looking ?
I'll simplify it:
To set RA2 as an output pin with low output what do I do?
Here is what I did (but it did not work as RA2 stayed high all the time)

BANKSEL Bank1
bsf TRISA,2
clrf ANSEL

banksel Bank0
movlw CM2 | CM1 | CM0
movwf CMCON
bcf PORTA,2 ; set output low

Thanks.

BANKSEL expects a label taken from somewhere in your code. That
"somewhere" is then examined to discover which bank it happens to be
in (it could vary as your code grows longer). Then, and only then,
will the compiler decide what instruction(s) to use for selecting the
correct bank and these will replace "BANKSEL <variable>". (section
5.6, page 40 of MPASM user's guide)

My guess is that you need to do something like this:-

BANKSEL TRISA

to keep the compiler happy.
bsf TRISA,2

should be

bcf TRISA,2

to set to output

Cheers
Robin
 
C

Charles Jean

Jan 1, 1970
0
Ater configuration word and before variable and constant declarations
put:

errorlevel -302

this will suppress the warnings you are getting for bank selections

a quirk, I quess, with MPASM

What a way to run a railroad!!!


I didn't make myself clear earlyer.
I am refering to the code in your first posting.
What I was suggesting was that in the very first line in the init section
the bank should be changed to bank1.
According to the manual I am looking at bank1 should be selected before calling
0x3ff
On power up the 16f676 defaults to bank0
No bank selection is made before calling 0x3ff.This would cause some indeterminate
result,possibly an endless loop or crash.
This may explain why RA2 stays high and the assembler warnings.

Strill

If God hadn't intended us to eat animals,
He wouldn't have made them out of MEAT! - John Cleese
 
Top