pic 16F684

Discussion in 'Programmer's Corner' started by rp216, Apr 9, 2013.

  1. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    hey guys!

    i would like some help in my programming as i have been newly introduced to it.

    well, my project is about LED DIMMING using pic 16F684

    i have to program to show the following:
    1) demonstration of PWM for brightness control
    2) demonstration of PWM for flashing control
    3) demonstration of ADC for single channel
    4) demonstration of ADC for two channels
    5) pic control of high power LED
    6) use of interrupts

    i have already build a simple hardware circuit to start with. please guide me further with programming as its my first time.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    The first think to do is write a program to make an LED flash.
     
  3. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    thanks - i think i will take a few days to write down this program as i have to learn the basics.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    Is this a school project? It sure sounds like one (not that there's anything wrong with that).

    Get ready to post your schematic as we will need to see that as well.

    Good luck and welcome to the forums.
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Looking up samples of what you are trying will help you tremendously, just make sure they are the same compiler you are using. Always program a device with the datasheet readily available and read the thing if/when you get stuck. In fact, read it anyway, that how you know what to do when attempting something.

    What language are you going to be programming in?
     
  6. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    @ ERNIEM - ya its a college program. i am not in the field of electronics but i had an optional subject so had to pursue it - i will upload the schematic soon

    @ tshuck- i was reading the data sheet but its too long. i tend to get confused - anyways thanks for the advice- its in assembly language
     
  7. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    how do i attach a scanned image or a picture here? the text box shows only " insert url " option. please help me out!
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Attach the image, then, you can insert the image into the body of the post with the "Insert Image" button, after getting the attached image's URL.
     
  9. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    the pic attached is the circuit diagram- abit messy though!
     
  10. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You have to click the [Go Advanced] button and then click the paperclip icon.
    <ed> OK, you figured it out while I was typing. </ed>
     
  11. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    No problem. Let me redraw it for you.

    Does it look right? Vcc is 5V anyway.

    Allen
     
  12. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Please tell us if you are using assembler or C and if C which compiler.
    I'd suggest:
    Find a good code template for your PIC.
    Get an LED to turn on on a normal pin as a test that everything is connected properly.
    Read the datasheet and look at example code for hardware PWM, ADC and interrupts.
    Add features one at a time and test.
    Learn to use the simulator.
    If anything isn't working as expected, post code and explanation of the problem.
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    The schematic looks very good. If I were you I would get the software working in little stages:

    get LED to light
    get LED to blink
    get LED to blink at defined rates for on and off
    get analog to digital readings and use in previous blink (so you can SEE the analog conversion readings)

    Now you have the pieces to make the final app. Of course, you may skip some steps if you have an in-circuit debugger (a PICkit works) and ain't afraid to use it.

    BTW: if you short all 3 terminals of J1 then LEDs will alternately blink:
    RC5 low turn on D1
    RC5 high turn on Q1 & D2
     
  14. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    OP is using assembly, see post # 6.

    OP: I will second what both Ernie and Mark have said, except looking at someone else's assembly can be pretty daunting, if you do it, make sure you understand what the code is attempting to do and how it's done.
     
  15. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    @ allen- yeah thanks for re drawing the circuit diagram- its 5v.

    thanks guys- i think once i figure out the way to write the program of turning the LED i will paste it here. its already took me a day to figure out the ports and reading the data sheet
     
  16. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    It's quite normal to start slow, at least for me. But once you get the hang of it, you will move on fast. It's just a hurdle you have to get over.

    Did you have the breadboard and programmer ready or are you just doing it on a simulator like multisim or proteus?

    Allen
     
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    There's nothing wrong with that!

    You may want to find a tutorial online about how to use the microcontroller.
    I liked this tutorial while learning PICs. It uses a different model, but the basics are there, and explained rather well...
     
  18. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    @ tshuck - thanks for the tutorial guide- will have a look at it.

    @ allen- i have already built the circuit on a copper board and now using the software " MPLAB IDE v8.70" for programming in assembly.
     
  19. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Yes, I also strongly recommend the Nigel's tutorial site. I started learning PIC from it and and I've made almost all the boards for that tutorial too.

    I'll show some of them when I am free to take photos for them.

    Allen
     
  20. rp216

    Thread Starter New Member

    Apr 5, 2013
    20
    0
    hello guys..i am now stuck after the following-

    #INCLUDE <P16f684.INC>
    __config _MCLRE_ON & _PWRTE_OFF & _WDT_OFF & _INTOSC & _CPD_OFF & _IESO_OFF & _CP_OFF & _BOD_OFF & _FCMEN_OFF

    ; ORG 0x000 ; processor reset

    Initialise
    bcf STATUS, RP0 ; activate BANK 0
    clrf PORTA ; initialize PORT A
    clrf PORTC ; initialize PORT C
    movlw 0x07
    movwf CMCON0 ; comparators OFF
    bsf STATUS, RP0 ; change to BANK 1


    how will i make my LED ON? should i create a delay?
    and there is an instruction called Banksel? i dont know how to use it...please help me out!
     
Loading...