Need help with PIC Assembly for PIC16F72 Interrupt service routine

jpanhalt

Joined Jan 18, 2008
11,087
Sorry, I missed that comment in post #48. Did you notice that PORTA only has 6 pins/inputs? It also comes up default with pins 0..2 as analog inputs. That creates a separate thing to deal with and is quite common on most of the 16F chips.

How do you plan to use 8 button switches? Multiplexed?
 

Thread Starter

seifullaah73

Joined Dec 13, 2019
51
Oh no.
I was just hoping to go through the checks for each button, but i think I will just do 5 buttons. don't want to make harder then it is.

The code I posted, I will exactly that but do checks for all the buttons I plan to use.
 

jpanhalt

Joined Jan 18, 2008
11,087
You haven't told us what development software you are using. I use MPLab 8.92, and it has MPLAB SIM built in (free download and use). You don't even require a programmer or chip for that. If you have a programmer, such as ICD3 or PicKit2/3 then you can also do hardware simulation.

There is also MPLabX IDE that can be used for Assembly, but I don't use it.
 

Thread Starter

seifullaah73

Joined Dec 13, 2019
51
I use MPLab too don't know version. It has MPLAB SIM built in but when I run that it just says loading it doesn't give much debug info of what is happening and if it is doing what I want it to do such toggle output.

We also use MLoader to load the assembled hex file into the chip via usb.

A good tutorial would be appreciated.

Hardware like pickit are a little expensive. when you need the pic board and the programmer kit.
 

jpanhalt

Joined Jan 18, 2008
11,087
Sorry I can't help you figure out which version of MPLab you have. There are many, many tutorials on the Internet. There is also a big difference between MPLab X and earlier versions. For Assembly, many people find version 8.92 (latest) or earlier preferred.

Have you tried the Help >> About tab?

1576627943817.png
 

Thread Starter

seifullaah73

Joined Dec 13, 2019
51
Yes. Thanks I have version 8.92

Cool videos I found.

So much you can do with sim. I hope there is a stimulus output like LED. will research into it.

According to stopwatch the time it takes between the toggling of the light without the switch is 211ms.
I timed it from XORWF function to next time it reaches same XORWF function. Someone said it took 1 seconds.
 
Last edited:

atferrari

Joined Jan 6, 2004
4,764
Sorry I can't help you figure out which version of MPLab you have. There are many, many tutorials on the Internet. There is also a big difference between MPLab X and earlier versions. For Assembly, many people find version 8.92 (latest) or earlier preferred.

Have you tried the Help >> About tab?

View attachment 194753
John,
I stopped working with PICs (Picstart Plus & MPLAB 8.92 ) some 4 years ago.

As you know I work in Assembly only.

One month ago I restarted with MPLABX 5.25 and Pickit4. It took me few (very) hours for being productive again even with a micro I had never used before.

If not compulsory I do not plan to come back to 8.92.

BTW I find impressive how easily the debugging capability becomes second nature.
 

jpanhalt

Joined Jan 18, 2008
11,087
@atferrari
I actually tried MPLabX early on. It was not friendly. Then I kept hearing comments by other people with the same impression. More recently, I have seen some OK's and examples by a few. Ian Rogers has also said the newer version is much better.

When my current project is done, I will give it another try. MPLab 8.92 has hardware simulation problems with some of the now older chips like 16F1783. And of course, getting the newer chips would be nice.

John
 
Last edited:

atferrari

Joined Jan 6, 2004
4,764
It seems that with the MPLABX, simulation not sure if discouraged but certainly is not encouraged, the typical answer being "do simulation in actual hardware" what, given the good performance of the debugger, does make sense.

The sole actual simulation I did was all my delay routines for a never-used-before clock of 32 MHz. The rest, plain debugging.
 

jpanhalt

Joined Jan 18, 2008
11,087
According to stopwatch the time it takes between the toggling of the light without the switch is 211ms.
I timed it from XORWF function to next time it reaches same XORWF function. Someone said it took 1 seconds.
Hmmm.... I simulated at 4 MHz, which is what you said your crystal was. 20 MHz is 5 x as fast. So, 5 x 211 us is about 1 second.

Seems pretty close. Do you get the point? When I simulate with that stopwatch, I pay more attention to the "cycles" (Tcy) than to the actual time in seconds.
 

Thread Starter

seifullaah73

Joined Dec 13, 2019
51
Hmmm.... I simulated at 4 MHz, which is what you said your crystal was. 20 MHz is 5 x as fast. So, 5 x 211 us is about 1 second.

Seems pretty close. Do you get the point? When I simulate with that stopwatch, I pay more attention to the "cycles" (Tcy) than to the actual time in seconds.
Yes I get it. The instruction cycle stays the same no matter what the frequency.

Now I get more time to play around with it using the debugger till it works for the switch. and just for this one i will use debugging variable to take the value of output pin to see if that turns on or off.

you can also simulate button press but it says port A is connected to A/D converter so it can't simulate that. so will change ports to PortB temporarily then switch over when trying on real board.
 

jpanhalt

Joined Jan 18, 2008
11,087
Yes I get it. The instruction cycle stays the same no matter what the frequency.

Now I get more time to play around with it using the debugger till it works for the switch. and just for this one i will use debugging variable to take the value of output pin to see if that turns on or off.

you can also simulate button press but it says port A is connected to A/D converter so it can't simulate that. so will change ports to PortB temporarily then switch over when trying on real board.
The stimulus package allows lots of options. It can be synchronous, say you want to measure the duty cycle of a square wave, or asynchronous Asynchronous can be by "firing" a pulse (that's the easiest), but it also can be by a text file with timed events. You also have register injection. For chips that are fully supported, the simulation program has left little for me to be desired except for lack of peripherals, like SPI displays. That is why I have been so reluctant to migrate.

You will find chips that are better supported than others, e.g., the 16F1829 is better supported than the 16F1783. That may be because the latter chip has more peripherals. But, if you don't use those peripherals, you can develop code on the chip that is better supported and transport it quite easily -- so long as you stay within the series or move up. Mid-range to enhanced mid-range is easy. The other way around is a little more difficult.

There are programs, I believe Proteus is one, that offer more enhanced simulation. For me, MPLab SIM has been sufficient to work out logic and math, and it is free. When I have something like a display or other plug-in, then I use hardware simulation that is quite a bit more limited, but allows one to see what happens on a display or other plug-in, say one using SPI. Some chips are limited to just one breakpoint. You can leapfrog those, but it is a little inconvenient. I find three breakpoints the most I have ever needed.
 
Top