PDA

View Full Version : On Interrupt Goto (for pic18f252 ) Help



jetpr
- 13th May 2005, 03:26
Is not Working Help
INCLUDE "modedefs.bas"

DEFINE OSC 4
DEFINE PULSIN_MAX 6000 '6000 Define el tiempo de espera por el Pulsin
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3 'Uses internal RC clock
DEFINE ADC_SAMPLEUS 10 'Microsecond sample time


'-------------- Timer Use ------------------------
PowerLED VAR PORTB.5 'Pin 26 Red
StatusLED VAR PORTB.4 'Pin 27 Green
'---------------------Timre --------------------------------------------------------
hour var byte ' Define hour variable
minute var byte ' Define minute variable
second var byte ' Define second variable
ticks var byte ' Define pieces of seconds variable

'----------------------------------------------
LCDScreen VAR PORTC.7 'LCD Out Pin 18
LCDCmd CON 254 'LCD Command prefix
LCDHome CON 2 'Move cursor home, Pause
LCDClr CON 1 'Clear LCD screen, Pause
LCDLine1 CON 128 'First cell line 1
LCDLine2 CON 192 'First cell line 2


' T1CON = $01 ' Turn on Timer1, prescaler = 1
' INTCON = $C0 ' Enable global interrupts, peripheral interrupts
T0CON=%11010101
INTCON = $a0 ' Enable TMR0 interrupts


On Interrupt Goto Gettime
enable
RsetAll:
High PowerLED 'RED LED
pause 1000
low PowerLED 'RED LED
goto RsetAll
' Interrupt routine to handle each timer tick
disable ' Disable interrupts during interrupt handler
Gettime:
ticks = ticks + 1 ' Count pieces of seconds
SerOut LCDScreen, N2400, [LCDCmd, LCDLine2,#hour,":",#minute,":",#second]
pause 200
If ticks < 59 Then tiexit ' 61 ticks per second (16.384ms per tick)

' One second elasped - update time
ticks = 0
second = second + 1
If second >= 60 Then
second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
hour = hour + 1
Endif
write 43,hour
write 44,minute
write 45,second
Endif

tiexit: INTCON.2 = 0 ' Reset timer interrupt flag
Resume
'-------------------------------------------
end

mister_e
- 13th May 2005, 03:49
IMHO you can't use a serin/serout/pause in an Interrupt routine since it's longer than the interrupt cycle itself. BUT have you try to disable all interrupt by writing to INTCON a the begining of your Handler and re-enable them at the end?

BUT also, you must use shorter delay , let's say pauseus 10, and do a loop to produce your needed delay. That way, you'll be sure of getting interrupt as fast as it should.

there's probably something else but begin with it and post your results.

jetpr
- 13th May 2005, 03:56
who i disable all interrupt by writing to INTCON a the begining
and re-enable them at the end?

mister_e
- 13th May 2005, 04:13
disable al interrupts:
INTCON=0

reenable... use the one you declare at the begining:INTCON = $a0 ' Enable TMR0 interrupts

also don't forget to add Enable after Resume

mister_e
- 13th May 2005, 05:02
Here's what you need. i'm using the internal USART @2400 baud.



' Pic define
' ==========
' Using PIC18F2320
'
define LOADER_USED 1
DEFINE OSC 4

' Hardware definition
' ===================
'
'
TRISB=0
TRISC=%10000000

' Interrupt definition
' ====================
'
'
INTCON = $a0 ' Enable TMR0 interrupts
T0CON = %11010101
On Interrupt Goto Gettime

' Serial Communication definition
' ===============================
'
'
DEFINE HSER_TXSTA 24h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 2400

' I/O alias definition
' ====================
'
'
PowerLED VAR PORTB.5 'Pin 26 Red
StatusLED VAR PORTB.4 'Pin 27 Green

' Variable definition
' ===================
'
'
hour var byte ' Define hour variable
minute var byte ' Define minute variable
second var byte ' Define second variable
ticks var byte ' Define pieces of seconds variable
Delay var word
CLEAR

RsetAll:
toggle PowerLED 'RED LED

' Delay loop
' ==========
'
'
for delay =1 to 10000
pauseus 10
next

goto RsetAll


' Interrupt routine to handle each timer tick
' ===========================================
'
'
disable ' Disable interrupts during interrupt handler
Gettime:
ticks = ticks + 1 ' Count pieces of seconds
If ticks < 59 Then T1Exit ' 61 ticks per second (16.384ms per tick)

' One second elasped - update time & display
' ==========================================
'
'
ticks = 0
second = second + 1
If second >= 60 Then
second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
hour = hour + 1
Endif
write 43,hour
write 44,minute
write 45,second
Endif
hSerOut [#hour,":",#minute,":",#second,13,10]

T1Exit:
INTCON.2=0 ' clear interrupt flag
Resume
enable


Forget about the INTCON stuff i said before..

P.S. By writing to internal EEPROM as often as you do, you'll burn it soon, You should consider the use of external EEPROM like FRAM OR by saving your data only when the Voltage goes bellow a certain threshold. For cheapness i'll use the last option.