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.

PIC12F675 external interrupt code

Status
Not open for further replies.
I have this timer and It can be used as kitchen timer. It need to a good switching and Buzzer. I try to make one with 12F675. Its so simple in mecanical side...more complicated in software side (for me)....
 

Attachments

  • Washing-machine-mechanical-timer-for-5-minutes.jpg
    Washing-machine-mechanical-timer-for-5-minutes.jpg
    72.1 KB · Views: 187
Yes Boss.. The resistor connection is wrong. But I change the conection.

I cant complie your programme in MPLAB v8.33. showing some more error.

Reguards Manoj

If you must use the old MPLAB v8.30 with Hitech C, I have just change a little bit in Ian's C program and it compiles fine.

C:
#include <htc.h>
//#include <pic.h>
#define _XTAL_FREQ  4000000       // Xtal speed
//#pragma config CONFIG = 0x3194   //
__CONFIG  (0x3194);   //

char ISRcount=0;

void interrupt ISR()
   {
   if(TMR1IF)
       {
       if(ISRcount++ == 0x14) // A for 5 seconds
           {
           GPIO = 0;
           ISRcount = 0;
           TMR1IE = 0;
           }
       TMR1H = 0xB;
       TMR1L = 0xDB;
       TMR1IF = 0;
       }
   }

void initchip()
   {
   T1CON = 0x35;
   TMR1IE = 0;
   TMR1H = 0xB;
   TMR1L = 0xDB;
   TMR1IE = 0;
   GIE = PEIE = 1;
   }

void main(void)
   {
     TRISIO =0x1;
   GPIO = 0x0;
   ANSEL = 0;
   IOCB = 0;
   WPU = 0;
   CMCON = 0x7;
   initchip();
   while(1)
       {
       if(GPIO0)
           {
           GPIO1 = 1;
           TMR1IE = 1;
           }
       }
   }

Allen
 
In Allen Code, How I set output 5 seconds to 5 blinks?

I use this ;-

delay_1s:
MOVLW d'5'
MOVWF LRAM_0x21
LOOP1: DECFSZ LRAM_0x21,W
GOTO LOOP1
RETURN

and a Call function added

CALL delay_1s

Is right? proteus not working..

No, I doubt you can do that. That variable LRAM_0x21 is used to count the number of interrupt that occurs every 250mS. In Ian's code it is called ISRcount.

In LOOP1, you can never decrement it to zero as it is incrementing by one every 250mS.

If you want to make use of that counter you have to understand how the program works. And that would take a bit of time to study. An easier way is to do a time waster loop of 0.5S on and 0.5S off using delay loops.

Code:
;PIC Time Delay = 0.5000020 s with Osc = 4.000000 MHz
    movlw    D'3'
    movwf    CounterC
    movlw    D'140'
    movwf    CounterB
    movlw    D'83'
    movwf    CounterA
loop    decfsz    CounterA,1
    goto    loop
    decfsz    CounterB,1
    goto    loop
    decfsz    CounterC,1
    goto    loop
    retlw

So you have to create 3 new vars after LRAM_0x26 like this...

Code:
; RAM-Variable
LRAM_0x20 equ 0x20
ISRCOUNT  equ 0x21    ;count number of interrupt
LRAM_0x22 equ 0x22
LRAM_0x23 equ 0x23
LRAM_0x24 equ 0x24
LRAM_0x25 equ 0x25
LRAM_0x26 equ 0x26
CounterA  equ 0x27
CounterB  equ 0x28
CounterC  equ 0x29
LRAM_0x50 equ 0x50
LRAM_0x5C equ 0x5C
LRAM_0x5D equ 0x5D
LRAM_0x5F equ 0x5F

So, do you have the idea of how to do it?

Allen
 
Last edited:
OK.. Now compilation fine in Ian C Programme.

I think I can learn the C to understand the code... asm is too difficult.


I am trying 5 seconds to 5 Blinks... Is it can done in Ian C programme?
 
I am trying 5 seconds to 5 Blinks... Is it can done in Ian C programme?

ISRcount controls the delay 0xA = 5(ish) seconds 0x14 = 10 (ish) seconds

What!! You want the LED to blink.. Okay... Press the button LED comes on... Then what??
 
I really don't understand what you want.... When do you want it to blink???

If you mean you want the LED to flash when its on for 10 seconds then you need to do this..

C:
#include <htc.h>
//#include <pic.h>
#define _XTAL_FREQ  4000000       // Xtal speed
//#pragma config CONFIG = 0x3194   //
__CONFIG  (0x3194);   //

char ISRcount=0;

void interrupt ISR()
   {
   if(TMR1IF)
       {
       if(ISRcount++ == 0x14) // A for 5 seconds
           {
           GPIO = 0;
           ISRcount = 0;
           TMR1IE = 0;
           }
       TMR1H = 0xB;
       TMR1L = 0xDB;
       TMR1IF = 0;
       }
   }

void initchip()
   {
   T1CON = 0x35;
   TMR1IE = 0;
   TMR1H = 0xB;
   TMR1L = 0xDB;
   TMR1IE = 0;
   GIE = PEIE = 1;
   }

void main(void)
   {
     TRISIO =0x1;
   GPIO = 0x0;
   ANSEL = 0;
   IOCB = 0;
   WPU = 0;
   CMCON = 0x7;
   initchip();
   
while(1)
       {
       if(GP0)
           {
           TMR1IE = 1;
           while(TMR1IE)
               {
               __delay_ms(200);  // delay for flash
               GP1 = 1;
               __delay_ms(200); //  delay for flash
               GP1 = 0;
               }
           }
       }

   }
 
I got Error while compile...


47.4 undefined identifier "GP0"
53.1 undefined identifier "GP1"


is it GPI0 and GPI1?

Reguards Manoj
 
Last edited:
Okey I installed MPLAB 8.30 and compile..

Again got Error..

52. delay exceeds maximum limit of 197120 cycles
54. delay exceeds maximum limit of 197120 cycles


I need to install MPLAB XC8 insted of MPLAB 8.30 ?
 
Did you install HiTech C to work with MPLab 8.40?
If not, it is better to just use MPLAB X.

Allen
 
can you provide Ian last code hex... I try many times.. But not sucess.....


Code (c):

#include <htc.h>
//#include <pic.h>
#define _XTAL_FREQ 4000000 // Xtal speed
//#pragma config CONFIG = 0x3194 //
__CONFIG (0x3194); //

char ISRcount=0;

void interrupt ISR()
{
if(TMR1IF)
{
if(ISRcount++ == 0x14) // A for 5 seconds
{
GPIO = 0;
ISRcount = 0;
TMR1IE = 0;
}
TMR1H = 0xB;
TMR1L = 0xDB;
TMR1IF = 0;
}
}

void initchip()
{
T1CON = 0x35;
TMR1IE = 0;
TMR1H = 0xB;
TMR1L = 0xDB;
TMR1IE = 0;
GIE = PEIE = 1;
}

void main(void)
{
TRISIO =0x1;
GPIO = 0x0;
ANSEL = 0;
IOCB = 0;
WPU = 0;
CMCON = 0x7;
initchip();

while(1)
{
if(GP0)
{
TMR1IE = 1;
while(TMR1IE)
{
__delay_ms(200); // delay for flash
GP1 = 1;
__delay_ms(200); // delay for flash
GP1 = 0;
}
}
}

}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top