(Newbie) Problem in lighting a LED with PIC16F84A

Discussion in 'Embedded Systems and Microcontrollers' started by lloydi12345, Aug 22, 2010.

  1. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    Hi, I have a problem on lighting my LED. My PIC's MCLR pin has no connections, VSS is connected to the ground, VDD is connected from my 7808's output which is 4.8v. My PIC's 18th pin (RA1) is connected to my 1k resistor and connected also on a LED in series. The LED's negative polarity is connected to the ground and also the 7808's middle pin is connected to the ground. The PIC's 15th and 16th pin is connected to my 4mhz crystal oscillator and every leg of the oscillator is connected on two 22pF capacitor. The end pin of the two capacitors are connected on the ground. My problem is even just a blink my LED wont light.

    Here's is my source code:

    Code ( (Unknown Language)):
    1. ;**********************************************************************
    2. ;   This file is a basic code template for assembly code generation   *
    3. ;   on the PIC16F84A. This file contains the basic code               *
    4. ;   building blocks to build upon.                                    *  
    5. ;                                                                     *
    6. ;   Refer to the MPASM User's Guide for additional information on     *
    7. ;   features of the assembler (Document DS33014).                     *
    8. ;                                                                     *
    9. ;   Refer to the respective PIC data sheet for additional             *
    10. ;   information on the instruction set.                               *
    11. ;                                                                     *
    12. ;**********************************************************************
    13. ;                                                                     *
    14. ;    Filename:        xxx.asm                                           *
    15. ;    Date:                                                            *
    16. ;    File Version:                                                    *
    17. ;                                                                     *
    18. ;    Author:                                                          *
    19. ;    Company:                                                         *
    20. ;                                                                     *
    21. ;                                                                     *
    22. ;**********************************************************************
    23. ;                                                                     *
    24. ;    Files Required: P16F84A.INC                                      *
    25. ;                                                                     *
    26. ;**********************************************************************
    27. ;                                                                     *
    28. ;    Notes:                                                           *
    29. ;                                                                     *
    30. ;**********************************************************************
    31.  
    32.  
    33.     list      p=16F84A            ; list directive to define processor
    34.     #include <p16F84A.inc>        ; processor specific variable definitions
    35.  
    36.     __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
    37.  
    38. ; '__CONFIG' directive is used to embed configuration data within .asm file.
    39. ; The lables following the directive are located in the respective .inc file.
    40. ; See respective data sheet for additional information on configuration word.
    41.  
    42.  
    43.  
    44.  
    45. ;***** VARIABLE DEFINITIONS
    46. w_temp        EQU     0x0C        ; variable used for context saving
    47. status_temp   EQU     0x0D        ; variable used for context saving
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55.  
    56. ;**********************************************************************
    57.         ORG     0x000             ; processor reset vector
    58.           goto    main              ; go to beginning of program
    59.  
    60.  
    61.         ORG     0x004             ; interrupt vector location
    62.         movwf   w_temp            ; save off current W register contents
    63.         movf    STATUS,w          ; move status register into W register
    64.         movwf    status_temp       ; save off contents of STATUS register
    65.  
    66.  
    67. ; isr code can go here or be located as a call subroutine elsewhere
    68.  
    69.  
    70.         movf    status_temp,w     ; retrieve copy of STATUS register
    71.         movwf    STATUS            ; restore pre-isr STATUS register contents
    72.         swapf   w_temp,f
    73.         swapf   w_temp,w          ; restore pre-isr W register contents
    74.         retfie                    ; return from interrupt
    75.  
    76.  
    77.  
    78. main
    79.  
    80. ; remaining code goes here
    81.  
    82. BSF STATUS, RP0
    83. MOVLW 0X00
    84. MOVWF PORTA
    85.  
    86. BCF STATUS, RP0
    87. MOVLW 0X00
    88. MOVWF PORTA
    89.  
    90. AGAIN
    91.  
    92. MOVLW 0XFF
    93. MOVWF PORTA
    94. MOVLW 0X00
    95. MOVWF PORTA
    96.  
    97. GOTO AGAIN
    98.  
    99.  
    100.  
    101.  
    102.  
    103.  
    104.  
    105.  
    106.  
    107.         END                     ; directive 'end of program'
    108.  
    109.  
    The compilation of the program is success and also programming the PIC from PICPgm Programmer is a success. Still the LED wont light. I hope you can help me. Thank you.
     
    Last edited: Aug 22, 2010
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Most often, a logic input pin left floating will tend to cause oscillations. It should be connected to ground or Vcc through a resistor so the state is established.

    Is this a miskey? A 7808 regulator should output close to 8 VDC. It will require an input about 2 volts larger in order to function properly. But 8 volts is well above the maximum allowable voltage for your PIC. That regulator really has to be a 7805.

    How is the PIC mounted? If it is on a breadboard, the chances of proper operation are close to zero. There is just too much stray capacitance for one to function like that.
     
  3. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    Remember to include the capacitors around the voltage regulator, or you will get an unreliable regulator which will sometimes produce a low output voltage (100n capacitor on the input and 1µF capacitor on the output.)

    If you have been running your PICs at 8V, you have probably damaged them. They usually require 2.0V to 5.5V.
     
  4. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Most PIC range works with 5VDC and as per datasheet 16F84a can have max 7.5 VDC so you applied 8VDC which may have damaged the mcu but the main problem is the power on reset ,connect the MCLR pin with a 10K resistor to positive rail and provide a regulated power of 5VDC ..
    Connecting the MCLR pin to ground will cause reset.

    Good Luck
     
  5. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    thanks for the reply, oh sorry,it was a mistake.. It was really 7805 which outputs 5v.. I also connected the tester not properly, now it outputs 5v. I tried connecting the mclr pin from 5v output of the regulator through a 10k resistor but nothing happens. The LED still wont light :(

    I also changed my first line having PORTA:

    Code ( (Unknown Language)):
    1. MOVLW 0x00
    2. MOVWF TRISA
     
  6. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    Instead of manipulating the bank bits use the banksel macro.

    Here is a program which should light an LED; the LED should never switch off.

    Code ( (Unknown Language)):
    1.  
    2. banksel TRISA
    3. movlw   0xff
    4. movwf   TRISA
    5. banksel PORTA
    6. movwf   PORTA       ; W = 0xff
    7. goto    $
    8.  
    Try this instead of getting it to blink.
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    In the config change to _WDT_OFF and _HS_OSC.
    The led will not look as though it is flashing as it will be over 100000Hz.
     
  8. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    sir I can't make this work on Proteus ISIS
     
  9. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    sir i got it now working on my circuit
     
  10. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    That is good. Is the LED lit? If you have a scope, double check that the chip is not resetting (and the LED going off), and you should be all good to go.
     
Loading...