Hi,
I am a newbie in this wonderful world of PIC programming and having some problems, so
I'm hopeing some one out there can help me out.
I have written a program for the pic 16f876a microcontroller, this uses RA0 as an analogue
input. I have tested it with MPLAB simulator and seems to work ok. Unfortunately MPLAB does not
seem to support analogue input simulation, I could be wrong here.
I have programmed the PIC with no problems encountered, but when I breadboard, it will not
function. All the external components are in the correct locations, using 100k pull-up
resistor on the MCLR pin and using a 10k pot for analogue input on pin 2 of the PIC. I would appreciated
it if someone could have a look at my programe
Also I would appreciate any good links, especially a simulator that allows analogue input.
Hope someone can help me out there, before I pull out all my hair.
Many thanks,
Jeff
The programme listing:-
;CHARGE CONTROLER
PROCESSOR 16F876a
INCLUDE <p16f876a.inc>
__config _HS_OSC & _WDT_OFF & _PWRTE_ON
;CONSTANTS
STATUS EQU 03H
TRISA EQU 85H ;BANK 1
TRISB EQU 86H ;BANK 1
PORTA EQU 05H
PORTB EQU 06H
ADCON0 EQU 1Fh
ADCON1 EQU 9FH ;BANK 1
ADRES EQU 1EH
GODONE EQU 02H
CARRY EQU 00H
;SET UP PORTS
BSF STATUS,5 ;TO BANK 1
MOVLW H'ff'
errorlevel -302
MOVWF TRISA ;PORT A INPUT
MOVLW 00H
MOVWF TRISB ;PORT B OUTPUT
MOVLW B'00000100'
MOVWF ADCON1 ;SET RA0,1,3 ANALOGUE INPUTS
BCF STATUS,5 ;TO BANK 0
errorlevel +302
MOVLW B'01000001'
MOVWF ADCON0 ;CLOCK 4Mz
CLRF PORTA
CLRF PORTB
GOTO START
;24V ROUTINE
ROUTINE24V BSF PORTB,1 ;24V LED ON
BEGIN2 BSF ADCON0,2
WAIT2 BTFSC ADCON0,2
GOTO WAIT2
MOVF ADRES,W ;READ ANALOGUE VALUE
SUBLW .179 ;3.5V Used for test purpose
BTFSC STATUS,CARRY
GOTO CHARGE24V
BCF PORTB,0 ;BIT 0 CLEAR
BCF PORTB,4 ;BIT 4 CLEAR
BSF PORTB,1 ;BIT 1 SET
BSF PORTB,5 ;BIT 5 SET
GOTO BEGIN2
;CHARGING ROUTINES
CHARGE12V BSF PORTB,0 ;BAT TR ON
BSF PORTB,4 ;BAT LED ON
BCF PORTB,1 ;DUMP TR OFF
BCF PORTB,5 ;DUMP LED OFF
GOTO BEGIN
CHARGE24V BSF PORTB,0 ;BAT TR ON
BSF PORTB,4 ;BAT LED ON
BCF PORTB,1 ;DUMP TR OFF
BCF PORTB,5 ;DUMP LED OFF
GOTO BEGIN2
START
BTFSS PORTA,2 ;CHECk SW FOR 12V OR 24V
GOTO ROUTINE24V
BSF PORTB,0 ;TURN ON 12V LED
BEGIN BSF ADCON0,2 ;TURN ON ANALOGUE INPUT
WAIT BTFSC ADCON0,2
GOTO WAIT ;WAIT UNTILL ANALOGUE CONVERTION COMPLET
MOVF ADRES,W
SUBLW .128 ;2.5V. TEST, CHECK IF REQUIRES CHARGING
BTFSC STATUS,CARRY
GOTO CHARGE12V
BCF PORTB,0 ;TURN OFF BAT TRANS
BCF PORTB,4 ;BAT LED OFF
BSF PORTB,1 ;DUMP TR ON
BSF PORTB,5 ;DUMP LED ON
GOTO BEGIN
end