PDA

View Full Version : Programming Issues



mitchf14
- 5th July 2009, 05:22
I am trying to use a timer1 program I created in pic simulator ide with microcode studio plus. I could not figure out the syntax in microcode studio plus for the timers so I made it with pic simulator ide, but I prefer to use microcode studio plus because all my other programs are made with it and I want to stay with the same software. My program works fine in pic simulator but in microcode it does not work here is my code; microcode complains about all the lines in bold.

TRISB = %10000000
INTCON = %11000000
PIE1 = %00000001
TMR1L = %11011100
TMR1H = %00001011
T1CON = %00110001
PIR1.TMR1IF = 0
Dim overflow As Byte

start:

If PORTB.7 = 1 Then
PORTB.5 = 1
Else
PORTB.5 = 0

Endif

Goto start

End

On Interrupt

overflow = overflow + 1

If overflow = 20 Then
overflow = 0

If PORTB.1 = 0 Then
PORTB.1 = 1 'Turn on LED
Else
PORTB.1 = 0 'Turn off LED
Endif
Endif

TMR1L = %11011100
TMR1H = %00001011
PIR1.TMR1IF = 0 Resume
I’ve then changed my program to look like this, it’s like the program never jumps into the blink subroutine does anyone have any ideas why it is not working.

TRISB = %10000000
INTCON = %11000000
PIE1 = %00000001
TMR1L = %11011100
TMR1H = %00001011
T1CON = %00110001
PIR1.0 = 0

overflow var Byte

start:

If PORTB.7 = 1 Then
PORTB.5 = 1
Else
PORTB.5 = 0
Endif

Goto start

End


On Interrupt goto blink

blink:

overflow = overflow + 1

If overflow = 20 Then

overflow = 0

If PORTB.1 = 0 Then
PORTB.1 = 1 'Turn on LED
Else
PORTB.1 = 0 'Turn off LED
Endif
Endif

TMR1L = %11011100
TMR1H = %00001011
PIR1.0 = 0

Resume

To me it should be working i have no clue why any help would be appreciated.

Bruce
- 6th July 2009, 15:28
ON INTERRUPT needs to be before start.


TRISB = %10000000
INTCON = %11000000
PIE1 = %00000001
TMR1L = %11011100
TMR1H = %00001011
T1CON = %00110001
PIR1.0 = 0

overflow var Byte

On Interrupt goto blink ' enable interrupt checking in start

start:
If PORTB.7 = 1 Then
PORTB.5 = 1
Else
PORTB.5 = 0
Endif
Goto start


disable ' disable interrupt checking below

blink:
overflow = overflow + 1
If overflow = 20 Then
overflow = 0

If PORTB.1 = 0 Then
PORTB.1 = 1 'Turn on LED
Else
PORTB.1 = 0 'Turn off LED
Endif
Endif

TMR1L = %11011100
TMR1H = %00001011
PIR1.0 = 0
Resume
enable

END

mitchf14
- 7th July 2009, 19:25
Thanks bruce il give that a try. Let you know if its worked.