Menu

16f84a interrupt

Help
salvo
2011-12-01
2013-05-30
  • salvo

    salvo - 2011-12-01

    hello

    i have a problem with interrupt with chip 16f84a i tried to run the follow procedure with pic simulator

    ;Chip Settings
    #chip 16F84A,4
    #config OSC=XT;

    ;Defines (Constants)
    #define Switch PORTB.4
    #define Led PORTB.1

    ;Variables
    Dim RCsignal As byte;

    ;Interrupt Handlers
    On Interrupt PORTBChange Call measure

    DummyRead = PORTB
    set RBIF off
    InitTimer0 Osc, PS0_1/8
    Dir Switch In
    Dir Led Out
    RCsignal = 0
    Start:
    set led off
    If RCsignal <> 0 Then
    Set Led On
    else
    set led off
    End If
    Goto start

    Sub measure
    Wait Until switch = 1
    ClearTimer 0
    Wait Until switch = 0
    RCsignal = TMR0
    DummyRead = PORTB ' Clear the mismatch
    End Sub

    this was suggested me by nobody but really i cannot understand why won't work
    i tried also another simple routine but nothing

    simple routine :
    ;Chip Settings
    #chip 16F84A,4

    ;Interrupt Handlers
    On Interrupt PORTBChange Call ledon

    Dir PORTB.4 In
    Dir PORTA.1 Out
    start:
    Set PORTA.1 On
    Wait 4 ms
    Set PORTA.1 Off
    Wait 4 ms
    Goto start

    Sub ledon
    Set PORTA.1 On
    End Sub

    can any one help

    many thanks
    salvo

     
  • gcha44

    gcha44 - 2011-12-01

    Hi ,
    In the second sample delays are too short to see any brigthness change of led . Try with wait 500 ms or wait 1 s
    In the first sample you ask waiting switch=1 at each interruptportBchange but if the program calls this sub it's because portB.4 have already toggled .
    GC

     
  • salvo

    salvo - 2011-12-01

    hello gcha44

    in the second sample i can see on the simulator the led flashing but it does not stay on.
    i tryed also to put the oscilloscope and set the simulation speed very slowly, but i cannot see the interrupt
    i didn't try with the real pic circuit because in my garage now the termometer show -1 °C
    so my hand get iced if i start work on my pic programmer so i'm trying with simulator

    if is not disturbing you it is possible to have a sample of interrupt program on this 16f84a?
    just a switch that can generate an interrupt to set an output on just to see if the simulator is working properly
    or gcbasic do some error on compiling

    i tryed any possible sample but with no luck…

    thx for your support
    ciao
    salvo

     
  • gcha44

    gcha44 - 2011-12-02

    Hi,
    The led never stays on because after each interrupt the program returns to the loop .
    Then the led is flashing on and off every  4 mS
    In the sub interrupt  "ledon" you can write      "wait  X s"  after  "set portA.1 on" .   
    X =1 or every value you want

     
  • lhatch

    lhatch - 2011-12-02

    Does this below work??  I would have to look more into the portbchange since you have the in and out both on port B

    #chip 16F84A,4
    On Interrupt PORTBChange Call ledon

    Dir PORTB.4 In           ;Assume a switch
    Dir PORTA.1 Out        ;Assume a LED and on PORTB will not cause interrupt?

    start:
    Set PORTA.1 Off
    Wait 3 s
    Goto start

    Sub ledon
      Set PORTA.1 On
    End Sub

     
  • gcha44

    gcha44 - 2011-12-02

    Hi,
    This code can work but if interrupt occurs just after wait 3 s the program 'll return to start and portA.1 'll reset again instantaneously so you cannot see LED flashing on
    It'll be better to put "Wait 3 s" just after   start:
    On PIC16F84 interrupts occur only on PortB.4 to PortB.7 , so i think your code is correct . You must read PIC16F84A datasheet  , PortB functions Table 5-3 and chapter 5-3
    So you can assume a led on portB.0 to portB.3
    But perhaps have you omitted to write the config OSC  :  "#config OSC=XT" ?
    regards
    GC

     
  • salvo

    salvo - 2011-12-02

    hi to all
    i tryed this under your advice and try to put 3s of delay everywere, but it is so strange nothing happen…
    here the routine

    ;Chip Settings
    #chip 16F84A,4
    #config OSC=XT

    ;Interrupt Handlers
    On Interrupt PORTBChange Call ledon

    Dir PORTB.4 In ;Assume a switch
    Dir PORTA.1 Out ;Assume a LED and on PORTB will not cause interrupt?
    start:
    wait 3 s
    Set PORTA.1 Off
    Wait 3 s
    Goto start

    Sub ledon
    Set PORTA.1 On
    wait 3 s
    End Sub

     
  • Nobody/Anonymous

    Sorry on the OSC, but I just cut and pasted his program.  My gold was the make it where the LED will stay off all the time and on with the switch press (via interrupt) until up to 3 seconds and go back out so they can see the compiler is working.  Or the sim.emulator they are use.

     
  • salvo

    salvo - 2011-12-02

    hello nobody how are you???

    if i understand good i have to program it with the real pic 16f84a?
    you think simulator can have trouble?

    thanks

     
  • Nobody/Anonymous

    Salvo.

    I just modded your code to what I would try first.  What simulator do you use, I will compile it and test it for you.  If you try it add the OSC type..

    Somar

     
  • salvo

    salvo - 2011-12-02

    i use pic simulator

    if you google it you can find it fast
    they allow you to test some progect for 30 day  than you have to buy it
    is very usefull.

    salvo

     
  • gcha44

    gcha44 - 2011-12-02

    Hi , I just tried to simulate jour code with Real Pic Simulator and it works fine .
    Differents times of ON and OFF depend of push- button.
    I tried this code ,slightly modified :

    ;Chip Settings
    #chip 16F84A,4
    #config OSC=XT

    ;Interrupt Handlers
    On Interrupt PORTBChange Call ledon

    Dir PORTB.4 In ;Assume a switch
    Dir PORTA.1 Out ;Assume a LED and on PORTB will not cause interrupt?

    do
    wait 1 s
    Set PORTA.1 Off
    wait 1 s
    loop

    Sub ledon
    Set PORTA.1 On
    End Sub

    GC

     
  • salvo

    salvo - 2011-12-03

    hi

    i tryed your routine with real pic simulator 1.1 but it does not work
    now i'm wondering wich version did you use?

    thx
    salvo

     
  • gcha44

    gcha44 - 2011-12-03

    Hi ,
    I use 1.3.0.0 version . I tried again and the result is OK .
    But you must choose 16F84A device before loading hex file .
    In visual mode you choose button on portB.4 and led on portA.1
    When you push button , led flash on and off . But the delays the led stays on an off are each time different as I explained you before.
    Good luck
    GC

     
  • salvo

    salvo - 2011-12-03

    hi!
    this is what i did….
    16f84a before to select the Hex file;
    push button normally open on port B4 and a led on port a1
    the simulator does not see any interrupt…
    may be the version is too old and need to buy the new one…
    let's try the demo so i can see if it work

    many thanks!
    ciao
    salvo

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.