1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to start PIC16F676 ...??

Discussion in 'Microcontrollers' started by koolguy, Feb 17, 2012.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Flashing approximately 90 times a second...

    You dont need the 5k pullup..... inr MCLR is internal.

    Eric changed the timings for simulation.... there is only 7mS delay.
     
    Last edited: Mar 14, 2012
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    As i said i have changed it value to have more delay!!
    please tell what does this .2 significance is that decimal no??
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Look at my Post #33 for the original 0.5Second delay times... .2 is decimal '2'
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    OK, now my latest code which are working fine in oshon....

    LIST p=16F676 ;tell assembler what chip we are using
    include "P16F676.inc" ;include the defaults for the chip
    __config 0x3D14 ;sets the configuration settings (oscillator type etc.)

    errorlevel -302, -207

    CounterA equ 0x20
    CounterB equ 0x21
    CounterC equ 0x22
    CounterD equ 0x23

    ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
    ORG 0
    GOTO INIT

    INIT
    bcf STATUS,RP0
    clrf PORTA
    MOVLW 0x05
    MOVWF CMCON

    BSF STATUS,RP0
    clrf ANSEL ; disable ADC

    movlw 0x0c
    MOVWF TRISA ; porta as inp

    clrf TRISC ; portc as out
    BCF STATUS,RP0

    START
    call delay
    movlw 0xff
    movwf PORTC
    call delay
    clrf PORTC
    GOTO START

    ;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
    delay: movlw D'3'
    movwf CounterC
    movlw D'138'
    movwf CounterB
    movlw D'85'
    movwf CounterA
    loop decfsz CounterA,1
    goto loop
    decfsz CounterB,1
    goto loop
    decfsz CounterC,1
    goto loop
    retlw 0

    end
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Ritesh,
    Its important to note that while the Delay periods are counting the PIC is 'tied up' doing just that.

    If you want to experiment, consider using the PIC's internal counters to create Interrupts for these delays, it will leave the PIC free to do other tasks.
     
    • Like Like x 1
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Perfect.. 500ms of 500ms on... Remember as well Ritesh! If you use internal 4mhz crystal to load the OSCCAL value ( last location of program memory ).
     
    • Like Like x 1
  8. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi, the pic is working fine on board i find it easy then chip used before !!
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Why which one did you use?
     
  10. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I mean to say chip like counters, astable vibrator now no tension of changing the chip, only code!
     
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    After running LED program successfully i want to make a analog to digital program..please guide me how to do this??
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Hi Ritesh....More specific? analogue to digital what?
     
    • Like Like x 1
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    As i want to make PWM for this we will require to read R from pot. meter!!
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Select a pic... You'll need a CCP module (PWM output) and an ADC input...

    The smallest of these is the 8 pin pic12f1822 / 40 You can set up the 10 bit ADC to supply a 10 bit PWM signal. so input on pin 7 and output on pin 5.

    You can do this very easy in Oshonsoft (I know you use this)


    Oh sorry....... Not in Oshonsoft .... chip not supported. on of the pics will be though.
     
    Last edited: Mar 25, 2012
    • Like Like x 1
  15. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,329
    Likes:
    653
    Location:
    Derbyshire, UK
    Sorry, but you don't require an ADC - you can easily read a variable resistor on a standard pin, check my joystick tutorial!.

    In many ways it's BETTER than an ADC for reading a pot.
     
    • Like Like x 1
  16. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I want to try it with PIC16F676
     
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK

    Ah... We used to do that for PC joysticks..... Simple AtoD but wasn't particularly linear.


    Ritesh.. That chip hasn't got a PWM module so you'll have to make a software one.
     
    Last edited: Mar 25, 2012
    • Like Like x 1
  18. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    No problem, please tell the procedure.
     
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    as it will help me to learn PWM from code!!
     
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I did it yesterday...

    Code (text):

    #include<htc.h>
    #define _XTAL_FREQ  4000000
    __CONFIG(0x31C4);


    int OnPulse = 128, OffPulse = 128;
    char TOG = 0;

    void interrupt ISR(void)
        {
        TOG = ~TOG;
        if(TOG)
            {
            TMR0 = OnPulse;
            RC0 = 1;
            }
        else
            {
            TMR0 = OffPulse;
            RC0 = 0;
            }  
        T0IF = 0;
        }

    int ADC_Read()
        {
        ADCON0 = 1;
        __delay_ms(40);
        GO = 1;
        while(GO);
        return ADRESH;
        }

    void main()
        {
        int pulse;
        TRISC = 0;
        TRISA = 255;
        CMCON = 7;
        TMR0 = OnPulse;
        ADCON0 = 0x0;
        ADCON1 = 0x50;
        ANSEL = 0x1;
        OPTION_REG = 0;
        T0IE = 1;
        GIE = 1;
        while(1)
            {
            pulse = ADC_Read();
            OnPulse = pulse;
            OffPulse = 255 - OnPulse;      
            }

        }
     
    8bit PWM at 2khz
     
    • Like Like x 1
  21. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Can't we do this in assembly??
    and please explain this..
     

Share This Page