Hi,
My brains not working at 100% what with olympics and kids etc I'm a bit sleep deprived! Anyway I'm having trouble with my PIC and I'm hoping someone can simply say oh its this.
I'm using a PIC18F4620 and it was working fine until I decided to place some extra functionality on port B.0. This is a switch where I can press it and I can then go and do other stuff. The trouble is that the PIC is waiting on the PORTB.0 = 1 line for me to press the key... Here is the relavent code...(its in MikroBasic but should be easy to follow)
I have been doing checks before and after the PORTB.0 = 1 and it is ok before and does nothing afterwards. If I do press the switch then "handleFunction" gets called fine at any time...which leads me to the conclusion that the PIC processor is waiting on the line PORTB.0 = 1
Thanks heaps,
Craig
My brains not working at 100% what with olympics and kids etc I'm a bit sleep deprived! Anyway I'm having trouble with my PIC and I'm hoping someone can simply say oh its this.
I'm using a PIC18F4620 and it was working fine until I decided to place some extra functionality on port B.0. This is a switch where I can press it and I can then go and do other stuff. The trouble is that the PIC is waiting on the PORTB.0 = 1 line for me to press the key... Here is the relavent code...(its in MikroBasic but should be easy to follow)
Code:
OSCCON = %01110110 ' set to 8Mhz
TRISA = %00011111 ' PORTA is input on RA0 to RA4. RA5 to RA7 as output
TRISB = %00000011 ' PORTB is output on all ports except RB0 and RB1
TRISC = $0 ' PORTC is output
TRISD = $0 ' PORTD is output
TRISE = $0 ' PORTE is output
PORTE = 0 ' Initialise Port E - this is the filling status and controls tap switch
PORTD = 0 ' Initialise Port D - this is the LED display
' Port C is the Ethernet
' Port B is the EEprom
ADCON1 = %00001011 ' Set AN0 to AN4 as analogue, rest are digital
ADCON2 = %00111011
CMCON = 0x07 ' Turn off all comparitors
'Set up the timer
'Clock = 8Mhz
'Time per instruction = 4/8Mhz = 0.5uSec
'Add in prescalar = 0.5uSec * 16 = 8uSec
'Add in postscalar = 8uSec * 10 = 80uSec = time per Timer2 register increment
'Add in register counting of 250 = 80uSec * 250 = 20mSec
'Therefore 1 second occurs when cnt variable = 50
T2CON = %01001111 ' prescalar = 1:16 postscalar = 1:10
PR2 = 249 ' count up to 250
SetBit(PIE1, TMR2IE) ' enable Timer2 interrupt
... Other setup ...
INTCON = %11000000 ' set GIE, PEIE interupt
' ==========================================================
'
' Main processing loop
'
' ==========================================================
while TRUE
if PORTB.0 = 1 then
handleFunction ' Go off and callibrate
end if
... Continue on with other bits and peices
wend
I have been doing checks before and after the PORTB.0 = 1 and it is ok before and does nothing afterwards. If I do press the switch then "handleFunction" gets called fine at any time...which leads me to the conclusion that the PIC processor is waiting on the line PORTB.0 = 1
Thanks heaps,
Craig