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

I download a proteus 7.5 .DSN file for a 12F675 Timer. It has one input switch and one LED in the output. I already have the hex code. Not the source code..

My hex file is works like:-

1. Power on the System the LED will ON.
2. When press the switch, LED will OFF.
3. If switch is pressed, The LED will OFF
4. If the switch is relese, The LED will ON for 5 Seconds and turn OFF.

In my needs, only change in the first state. ie, Power on the System the LED will be OFF.


any help would be appriciated.... Thank you so much
 

Attachments

sagor1

Active Member
What pin is the LED on? Which pin is the switch? (cannot read the .DSN file) Not that I can help, but anyone looking at the hex code, and dis-assembling it, needs to look at which pin is being set to turn on the LED on power on...
 

absf

Active Member
This is the schematics extracted from the zip file.

12f675_ETO.PNG

I disassembled the hex file and it was confirmed the source was not written in ASM. It uses timer 1 for the delay and 7 bytes for scratch vars from 0x20 to 0x26.

So I think the best is to follow Max advice and write a new program in C or BAS for the job.

In case someome wants to see the ASM codes, it is attached.

Allen
 

Attachments

Last edited:
Great Effort Sir... Thank you So much.

Is the led.asm is working for my needs?


Its compaile and working same as like the first hex I Supplied. I need to OFF the LED when the circuit power ON.

Thank you so much for the asm file...
 
Last edited:
Done...


This is the original code..


MOVWF GPIO ; !!Bank!! GPIO - TRISIO
CLRF ADCON0 ; !!Bank!! ADCON0 - ANSEL
MOVLW 0x02 ; b'00000010' d'002'



and I change the code like this...

MOVWF GPIO ; !!Bank!! GPIO - TRISIO
CLRF ADCON0 ; !!Bank!! ADCON0 - ANSEL
MOVLW 0x00 ; b'00000000' d'000'


Now its working fine what my needs...... Thank you so much everyone... Especially Allen...
 
I am trying Allen... But time is very important. But I am working in a government sector (Kerala State Electricity Board, India) and I need to spend more time to the field. When I get free time, I am trying to make some hobby electronics work. Its only for my use, Not for sale. In this circuit, I can use it with a mechanical 6 minute timer switch of a washing machine. Normally its OFF position. But we turn the knobe, Its contacts are closed. whenever the knobe return to its normal position, Its again OFF. I need to activate the circuit only when the contact OPEN and its only for 5 Seconds. Now its working Fine.

and one more thing...

how to extend the time or how to set the delay time 5 seconds to 10 seconds?

Which line I need change the .asm file, if I want....?

I know, You can do it....

If not done, I can use BS170, 470uF capacitor and 150K resistor to setup a autopower OFF circuit. Its Okey....

But how to extend the time or how to change the delay time 5 seconds to 10 seconds?

Thank again...
 

absf

Active Member
I have to study first too.

Because an asm program compiled from a C program is very long and difficult to understand. If the program was originally written in ASM and coverted to HEX. It would be much easier to understand after dis-assembled.

You may try also. I think it should be the part involving the Timer1. The timer1 in the program has a counting time of 31 mS...

Code:
LADR_0x001A            ;  every 31mS or 32.25Hz
    MOVLW 0x0B           ;   b'00001011'  d'011'
    MOVWF TMR1H          ; !!Bank!! TMR1H - Unimplemented
    MOVLW 0xDB           ;   b'11011011'  d'219'
    MOVWF TMR1L          ; !!Bank!! TMR1L - PCON
To get 5S or 5000mS, you need to count 31mS 161 times.
ie 31mS x 161 ~= 4.99S

So you have to look for a fiugure around that value in the main loop of the program.

Allen

[update] the timer 1 prescaler was set to 1:8. So a count of 20 interrupt would be enough for 5 seconds.
 
Last edited:

absf

Active Member
Code:
    INCF LRAM_0x21,F
    MOVF LRAM_0x21,W
    XORLW 0x0A           ;   b'00001010'  d'010'
    BTFSS STATUS,Z
    GOTO LADR_0x001A
    CLRF LRAM_0x21
Try changing the instruction "XORLW 0x0A" to "XORLW 0x14" and test it with proteus. See if that would make the LED lights for 10S from 5S.

LRAM_0x21 is used as an interrupt counter, I guess.

Allen
 
Yes... Its working Very fine.... Thank you so much allen.

I am trying to do some programmes...

will share you after I write the code. Please correct me if I make any mistake.

Thank you so much.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
A) That circuit is wrong!!! The button isn't biased one way or the other... the resistor should connect to the pin!!

Best translation I could do....
C:
#include<xc.h>
#define _XTAL_FREQ  4000000       // Xtal speed
#pragma config 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)
           {
           GP1 = 1;
           TMR1IE = 1;
           }
       }
   }
 
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
 
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..
 
This is the part of the code I edit...



Code:
CALL delay_1s
                                                                          ;XORLW 0x0A           ;   b'00001010'  d'010'        
    BTFSS STATUS,Z
    GOTO LADR_0x001A
    CLRF LRAM_0x21
    BSF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    BCF PIR1,0           ; !!Bank!! PIR1 - PIE1
    BCF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    BCF GPIO,1           ; !!Bank!! GPIO - TRISIO

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




[code]


Is it will work?
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top