
Originally Posted by
Kenjones1935
Mackrackit,
From what I understand your code will do a PWM every time TMR0 overflows.
The code in post #73 will toggle a LED when TMRO overflows. The LED on PORTD.7 will gradually become brighter then turn off and start over again.
This was just an example of an interrupt working with something else going on.
You do have to be careful with this as things will sometimes not work as expected. Like they say, the machine will do what it is told, not what you want 
This is the same code as in post #73 with some modifications to demonstrate a "pitfall".
The START loop still has PORTD.7 PWMing the LED with PORTD.0 added to be toggled.
Inside of the interrupt loop the same PWM that is on PORTD.7 is now on PORTD.6.
What do you think will happen?
What does happen?
Code:
'16F887 INT RUPT
'44 PIN DEMO BOARD
@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
INTCON.5 = 1 'ENABLE TMR0 DATA SHEET SECTION 14.3.2
OSCCON = %01110000 '8 Mhz
OPTION_REG = %10000111 ' 1:256 PRESCALE
ON INTERRUPT GOTO TLOOP
CNT VAR BYTE
D VAR BYTE
D = 0
HIGH PORTD.0
PAUSE 500
START:
FOR CNT = 0 TO 150
PWM PORTD.7,D,100
D = D + 2
NEXT CNT
TOGGLE PORTD.0
PAUSE 100
GOTO START
DISABLE
TLOOP:
INTCON.2=0 ' DATA SHEET SECTION 14.3.2
TOGGLE PORTD.4
FOR CNT = 0 TO 150
PWM PORTD.6,D,100
D = D + 2
NEXT CNT
RESUME
ENABLE
Bookmarks