Searching \ for 'First Project with PIC16F87x doesn't work' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: 'First Project with PIC16F87x doesn't work'.

Truncated match.
PICList Thread
'First Project with PIC16F87x doesn't work'
2000\02\07@110648 by anbarsystem

flavicon
face
Hi All,
My first project with the PIC16F87X doesn't work. I am simply trying to do a
conversion A/D in the PORTA0 and show it  in PORTB with leds.Also a led
blinking in the PORTC6 using TMRO overflow. I'm using a 4MHZ cristal.

See my Codes below.

#DEFINE LED     PORTC6

       list p=16f873

       include "p16f873.inc"


        __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC &
_WRT_ENABLE_OFF

;----------------------------------------------------
; Start at the reset vector
       org 0x000


Start:
       clrf PORTA
       clrf PORTB
       clrf PORTC
       bsf STATUS,RP0
       movlw B'00000111'     ;TMR0 prescaler, 1:256
       movwf OPTION_REG
       movlw b'00000001'     ;PA0=IN
       movwf TRISA
       movlw b'00000000'
       movwf TRISB                 ;PB=OUT
       movlw b'00000000'       ;PC=OUT
       movwf TRISC
       movlw b'00001110'     ;VREF+ VDD E VREF- VSS, PORTA0  A/D IN
       movwf ADCON1
       bcf STATUS,RP0      ;Fosc/8, A/D ON
       movlw b'01000001'
       movwf ADCON0



MAIN:
       clrf TMR0
       btfss INTCON,T0IF     ;Wait for Timer0 to timeout
       goto $-1
       bcf INTCON,T0IF
       btfss LED
       goto LED_ON
       bcf LED
       goto SET_AD

LED_ON:
       bsf LED

SET_AD:
       bsf ADCON0,GO     ;Start A/D conversion

Wait:
       btfss PIR1,ADIF     ;Wait for conversion to complete
       goto $-1

       movf ADRESH,W     ;Write A/D result to PORTB
       movwf PORTB
       goto MAIN

I would appreciate it if someone could make a suggestion.

Thanks in advanced.
Anbar.

2000\02\07@170541 by Tony Nixon

flavicon
picon face
anbarsystem@ZAZ.COM.BR wrote:
>
> Hi All,
> My first project with the PIC16F87X doesn't work. I am simply trying to do a
> conversion A/D in the PORTA0 and show it  in PORTB with leds.Also a led
> blinking in the PORTC6 using TMRO overflow. I'm using a 4MHZ cristal.
>
> See my Codes below.
>
> #DEFINE LED     PORTC6
>
>         list p=16f873
>
>         include "p16f873.inc"
>
>          __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC &
> _WRT_ENABLE_OFF
>

Add this..

Temp     equ 20h        ; temp timer register


{Quote hidden}

Try this value for ADCON1

        movlw b'00000100'          ; RA0,1,3 = A2D, left justify

>         movlw b'00001110'     ;VREF+ VDD E VREF- VSS, PORTA0  A/D IN
>         movwf ADCON1
>         bcf STATUS,RP0      ;Fosc/8, A/D ON

Try this value for ADCON0

        movlw b'11000001'          ; A2D = on, internal RC, chan 0

>         movlw b'01000001'
>         movwf ADCON0
>


The LED may appear not to blink because the time it takes for TMR0 to
overflow at 4MHz is about 65mS. Try this...

> MAIN:
         movlw d'10'
         movwf Temp
>         clrf TMR0
TimeWt    btfss INTCON,T0IF     ;Wait for Timer0 to timeout
>         goto $-1
>         bcf INTCON,T0IF

         decfsz Temp
         goto TimeWt

{Quote hidden}

Try this code for conversion complete

Wait     nop
        btfsc ADCON0,GO       ; (bit 2) = 0, conv is complete
        goto Wait

{Quote hidden}

--
Best regards

Tony

http://www.picnpoke.com
spam_OUTsalesTakeThisOuTspampicnpoke.com

2000\02\07@172208 by Mike Mansheim

picon face
One reason I've seen for F87X's not working right away
is the Low Voltage Programming (LVP) enable bit in the
configuration word.  It defaults to enabled, which
takes away RB3 as an I/O pin.  I only looked at enough
of your code to see that LVP wasn't disabled.  You
don't say exactly what the problem is, but if RB3 is
mysteriously not reacting properly, this would explain
it.  Set configuration word bit 7 = 0.

--- .....anbarsystemKILLspamspam@spam@ZAZ.COM.BR wrote:
{Quote hidden}

<snip>
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

2000\02\07@172446 by anbarsystem

flavicon
face
Hi Tony, thanks for your attention.
My doubts it is: Will it be that my initial configuration this correct one?
         __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC &
 _WRT_ENABLE_OFF

The led realy doesn't blink. I put on  the osciloscope in the out (PORTC6),
and nothing doesn't happen, it just is in 0.
I am using PICSTART PLUS for play the PIC16F873.
Regards.
Anbar.

{Quote hidden}

to
> do a
> > > conversion A/D in the PORTA0 and show it  in PORTB with leds.Also a
led
{Quote hidden}

_XT_OSC
{Quote hidden}

2000\02\07@230506 by Myke Predko

flavicon
face
Hi Anbar,

Your problem is that your "__CONFIG" statement does not have "_LVP_OFF" as
one of your parameters.  This screwed me up too when I found out that it was
required in PIC16F87x parts.

The statement should be:

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC &
_WRT_ENABLE_OFF & _LVP_OFF

myke

{Original Message removed}

2000\02\08@023827 by Lorick

flavicon
face
----- Original Message -----
From: <@spam@anbarsystemKILLspamspamZAZ.COM.BR>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Monday, February 07, 2000 11:00 AM
Subject: First Project with PIC16F87x doesn't work


> Hi All,
> My first project with the PIC16F87X doesn't work. I am simply trying to do
a
> conversion A/D in the PORTA0 and show it  in PORTB with leds.Also a led
> blinking in the PORTC6 using TMRO overflow. I'm using a 4MHZ cristal.


I can't offer much advice on getting your particular code to work but since
I'm new to pics as well and I was using the 16F876, the demo A/D code I
finally got working after much struggle should work for you to get you
started at least.  I didn't use a crystal for my test, just the external RC
connection, but I did get my program to do A/D on port A0 and show the left
justified highest 8 bits on port B if you can use it at all.  I modified a
demo file that came wth MPlab for the 877 chip and here's my result:


;**********************************************************
;*  This program configures the A/D Module to convert on
;*  A/D channel 0 and display the results on the LEDS on PORTC.
;* Code modified from MPlab demo file for experimental use
;**********************************************************

                    list p=16f876
                    include "p16f876.inc"

                    org 0x000

                    nop
Start
                    banksel PORTC
                    clrf PORTC                      ;Clear PORTC
                    movlw B'11000001'         ;RC, A/D enabled
                    movwf ADCON0

                    banksel OPTION_REG
                    movlw B'10000111'         ;TMR0 prescaler, 1:256
                    movwf OPTION_REG
                    clrf TRISC                      ;PORTC all outputs
                    movlw B'00001110'       ;Left justify,1 analog channel
                    movwf ADCON1          ;VDD and VSS references

                    banksel PORTC
Main
                    bsf ADCON0,GO         ;Start A/D conversion
Wait
                    btfss PIR1,ADIF             ;Wait for conversion to
complete
                    goto Wait

                    movf ADRESH,W         ;Write A/D result to PORTC
                    movwf PORTC
                    goto Main                      ;Do it again

end

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...