Pic 16f876a Programming Problem

Reply

Join Date: Sep 2006
Posts: 3
Reputation: Jeffxxx is an unknown quantity at this point 
Solved Threads: 0
Jeffxxx Jeffxxx is offline Offline
Newbie Poster

Pic 16f876a Programming Problem

 
0
  #1
Sep 13th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 127
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Re: Pic 16f876a Programming Problem

 
0
  #2
Sep 14th, 2006
Hi,I think I can help you but can I see the circuit you are working on.And I also think you should use PROTEUS for simulations....you can actually add analog input and test your program from there...
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 155
Reputation: mostafadotnet is on a distinguished road 
Solved Threads: 10
mostafadotnet's Avatar
mostafadotnet mostafadotnet is offline Offline
Junior Poster

Re: Pic 16f876a Programming Problem

 
0
  #3
Sep 14th, 2006
Hi Jefxxx,
This simulator is one the bests:
http://www.oshonsoft.com/pic.html
Also,I'll give you anything I found about your code and any othe related things I found.And also I'll help you as much as I can.

Good luck.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: Jeffxxx is an unknown quantity at this point 
Solved Threads: 0
Jeffxxx Jeffxxx is offline Offline
Newbie Poster

Re: Pic 16f876a Programming Problem

 
0
  #4
Sep 16th, 2006
Originally Posted by mostafadotnet View Post
Hi Jefxxx,
This simulator is one the bests:
http://www.oshonsoft.com/pic.html
Also,I'll give you anything I found about your code and any othe related things I found.And also I'll help you as much as I can.

Good luck.
Hi,
Many thanks for your help.
t tried the simulator with my program and it seems
to work perfectly, Inact seems a great simulator, thanks
, so possibly it is a hardware problem .
I will try and inclute a circuit diagram
Regards
Jeff
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 7
Reputation: embeddedravi is an unknown quantity at this point 
Solved Threads: 0
embeddedravi embeddedravi is offline Offline
Newbie Poster

Re: Pic 16f876a Programming Problem

 
0
  #5
Sep 25th, 2006
R U Solve That Problm.......................
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: Jeffxxx is an unknown quantity at this point 
Solved Threads: 0
Jeffxxx Jeffxxx is offline Offline
Newbie Poster

Re: Pic 16f876a Programming Problem

 
0
  #6
Oct 5th, 2006
Originally Posted by embeddedravi View Post
R U Solve That Problm.......................
Hi,
Sorry for delay in responding.
I found two problems:-
First the two caps. for the crystal were faulty, replaced and ran OK.
Second I had set the wrong bit for turning on the 12V led and the 24V
led, they should have been bit 2 and 3.
It now works perfectly.
Many thanks for all your input.
Regards,
Jeff:p
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC