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.
Yes . Done .

Compile sucess with MPLAB 8.66.

Thank you so much Allen and Ian Rogger.

Reguards Manoj
 
Last edited:
Ohhh... Allen, Just take a look these..

Its going to more complicate...ohh... its working 60%.....

I try to understand to you, what I really needs..
 
njbcBQ

Allen,

https://ibb.co/njbcBQ


this is actually I want....



Reguards Manoj
 

Attachments

  • 1.bmp
    1.3 MB · Views: 184
Today is Saturday. I have to go to airport to pick my daughter. Have lunch and go to a computer fair.:(

To most US and UK members, weekend is the time for enjoyment and not using computers for work.:D

May be tonight when I find some time when every one goes to sleep.:cool:

Allen
 
Last edited:
Allen, I am talking to you. I think Ian mad on me...:nailbiting:

do you compile Ian last source? Do you get the hex file?
No... I just live in the 21st century!!!

As Allen said.... In ( "Ye Olde" Hitec land ), you must use slightly different definitions.. I am not installing outdated compilers just to get you up and running...
 
Implementing this

1.PNG

Modify Ian's C program on the while(1) loop...

C:
void main(void)
   {
   TRISIO =0x1;
   GPIO = 0x0;
   ANSEL = 0;
   IOCB = 0;
   WPU = 0;
   CMCON = 0x7;
   initchip();
   while(1)
      {
        {
        while (GPIO0 != 1)
          {__delay_ms(50);
         GPIO1 = 0;    // LED off   
          }
       }
            if (GPIO0 == 1)
                  while (GPIO0)
                  {__delay_ms(50);
                GPIO1 = 0;    // LED STILL off   
                  }
            if (GPIO0 == 0)
           {
              TMR1IE = 1;    // enable TMR1
            while (TMR1IE)
                  {
                    for (Count=0; Count<10; Count++)
                    {
                        __delay_ms(500);    // delay for flash
                        GPIO1 = 1;
                        __delay_ms(500);    // delay for flash
                        GPIO1 = 0;
                    }
                }
              }
        }
    }

Hex file attached..

Allen
 

Attachments

  • ian_code.hex
    874 bytes · Views: 158
I'm using Hitech C.

Here's the complete file attached.

Allen
 

Attachments

  • Ian's code.c
    1.3 KB · Views: 185
Here's the working asm file modified from your original led.asm in post #5.

Code:
; original File = J:\pic disassembler\picdisasm106\led.hex

    processor 12F675
    #include <P12F675.INC>
    __config 0x3194
;   _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF 
;   & _INTRC_OSC_NOCLKOUT 

; 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
temp     equ 0x2A     ;general purpose
LRAM_0x50 equ 0x50
CBD1      equ 0x5C    ;contact bounce delay 1
CBD2      equ 0x5D    ;contact bounce delay 2
LRAM_0x5F equ 0x5F

; Program

    Org 0x0000

;   Reset-Vector
    GOTO MAIN

    Org 0x0004

;   Interrupt-Vector
    MOVWF LRAM_0x5F
    SWAPF STATUS,W
    CLRF STATUS
    MOVWF LRAM_0x24
    MOVF PCLATH,W        ; !!Bank Program-Page-Select
    MOVWF LRAM_0x25
    CLRF PCLATH          ; !!Bank Program-Page-Select
    MOVF LRAM_0x50,W
    MOVWF LRAM_0x20        ; set (0x20) = (0x50)
    BTFSS PIR1,0         ; Is TMR1IF on?
    GOTO LADR_0x001E    ; No.
    BCF PIR1,0           ; Yes, turn TMR1IF off
    INCF ISRCOUNT,F        ; increment counter
    MOVF ISRCOUNT,W
    XORLW 0x0A           ; counter = 10? (old=10)
    BTFSS STATUS,Z
    GOTO LADR_0x001A     ; No
    CLRF ISRCOUNT        ; clear counter to 0 
    BSF STATUS,RP0       ; select bank 1
    BCF PIR1,0           ; turn TMR1IF off
    BCF STATUS,RP0       ; select bank 0
    BCF GPIO,1           ; switch off LED
LADR_0x001A            ;  reload back TMR1 values.  every 248mS or 4Hz
    MOVLW 0x0B           ;   b'00001011'  d'011'
    MOVWF TMR1H          ; !!Bank!! TMR1H - Unimplemented
    MOVLW 0xDB           ;   b'11011011'  d'219'
    MOVWF TMR1L          ; !!Bank!! TMR1L - PCON
LADR_0x001E
    MOVF LRAM_0x20,W    ; move (0x20) to (0x50)
    MOVWF LRAM_0x50
    MOVF LRAM_0x25,W    ; pclath = (0x25)
    MOVWF PCLATH         ; !!Bank Program-Page-Select,
    SWAPF LRAM_0x24,W    ;
    MOVWF STATUS        ;
    SWAPF LRAM_0x5F,F    ;
    SWAPF LRAM_0x5F,W    ;
    RETFIE
LADR_0x0027
    BCF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    MOVF LRAM_0x23,W
    MOVWF PCLATH         ; !!Bank Program-Page-Select
    MOVF LRAM_0x22,W
    MOVWF PCL            ; !!Program-Counter-Modification
    RETURN
LADR_0x002D
    CALL LADR_0x0027
    BCF PCLATH,3         ; !!Bank Program-Page-Select
    BCF PCLATH,4         ; !!Bank Program-Page-Select
    MOVWF INDF
    INCF FSR,F
    INCF LRAM_0x22,F
    BTFSC STATUS,Z
    INCF LRAM_0x23,F
    DECF LRAM_0x50,F
    BTFSS STATUS,Z
    GOTO LADR_0x002D
    RETURN
ISR_init                ; 0x0039 setup timer1 and ebable interrupt
    MOVLW 0x35           ;   b'00110101'  d'053'  "5"
    BCF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    MOVWF T1CON          ; prescaler = 1:8, timer1 enabled
    BCF PIR1,0           ; clear tmr1 flag
    MOVLW 0x0B           ;   b'00001011'  d'011' set timer1 = 248mS
    MOVWF TMR1H          ; !!Bank!! TMR1H - Unimplemented
    MOVLW 0xDB           ;   b'11011011'  d'219'
    MOVWF TMR1L          ; !!Bank!! TMR1L - PCON
    BSF STATUS,RP0       ; select bank 1
    BCF PIR1,0           ; clear tmr1 flag
    MOVLW 0xC0           ;   b'11000000'  d'192'
    MOVWF INTCON        ; enable interrupt GIE=1, PEIE=1
    RETURN
MAIN
    BCF STATUS,RP0       ; select Bank 0
    CLRF ISRCOUNT
    CLRF LRAM_0x26
    MOVLW 0x01           ; W = b'00000001'
    BSF STATUS,RP0       ; select Bank 1
    MOVWF GPIO           ; set gp0 as input, gp1 as output
    CLRF ADCON0          ; ADC is disabled
    MOVLW 0x02           ; W = b'00000010'
    BCF STATUS,RP0       ; select Bank 0
;   MOVWF GPIO           ; switch on LED..  "insert call BLINK5T here"
    CALL  BLINK5T        ; Blink LED 5 times
    BSF STATUS,RP0       ; select Bank 1
    CLRF IOCB            ; !!Bank!! Unimplemented - IOCB
    CLRF WPU             ; !!Bank!! Unimplemented - WPU
    MOVLW 0x07           ; W = b'00000111'  d'007'
    BCF STATUS,RP0       ; select Bank 0
    MOVWF CMCON          ; CMCOM=7 all ports digital
    CALL ISR_init        ; setup timer1 and enable interrupt
SW_SCAN
    BCF STATUS,RP0       ; select Bank 0
    BTFSS GPIO,0         ; Is SW1 ON?
    GOTO LADR_0x0073    ; No
    MOVF LRAM_0x26,W    ; SW1 previous state
    XORLW 0x00           ; 
    BTFSS STATUS,Z        ; Is SW1 released?
    GOTO LADR_0x0073    ; No
    MOVLW 0x41           ;   b'01000001'  d'065'  "A"
    MOVWF CBD1
    MOVLW 0xEE           ;   b'11101110'  d'238'
    MOVWF CBD2
LADR_0x0062
    DECFSZ CBD2,F
    GOTO LADR_0x0062
    DECFSZ CBD1,F
    GOTO LADR_0x0062
    NOP
    BTFSS GPIO,0         ; SW1 ON?
    GOTO LADR_0x0072    ; No
    MOVF LRAM_0x26,W    ; Yes,
    XORLW 0x00           ; LAST_STATE=0?
    BTFSS STATUS,Z
    GOTO LADR_0x0072
    BCF GPIO,1           ; switch off LED
    MOVLW 0x01           ;   b'00000001'  d'001'
    MOVWF LRAM_0x26
    BSF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    BCF PIR1,0           ; !!Bank!! PIR1 - PIE1
LADR_0x0072
    GOTO LADR_0x008D
LADR_0x0073                ; SW1 still ON
    BCF STATUS,RP0       ; !!Bank Register-Bank(0/1)-Select
    BTFSC GPIO,0         ; SW1 released?
    GOTO LADR_0x008D    ; No
    MOVF LRAM_0x26,W    ; Yes, update SW1 previous state. 
    XORLW 0x01           ; 
    BTFSS STATUS,Z        ; Was SW1 still ON?
    GOTO LADR_0x008D    ; No
    MOVLW 0x41           ; Yes, load 0x5c & 0x5d with #0x41EE
    MOVWF CBD1
    MOVLW 0xEE           ;   b'11101110'  d'238'
    MOVWF CBD2
LADR_0x007E
    DECFSZ CBD2,F    ; delay for ??? mS
    GOTO LADR_0x007E
    DECFSZ CBD1,F
    GOTO LADR_0x007E
    NOP
    BTFSC GPIO,0         ; Is SW1 OFF?
    GOTO LADR_0x008D    ; No
    MOVF LRAM_0x26,W    ; Yes, 
    XORLW 0x01           ; SW1 old_state=1?
    BTFSS STATUS,Z
    GOTO LADR_0x008D    ; Yes, back to main loop
;    BSF GPIO,1           ; No, switch ON LED
    call BLINK5T
    CLRF LRAM_0x26
    BSF STATUS,RP0       ; select bank 1
    BSF PIR1,0           ; set TMR1IF
LADR_0x008D
    GOTO SW_SCAN
LADR_0x008E                ; ERROR condition
    GOTO LADR_0x008E

BLINK5T
    movlw    5
    movwf     temp
B5TLOOP
    call    BLINK
    decfsz    temp,1
    goto    B5TLOOP
    return
   
;BLINK 0.5S ON 0.5S OFF
BLINK
    BSF     GPIO,1           ; switch on LED
    call    DELAY_500MS
    BCF        GPIO,1            ; switch off LED
    call    DELAY_500MS
    return
   
;PIC Time Delay = 0.5000020 s with Osc = 4.000000 MHz
DELAY_500MS
    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
    return

    End

Allen
 
Allen, the last statement is not working..

whenever GPo=1 then GP1=0

this statement is not working...

will contact you latter


reguards
 
Allen,

Initial condition is also not done...

Initial condition is LED OFF.. But you last code, It is blinking the LED when POWER ON the system.

Reguards Manoj Soorya
 
Both Ian's code.hex and the hex file assembled from the led.asm worked in my proteus exactly as in your table.

But I didn't test it on the real 12f675. Since both the C and ASM files are there, I think it's good opportunity for you to learn how to modify them to work as your need. I did add a lot of comments in the ASM file if you care to read it again carefully.

Allen
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top