I am programming a PIC 16F676 and have come across a problem. I am using a 20MHz ceramic as the oscillator, but the problem persists even if I use the internal 4MHz one.
You can see from the initialisation code below that I want to set PORTA 1 & 2 as inputs with pull-ups. PORTA,2 works OK, but PORTA,1 does not function at all. It uses a pushbutton to ground and I wrote the bit of code at the end to test it.
I used a digital probe to test the pins. It has two LEDs for high or low states and no LEDs lit indicates no connection. PORTA,1 shows as no connection. I fitted an external pull-up and the probe showed the operation of the pushbutton at the pin to be OK. But still the test does not work.
I have two 16F676 chips and they both behave the same. So either I have two chips with identical faults or I have a fault in my program. Any help would be most welcome.
You can see from the initialisation code below that I want to set PORTA 1 & 2 as inputs with pull-ups. PORTA,2 works OK, but PORTA,1 does not function at all. It uses a pushbutton to ground and I wrote the bit of code at the end to test it.
I used a digital probe to test the pins. It has two LEDs for high or low states and no LEDs lit indicates no connection. PORTA,1 shows as no connection. I fitted an external pull-up and the probe showed the operation of the pushbutton at the pin to be OK. But still the test does not work.
I have two 16F676 chips and they both behave the same. So either I have two chips with identical faults or I have a fault in my program. Any help would be most welcome.
Code:
main ;initialise ****** set up at switch on
bcf STATUS,5 ; select Bank 0
clrf PORTA ;init
;set up CMCON comparitor mode
;input to CIN+
;use int ref, and output to COUT
movlw b'00000100'
movwf CMCON
;set up ANSEL
bsf STATUS,5 ;Select Bank 1
; select bits for analogue (PA,0 and PC,3) (CIN+ & AN7)
movlw b'10000001'
;1 = analogue; 0 - digital
movwf ANSEL
;set PORTA 0, 1, 2, 3 , 5 as input. set 4 as output for Xtal
movlw b'101111' ;set port A in/out
movwf TRISA
movlw b'000110'
movwf WPUA ;pullups on 1 & 2
;set PORTC 0, 3, as input. Set the rest as outputs
bcf STATUS,5 ;select Bank 0
clrf PORTC ;init
bsf STATUS,5 ;Select Bank 1
movlw b'001001' ;set port C in/out
movwf TRISC
;set up OPTION timer0 prescaler
bsf STATUS,5 ;Select Bank 1
movlw b'00000001'
; b'0-------' ;pullups enabled
; b'----0---' ;prescaler to timer mode
; b'-----001' ;set prescaler = 4,
movwf OPTION_REG
;set up VRCON comparitor ref voltage
bsf STATUS,5 ;Select Bank 1
movlw b'10001111'
; b'1x-x----' ;CV power on
; b'-x0x----' ;high range
; b'-x-x1111' ;set at 3.59V
movwf VRCON
;set up for A/D ;(ADCON0)
bcf STATUS,5 ;select Bank 0
movlw b'00011100'
; b'—x111--' ;select AN7 as input
movwf ADCON0
;set up Timer0
bcf STATUS,5 ; select bank 0
movlw b'10100000' ;
; b'1-------' ;enable interrupt
; b'--1-----' ;enable TMR0 interrupt
movwf INTCON
;set up Timer1
bcf STATUS,5 ; select Bank 0
movlw b'01000000'
; b'x1------' ;timer gate enable
movwf T1CON
setup ;test for fault
btfss PORTA,1
goto setup1
goto setup2
setup1
bsf PORTC,2 ;high
goto setup
setup2
bcf PORTC,2 ;low
goto setup
