PIC problem!

Thread Starter

vane

Joined Feb 28, 2007
189
What program did you draw that in?

Got a few old computer psus.

Do you just put the LEDs in between the certain port and Vcc?
 

BMorse

Joined Sep 26, 2009
2,675
What program did you draw that in?

Got a few old computer psus.

Do you just put the LEDs in between the certain port and Vcc?

I drew it up in Eagle (Lite version).....

You can place an LED in series with a resistor to either VCC or VSS, depends on how you want to turn them on...

I usually connect it to where it is in series with a resistor to Vcc, then I use :
bcf to turn it on and bsf to turn it off...
 

Attachments

Thread Starter

vane

Joined Feb 28, 2007
189
I replaced the config with the fuses you said earlier but it did not work, all it is doing is making all the outputs high :(
Which config gets it to use the inbuilt oscillator?
 

BMorse

Joined Sep 26, 2009
2,675
I replaced the config with the fuses you said earlier but it did not work, all it is doing is making all the outputs high :(
Which config gets it to use the inbuilt oscillator?
I don't believe the F84A has an internal oscillator option

• LP Low Power Crystal
• XT Crystal
• HS High Speed Crystal
• RC Resistor/Capacitor


Have you tried the _RC_OSC settings with the RC setup with a 10K resistor and a 100nf capacitor in the circuit like I posted (post #20)??
 

BMorse

Joined Sep 26, 2009
2,675
These are from the Datasheet of the Pic16F84A:

The PIC16F84A oscillator design requires the use of a
parallel cut crystal. Use of a series cut crystal may give
a frequency out of the crystal manufacturers
specifications. When in XT, LP, or HS modes, the
device can have an external clock source to drive the
OSC1/CLKIN pin
When using resonators with frequencies
above 3.5 MHz, the use of HS mode rather
than XT mode, is recommended. HS mode
may be used at any VDD for which the
controller is rated.
 

BMorse

Joined Sep 26, 2009
2,675
Try setting it up as shown in post #20 (The circuit I posted) and run this code in your pic, connect the LED to RA0 with a resistor in between the Pic pin and the LED going to VCC.

Rich (BB code):
;********************************************************
;PIC16F84A Code template ASM file
;By Brent Morse,    2006
;********************************************************
    list    p=16f84A
    include "p16f84A.inc"
    ERRORLEVEL    -224,-302,-305    ;supress compiler errors
    __FUSES _CP_OFF & _WDT_ON & _RC_OSC & _PWRTE_OFF 

    cblock    0x0c                    ;This is where you declare your variables
        safe_w
        safe_s
        tick
    endc
;---COMMON-------all inputs pulled high externally
#define    LED        PORTA,0            ;
;----------------------------------------------
    org    0x00         
    goto   Start
    
;---INTERRUPT ROUTINE--------------------------
    org     0x04                    ;interrupt vector
INT    ;save working vars
    movwf   safe_w                  ;save w
    swapf   STATUS,w                ;swap status, w
    movwf   safe_s                  ;save status(nibble swap, remember)
;----------------------------------------------
;Do Interrupt stuff here
;----------------------------------------------
    clrwdt                            ;Clear the watchdog timer

End_int    ;restore working vars
    swapf   safe_s,w                ;fetch status, reswap nibbles
       movwf   STATUS                  ;restore status
       swapf   safe_w,f                ;swap nibbles in preparation
       swapf   safe_w,w                ;for the swap restoration of w
       bcf     INTCON,2                ;clear interrupt flag
        retfie                          ;return from interrupt
;---end of Interrupt routine-----------------

;-----------------------------------
Port_init

    ;PORTA-------------------------
        BANKSEL PORTA         ;
        clrf PORTA             ;Init PORTA
        bcf STATUS,RP1         ;Bank 1
        BANKSEL TRISA         ;
        movlw b'00000000'    ;All Outputs
        movwf TRISA         ;
        ;PORTB-------------------------
        BANKSEL PORTB         ;
        clrf PORTB             ;Init PORTB
        bcf STATUS,RP1         ;Bank 1
        BANKSEL TRISB         ;
        movlw b'11111111'     ;All Inputs
        movwf TRISB         ;    
        retlw   0
;-----------------------------------
Timer_init
        bsf     INTCON,7        ;enable global interrupts
        bsf     INTCON,5        ;enable TMR0 int
        bcf     INTCON,2        ;clear TMR0 int flag
        clrf    TMR0            ;clear timer
        clrwdt                  ;clear watchdog timer
        movlw   b'00000000'     ;set up timer. no prescale
                                ;set int to TMR0 not WDT
                                ;portb pullups not enabled 
        option                  ;send w to option. generate warning.
        clrf    TMR0            ;start timer
        retlw   0
;------------------------------------
; a short delay routine
;--------
Delay        movwf    tick
Delay_loop    decfsz    tick,f
        goto    Delay_loop            ;w is not damaged, so Delay can
        return                        ;be recalled without reloading


; Program starts here
;--------------------
Start   call    Port_init           ;set port directions    
        call    Timer_init          ;start timer based interrupt 
My_loop
        
        bcf        LED                    ;turn on led
        movlw    0xFF
        call    Delay                ;Run Delay, so you can see LED on
        bsf        LED                    ;Turn off LED
        movlw    0xFF                
        call    Delay                ;Run Delay so you can see LED off

        goto     My_loop                ;keep the program running!
        end
See if this works for you, if not.... you might have a bad PIC!!
 

Thread Starter

vane

Joined Feb 28, 2007
189
Does the value of the capacitor matter? my dad doesn't have a load of capacitors, i nicked a 100uF from college and thats kinda the only cap i have :p can you get selection packs of capacitors?
 

Markd77

Joined Sep 7, 2009
2,806
Looks like your capacitor is too big. Look for ceramic disc capacitors - they are typically availabe in these capacitances.
I found this in:
Table 31-1 in Mid-Range MCU Family Reference Manual
CEXT REXT
Average
Fosc @ 5V, 25°C
22 pF
5k 4.12 MHz ± 1.4%
10k 2.35 MHz ± 1.4%
100k 268 kHz ± 1.1%
100 pF
3.3k 1.80 MHz ± 1.0%
5k 1.27 MHz ± 1.0%
10k 688 kHz ± 1.2%
100k 77.2 kHz ± 1.0%
300 pF
3.3k 707 kHz ± 1.4%
5k 501 kHz ± 1.2%
10k 269 kHz ± 1.6%
100k 28.3 kHz ± 1.1%
The percentage variation indicated here is part to part variation due to normal process distribution.
The variation indicated is ±3 standard deviation from average value for VDD = 5V.
 

Thread Starter

vane

Joined Feb 28, 2007
189
Bmorse, don't suppose you could send a premade Hex could you? when i try and compile it, it comes up with 27 errors :s
 

Thread Starter

vane

Joined Feb 28, 2007
189
Electronics is stupid :( in all my experimenting i have only had one success and i didn't even do the coding :(
 

THE_RB

Joined Feb 11, 2008
5,438
This is about as simple as your LED blinky code is going to get;
(my apologies to Mr BMorse who's code I just butchered :))

Rich (BB code):
;********************************************************
; Brutally simplified 16F84A BLINKY LED code
; blinks LED at approx 7 Hz
;********************************************************
    list    p=16f84A
    include "p16f84A.inc"
    ERRORLEVEL    -224,-302,-305    ;supress compiler errors
    __FUSES _CP_OFF & _WDT_ON & _RC_OSC & _PWRTE_OFF 

;----------------------------------------------

Port_init

	BANKSEL TRISA		;

        movlw b'00000000'	; PORTA All Outputs
        movwf TRISA		;

        movlw b'00000111'	; TMR0 = 1:256 prescaler
        movwf OPTION_REG	;

        BANKSEL PORTA		;
	clrf PORTA		; Init PORTA

Blinky_LED

	btfss INTCON,2		; wait for TMR0 overflow flag
	goto $-1		;
	clrf INTCON		; (this is a 64mS delay)

	movlw b'11111111'	; toggle all PORTA pins
	xorwf PORTA,f

	goto Blinky_LED		; keep blinkin'	

end
 
Top