944,172 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 8419
  • Assembly RSS
Sep 13th, 2006
0

Pic 16f876a Programming Problem

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jeffxxx is offline Offline
3 posts
since Sep 2006
Sep 14th, 2006
0

Re: Pic 16f876a Programming Problem

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...
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004
Sep 14th, 2006
0

Re: Pic 16f876a Programming Problem

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.
Reputation Points: 55
Solved Threads: 11
Junior Poster
mostafadotnet is offline Offline
157 posts
since Jul 2006
Sep 16th, 2006
0

Re: Pic 16f876a Programming Problem

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jeffxxx is offline Offline
3 posts
since Sep 2006
Sep 25th, 2006
0

Re: Pic 16f876a Programming Problem

R U Solve That Problm.......................
Reputation Points: 10
Solved Threads: 0
Newbie Poster
embeddedravi is offline Offline
10 posts
since Sep 2006
Oct 5th, 2006
0

Re: Pic 16f876a Programming Problem

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jeffxxx is offline Offline
3 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Where can i learn about assembly language
Next Thread in Assembly Forum Timeline: beep codes, and frequency





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC