Hi there!
I have written a programme for a line follower robot ( though still not implemented), first I want to try it with LEDs, Here is the code :
Now let me explain you what this code supposed to do (which it does very well but only when the PIC is powered by PIC Kit 2):
First when the power turned on RA0 and RA3 goes HIGH lighting YELLOW and GREEN LEDs, and when I press switch 1, RB0 goes high and an interrupt occur and YELLOW LED switched off and BLUE LED lights up and same sequance is applicable to RED and GREEN LEDs when I press switch 2 which causes interrupt at RB5
Again let me tell you that the PIC runs this programme very well BUT ONLY WHEN IT IS POWERED BY PIC KIT 2 AND NOT WHEN CONNECTED EXTERNALLY AS SOWN IN CKT.
PLEASE, don't check that this code is o.k. for a line follower or not or don't tell me that there is a better code for that I know ther are many, I'm a layman (see how I learned PIC programming on thread titled" setup an interrupt in 16f690") , I JUST WANT TO ASK THAT WHY IT IS NOT WORKING WHILE POWERED EXTERNALLY ?
By not working I mean :
When I turn on the power YELLOW and GREEN LEDs lights up as it should be but, on either interrupt both LEDs goes off lightning NO OTHER LED, I tried tieing MCLRE high and even LOW but nothing work.
PLEASE HELP ME !!
Edit: Kindly see the circuit that is exactly how I connect it, nothing more nothing less
I have written a programme for a line follower robot ( though still not implemented), first I want to try it with LEDs, Here is the code :
Code:
list p=16f628
#include<p16f628.inc>
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
temp
temp_s
endc
;******************************************************************
org 0x00
goto main
;***********************************INTERRUPT LOOP*****************
org 0X04
inter:
movwf temp
swapf STATUS,w
clrf STATUS
movwf temp_s
btfsc PORTB,0x00
goto loop1
loop2:
movlw b'00000101'
movwf PORTA
btfsc PORTB,0x05
goto loop2
goto loop_x
loop1:
movlw b'10001000'
movwf PORTA
btfsc PORTB,0x00
goto loop1
loop_x
bcf INTCON,0x01
bcf INTCON,0x00
swapf temp_s,w
movwf STATUS
swapf temp,w
retfie
main:
bsf INTCON,0x07 ;Globel interrupt enable(we are using interr.)
bsf INTCON,0x04
bsf INTCON,0x03 ;RB4-RB7 interrupt on change is enabled/ in other words these pins will also work as
;interrupts and interrupt will occur every time any of these pin changes state
; i.e.:HIGH to LOW or LOW to HIGH, we can not set it to be on eather one state change
bcf INTCON, 0x01
bcf INTCON, 0x00 ;Clear RB4-RB7 interrupt flag so, that another interr. can occur.
;**********************************SET UP THE PORTS *****************
bsf STATUS,RP0 ;switch to BANK 1
movlw b'00100001'
movwf TRISB ;set RB6 & RB5 as input
movlw b'00000000'
movwf TRISA ;setPORT A all output
bcf OPTION_REG,0x07 ; enable weak pull ups on port b/ pull ups mean internal resistors
bcf STATUS,RP0 ;back to BANK 0
movlw 0x07 ;turn comparators off, so HIGH will be simple
; HIGH rather than +5V (compared to supply) so with the LOW
movwf CMCON
Loop:
movlw b'00001001'
movwf PORTA ;set pin 0 of port a HIGH
goto Loop
END
Now let me explain you what this code supposed to do (which it does very well but only when the PIC is powered by PIC Kit 2):
First when the power turned on RA0 and RA3 goes HIGH lighting YELLOW and GREEN LEDs, and when I press switch 1, RB0 goes high and an interrupt occur and YELLOW LED switched off and BLUE LED lights up and same sequance is applicable to RED and GREEN LEDs when I press switch 2 which causes interrupt at RB5
Again let me tell you that the PIC runs this programme very well BUT ONLY WHEN IT IS POWERED BY PIC KIT 2 AND NOT WHEN CONNECTED EXTERNALLY AS SOWN IN CKT.
PLEASE, don't check that this code is o.k. for a line follower or not or don't tell me that there is a better code for that I know ther are many, I'm a layman (see how I learned PIC programming on thread titled" setup an interrupt in 16f690") , I JUST WANT TO ASK THAT WHY IT IS NOT WORKING WHILE POWERED EXTERNALLY ?
By not working I mean :
When I turn on the power YELLOW and GREEN LEDs lights up as it should be but, on either interrupt both LEDs goes off lightning NO OTHER LED, I tried tieing MCLRE high and even LOW but nothing work.
PLEASE HELP ME !!
Edit: Kindly see the circuit that is exactly how I connect it, nothing more nothing less
Attachments
Last edited: