Continue to Site

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.

  • 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.

12F675

Status
Not open for further replies.

rthuey

Member
I was able to program a 12F675 with this;

C:
/*Configuration Bits - not set in code
BG1:BG0 (Bandgap Calibration Bits for BOD and POR voltage)= DEFAULT
FOSC2:FOSC0 (Oscillator selection Bits) = 100
INTOSC oscillator:        I/O function on GP4/OSC2/CLKOUT pin,
                          I/O function on GP5/OSC1/CLKIN
WDTE - Watchdog Timer Enable bit - WDT disabled
PWRTE - Power-up Timer bit - PWRT disabled
MCLRE - GP3/MCLR pin function select - GP3/MCLR pin function is MCLR
BOREN - Brown-out detect Enable bit - BOD disabled
CP - Code Protection bit - Program Memory code protection is disabled
CPD - Data Code Protection bit - Data memory code protection is disabled
*/

// Header Files
#include <xc.h>        //Header file for libpicio (pic_read, pic_write, ...)

#define Sys_tick_counter 8 //Timer1 interrupt count to make a half second flag
#define Button GPIO2
#define Output GPIO5

//Variables
unsigned int Sys_tick=0; //timer1 overflow/interrupt count value
unsigned int Count=0; //timer1 overflow/interrupt count value

// Functions in the program
void Init (void);

//  Function:        Sets up the PIC12F675 I/O ports functionality
void Init (void)
{
    VRCON=0x00;         //Disable voltage reference
    CMCON=0b00000111;         //Disable comparator
    ANSEL=0x00;            //A/D disabled
    GPIO=0;             //Clear GPIO
    TRISIO=0b00011111;        //Set  AND GPIO5 as outputs and GPIO0, GPIO1, GPIO2, GPI03 and GPIO4 as inputs
    WPU=0;             //Disable all weak pull up
    T1CON = 0b00000100;         //Timer1 setup
    PIE1 = 0b0000001;           //Timer1 interrupt enabled
    INTEDG = 1;                 //Interrupt set on rising edge
    INTCON=0b11010000;        //Global Interrupt Enabled and interrupt-on-change Enabled
    TMR1ON=1;                   //Timer1 ON
}

// Interrupt Sub Routine
void interrupt isr(void)
{
    if((INTE==1) && (INTF==1)) //If interrupt-on-change Enable bit and GPIF: interrupt-on-change Flag bit equal 1, interrupt.
    {
        INTF = 0;
        INTE = 0;
        if (Count < 46)
        {
            Count += 5;
        }
//        SLEEP();
//        NOP();
    }

    if((TMR1IE) && (TMR1IF)) //If TMR1 Overflow Interrupt Enable bit and TMR1IF: TMR1 Overflow Interrupt Flag bit equal 1, interrupt.
    { // every 65,5ms
        TMR1IF = 0;
        Sys_tick++;
        if (Sys_tick >= Sys_tick_counter)
        {
            INTE = 1;
            Sys_tick=0;
            if (Count)
            {
                Count--;
            }
            if (Count>=25)
            {
                Output = 1;
            }
            else
            {
                Output = 0;
//                SLEEP();
//                NOP();
            }
        }
//        else
//        {
//            if (Count<25)
//            {
//                SLEEP();
//                NOP();
//            }
//        }
    }
}

// Main Program
void main(void)
{
    Init();        //Initialize
//    SLEEP();        //Powerdown Mode ON
//    NOP();
    while(1)
    {
        NOP();
    }
}

Inserted into this circuit it works as advertised. The SQ-SEN-200 is an omni-directional movement detector.

nfic.jpg





I get a blinking light when ever there is movement.


Can the same program on the same chip be used with this circuit from the manufacturer website?

flexic.jpg


I started with a 4.7m on R1 and a 1m on R2. A 10pf on C1. Not sure where to lead in as High_Z on the chip nor do i know where or how to place the LED.
I tried Pin 5 as the High_Z and putting a 510 resistor off of Pin 4 followed by one lead of the LED. With the other lead of the LED going to ground. I was not able to light the LED this way.
 
Last edited by a moderator:
Would you mind putting the code in code tags to preserve the spacing? It makes it much easier to follow. Thanks!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top