Hetal said:well but its funny tht was a simple code and all this while i was trying al the hard stuff..
aneways i guess this way i learnt how to .. do a/d conversion and timer interrupts.. soo a quick question though .. when is the actual need for an interrupt can u give me a good example..
thnks a lot for the time and effort u took to help me for the code.... really appreciated.. now i feel from a person who knew nothing about the assembly language seems to .. understand
The only one of my tutorials that uses them is the seven segment tutorial, where I use a timer interrupt to multiplex the display.
Multiplexing requires you to display each digit in turn (in this case there's just two of them), and requires the same amount of time for each - or you can see the brightness difference between the digits.
So in the tutorial the interrupt routine is called at specific accurate intervals, the first time it's called it displays one digit, the next time it displays the other digit, this ensures exactly equal timing for each digit - it could easily be extended to drive more digits if required.
So the timer interrupt is doing the multiplexing, all we need to do in the main program is transfer the number we want to display to the correct variable, in this case 'Ones' and 'Tens'.
The main program code looks like this:
Code:
Main
call Delay255
call Delay255
call Delay255
call Delay255
incf ones, f
movf ones, w ;test first digit
sublw 0x0A
btfss STATUS, Z
goto Main
clrf ones
incf tens, f
movf tens, w ;test second digit
sublw 0x0A
btfss STATUS, Z
goto Main
clrf tens
goto Main ;loop for ever
It simply counts from 0 to 99, and loops back to zero. Notice that in the entire routine there's no mention of ports or displays or anything - it's simply incrementing a two digit decimal counter consisting of two GPR's.
Everything else is done by the interrupt routine, from the main routine point of view you don't even need to know it exists, it's completely transparent.
Another classic example is a real time clock, using timer interrupts the clock can run even while you're doing something else!.