hi guys.. with respect to it not working as soon as i connect it to the PIC because its running on 12V... i tried it on 5V and i had the same problem... but that was after i first tried it on 12V. Ill try it again on 5V and reduce the value of the resistor so that i dont loose so much range on the IR transmitter/detector. By the way, i can use 16V max with the IR reciever, the minimum it can have to operate is 4.5V! I have pasted the software that i am using below. Ill also mention that when i was doing this test on the sensors... i was connecting it to an emulation board and running the software off the PC in a program called ICE pic. the pic i am using is PIC 16c66 and i am using delays in my software instead of interrupts. These sensors are part of a robot, they are used to detect the position of the robot with respect to a narrow coridoor wall. The principle of the sensors are fine, it works, its just when i connect it to the PIC or emulation board, all the LEDs turn off simultaneously, and when one of them detects a wall, ALL the LEDs come on instead of just the one LED that goes with the sensor that detected the wall.
The software im using is given below. Note that other commans other than the commands for the sensors are included, commands for the motors to make the robot turn right, left etc. thanks
list p=pic16c66,r=HEX,c=80 ; sets processor to 16c66, radix=hex
; set up labels, for ease of reading
PCL equ 0x02
FSR equ 0x04
INTCON equ 0x0b
OPT equ 0x81
PORTB equ 0x06
TRISB equ 0x86
PORTC equ 0x07
TRISC equ 0x87
STATUS equ 0x03
TMR0 equ 0x01
RP0 equ 5
TOIF equ 2
TOIE equ 5
GIE equ 7
RC0 equ 0
RC1 equ 1
RC2 equ 2
RC3 equ 3
RB0 equ 0
RB1 equ 1
RB2 equ 2
RB3 equ 3
RB4 equ 4
RB5 equ 5
RB6 equ 6
RB7 equ 7
LSB equ 0
Z_BIT equ 2
TMR1L equ 0x0E
TMR1H equ 0x0F
T1CON equ 0x10
CCPR2L equ 0x1B
CCPR2H equ 0x1C
CCP2CON equ 0x1d
; general storage locations
VALUE equ 0x2d
OFFSET equ 0x2e
PATTERN equ 0x2f
counter1 equ 0x31
counter2 equ 0x32
counter3 equ 0x33
; ###################################################
; Set_up reset Vector
org 0
goto main_start
; set_Up interrupt Vector
org 4
goto isr_start
; #####################################################
; ######### set-up interrupts and ports #############
; #####################################################
; set up port B pins to inputs
setup
bsf STATUS,RP0 ; set page to 1
movlw 0xFF
movwf TRISB ; set all portb pins to inputs
clrf TRISC ; set all portc pins to outputs
bcf STATUS,RP0 ; set page to 0
clrf INTCON
bsf INTCON,GIE ; enable interrupts globally
return
; ################################################
; ################# Data Tables ##################
; ################################################
table_1
decf OFFSET,0
addwf PCL,1
retlw b'11110111'
retlw b'11110101'
retlw b'11110101'
retlw b'01111111'
retlw b'00000010'
table_2
decf OFFSET,0
addwf PCL,1
retlw b'11010111'
retlw b'10110111'
retlw b'10010111'
retlw b'11100111'
retlw b'11000111'
table_3
decf OFFSET,0
addwf PCL,1
retlw b'11010101'
retlw b'11010100'
retlw b'11000101'
retlw b'11000100'
retlw b'10010101'
retlw b'10010001'
table_4
decf OFFSET,0
addwf PCL,1
retlw b'10011001'
retlw b'10111011'
;retlw b'10011101'
retlw b'10111001'
retlw b'10111011'
table_5
decf OFFSET,0
addwf PCL,1
retlw b'11101110'
retlw b'11001100'
retlw b'11101100'
retlw b'11101101'
retlw b'11001110'
; ################################################
; ######### 20ms Delay (APROX) ##########
; ################################################
delay_20
movlw d'6'
movwf counter1
loop1 movlw d'240'
movwf counter2
loop2 decf counter2,1
btfss STATUS,Z_BIT
goto loop2
decf counter1,1
btfss STATUS,Z_BIT
goto loop1
return
; ################################################
; ######### 30ms Delay (APROX) ##########
; ################################################
delay_30
movlw d'15'
movwf counter1
loop3 movlw d'240'
movwf counter2
loop4 decf counter2,1
btfss STATUS,Z_BIT
goto loop4
decf counter1,1
btfss STATUS,Z_BIT
goto loop3
return
; ################################################
; ######### Compare ##########
; ################################################
test_Lturn
incf OFFSET,1 ; add one to array index
call table_1
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto left_turn
movlw d'4'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Lturn
clrf OFFSET
test_Rturn
incf OFFSET,1 ; add one to array index
call table_2
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto right_turn
movlw d'5'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Rturn
clrf OFFSET
test_Uturn
incf OFFSET,1 ; add one to array index
call table_3
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto u_turn
movlw d'6'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Uturn
clrf OFFSET
test_Lsteer
incf OFFSET,1 ; add one to array index
call table_4
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto steer_left
movlw d'4'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Lsteer
clrf OFFSET
test_Rsteer
incf OFFSET,1 ; add one to array index
call table_5
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto steer_right
movlw d'5'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Rsteer
call no_match
return
; ################################################
; ######### Left Turn ##########
; ################################################
left_turn
movlw d'130'
movwf counter3
loop_stop
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop
movlw d'120'
movwf counter3
loop_left
movlw b'00000011'
movwf PORTC
call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_left
return
; ################################################
; ######### Right Turn ##########
; ################################################
right_turn
movlw d'130'
movwf counter3
loop_stop2
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop2
movlw d'120'
movwf counter3
loop_right
movlw b'00001111'
movwf PORTC
call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_right
return
; ################################################
; ######### U Turn ##########
; ################################################
u_turn
movlw d'150'
movwf counter3
loop_stop3
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop3
movlw d'238'
movwf counter3
loop_U
movlw b'00001111'
movwf PORTC
call delay_30
clrf PORTC
call delay_30
decfsz counter3,1
goto loop_U
return
; ################################################
; ######### Steer Left ##########
; ################################################
steer_left
movlw b'00000011'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### Steer Right ##########
; ################################################
steer_right
movlw b'00001111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### No Match ##########
; ################################################
no_match
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### Main Start ##########
; ################################################
main_start
call setup
main_loop
movf PORTB,0 ; move input values to w
movwf PATTERN ; move input values to comparison register
clrf OFFSET
call test_Lturn
goto main_loop
; ################################################
; ###### interrupt service routine #######
; ################################################
isr_start
retfie
end
The software im using is given below. Note that other commans other than the commands for the sensors are included, commands for the motors to make the robot turn right, left etc. thanks
list p=pic16c66,r=HEX,c=80 ; sets processor to 16c66, radix=hex
; set up labels, for ease of reading
PCL equ 0x02
FSR equ 0x04
INTCON equ 0x0b
OPT equ 0x81
PORTB equ 0x06
TRISB equ 0x86
PORTC equ 0x07
TRISC equ 0x87
STATUS equ 0x03
TMR0 equ 0x01
RP0 equ 5
TOIF equ 2
TOIE equ 5
GIE equ 7
RC0 equ 0
RC1 equ 1
RC2 equ 2
RC3 equ 3
RB0 equ 0
RB1 equ 1
RB2 equ 2
RB3 equ 3
RB4 equ 4
RB5 equ 5
RB6 equ 6
RB7 equ 7
LSB equ 0
Z_BIT equ 2
TMR1L equ 0x0E
TMR1H equ 0x0F
T1CON equ 0x10
CCPR2L equ 0x1B
CCPR2H equ 0x1C
CCP2CON equ 0x1d
; general storage locations
VALUE equ 0x2d
OFFSET equ 0x2e
PATTERN equ 0x2f
counter1 equ 0x31
counter2 equ 0x32
counter3 equ 0x33
; ###################################################
; Set_up reset Vector
org 0
goto main_start
; set_Up interrupt Vector
org 4
goto isr_start
; #####################################################
; ######### set-up interrupts and ports #############
; #####################################################
; set up port B pins to inputs
setup
bsf STATUS,RP0 ; set page to 1
movlw 0xFF
movwf TRISB ; set all portb pins to inputs
clrf TRISC ; set all portc pins to outputs
bcf STATUS,RP0 ; set page to 0
clrf INTCON
bsf INTCON,GIE ; enable interrupts globally
return
; ################################################
; ################# Data Tables ##################
; ################################################
table_1
decf OFFSET,0
addwf PCL,1
retlw b'11110111'
retlw b'11110101'
retlw b'11110101'
retlw b'01111111'
retlw b'00000010'
table_2
decf OFFSET,0
addwf PCL,1
retlw b'11010111'
retlw b'10110111'
retlw b'10010111'
retlw b'11100111'
retlw b'11000111'
table_3
decf OFFSET,0
addwf PCL,1
retlw b'11010101'
retlw b'11010100'
retlw b'11000101'
retlw b'11000100'
retlw b'10010101'
retlw b'10010001'
table_4
decf OFFSET,0
addwf PCL,1
retlw b'10011001'
retlw b'10111011'
;retlw b'10011101'
retlw b'10111001'
retlw b'10111011'
table_5
decf OFFSET,0
addwf PCL,1
retlw b'11101110'
retlw b'11001100'
retlw b'11101100'
retlw b'11101101'
retlw b'11001110'
; ################################################
; ######### 20ms Delay (APROX) ##########
; ################################################
delay_20
movlw d'6'
movwf counter1
loop1 movlw d'240'
movwf counter2
loop2 decf counter2,1
btfss STATUS,Z_BIT
goto loop2
decf counter1,1
btfss STATUS,Z_BIT
goto loop1
return
; ################################################
; ######### 30ms Delay (APROX) ##########
; ################################################
delay_30
movlw d'15'
movwf counter1
loop3 movlw d'240'
movwf counter2
loop4 decf counter2,1
btfss STATUS,Z_BIT
goto loop4
decf counter1,1
btfss STATUS,Z_BIT
goto loop3
return
; ################################################
; ######### Compare ##########
; ################################################
test_Lturn
incf OFFSET,1 ; add one to array index
call table_1
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto left_turn
movlw d'4'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Lturn
clrf OFFSET
test_Rturn
incf OFFSET,1 ; add one to array index
call table_2
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto right_turn
movlw d'5'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Rturn
clrf OFFSET
test_Uturn
incf OFFSET,1 ; add one to array index
call table_3
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto u_turn
movlw d'6'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Uturn
clrf OFFSET
test_Lsteer
incf OFFSET,1 ; add one to array index
call table_4
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto steer_left
movlw d'4'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Lsteer
clrf OFFSET
test_Rsteer
incf OFFSET,1 ; add one to array index
call table_5
xorwf PATTERN,0 ; compare input pattern with stored values
btfsc STATUS,Z_BIT
goto steer_right
movlw d'5'
subwf OFFSET,0
btfss STATUS,Z_BIT
goto test_Rsteer
call no_match
return
; ################################################
; ######### Left Turn ##########
; ################################################
left_turn
movlw d'130'
movwf counter3
loop_stop
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop
movlw d'120'
movwf counter3
loop_left
movlw b'00000011'
movwf PORTC
call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_left
return
; ################################################
; ######### Right Turn ##########
; ################################################
right_turn
movlw d'130'
movwf counter3
loop_stop2
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop2
movlw d'120'
movwf counter3
loop_right
movlw b'00001111'
movwf PORTC
call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_right
return
; ################################################
; ######### U Turn ##########
; ################################################
u_turn
movlw d'150'
movwf counter3
loop_stop3
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
decfsz counter3,1
goto loop_stop3
movlw d'238'
movwf counter3
loop_U
movlw b'00001111'
movwf PORTC
call delay_30
clrf PORTC
call delay_30
decfsz counter3,1
goto loop_U
return
; ################################################
; ######### Steer Left ##########
; ################################################
steer_left
movlw b'00000011'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### Steer Right ##########
; ################################################
steer_right
movlw b'00001111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### No Match ##########
; ################################################
no_match
movlw b'00000111'
movwf PORTC
Call delay_20
clrf PORTC
call delay_20
return
; ################################################
; ######### Main Start ##########
; ################################################
main_start
call setup
main_loop
movf PORTB,0 ; move input values to w
movwf PATTERN ; move input values to comparison register
clrf OFFSET
call test_Lturn
goto main_loop
; ################################################
; ###### interrupt service routine #######
; ################################################
isr_start
retfie
end