I have problem starting iterrupt 0
I setup the following interrupt routine and i have on the display settup to see the counter running
When i start, nothing happen
timer does not start
I am using Mikrobasic from Mikroelectronica, but any sugestion will be good, and i can implement it
here is the initialization at start program
Code:
INTCON.7 = 1 'GIE IS SET == GLOBAL INTRRUPT ENABLE BIT
INTCON.2 = 0 ' START TIMER
INTCON2.2 = 1 'TMR0IP SET TO 1 ;TIMER 0 INTERUPT PRIORITY ==HIGH
RCON.7 = 1 'INTERUPT PRIORITY ENABLE IPEN SET TO 1
T0CON.7 = 1 'ENABLE TIMER 0 ; IF 0 STOP TIMER 0
T0CON.6 = 0 'SET TO 16 BITS
T0CON.5 = 0 'SELECT INTERNAL CLOCK
T0CON.3 = 0 'IT WILL USE THE PRESCALLER
then this is the interrupt service routine
Code:
sub procedure interrupt ' Define interrupt subprocedure
IF TMR0IF = 1 THEN
cnt = cnt +1 ' Increment variable cnt by 1
INTCON.2 = 0
TMR0L = 0
TMR0H = 0
end if
end sub ' End of interrupt routine
and this is the display of the counter
Code:
if cnt > 2000 then
porte.1 = 1
delay_ms(600)
porte.1 = 0
cnt = 0
TMR0L = 0
TMR0H = 0
end if
Thank you very much !!!
It does work now.
Do you have any idea or example ( better) how to use the interrupt for usart receive ?
I get data from usart receive , while the program is stuck in a loop doing something, and for this i miss the data.
I need an interrupt to tell me that i have data, read it , assign it to a variable ,then go back
Example will be GREAT
Thank you
Ion
I would suggest you to look at Microchip site, where you can get a number of examples!!. You have to configure USART Tx & Rx interrupts. You should also configure correct baud rate.
Thank you , I will look.
The bad part with Microchip is that they give you examples on C or assembler, and i do not know any of them
I read and set the interrupts for usart, but i do not know what to write inside ISR and extraxt data from RCREG to a variable which i can use it.
Regards
Ion
sub procedure interrupt
IF PIR1.RCIF = 1 THEN 'if flag is on
Rval = RCREG
if Rval = 9 then Rwdt = 1 end if
if (Rval <> 9) then TravelOUT = Rval end if
pir1.rcif = 0 'clear flag
end if
IF INTCON.TMR0IF = 1 THEN
cnt = cnt +1 'Increment variable cnt by 1
INTCON.TMR0IF = 0 'REFET FLAG
TMR0L = 0 'LOAD TIMER LOW BYTE
TMR0H = 0 'LOAD TIMER HIGH BYTE
if cnt = 1000 then cnt = 0 end if
end if
end sub 'End of interrupt routine