bigal_scorpio
Active Member
Hi Guys,
I have been trying for days to write a program to read a pin pin going ground and flashing a corresponding LED on another port.
The program below is about the tenth attempt and still refuses to work.
This final version ignores all but PortB pin 3 and even then just lights the C port pin 3 WHILE the button is held! No flashes!
I am ready to give up and beleive me I don't quit easily.
Any ideas please.
Thanks.............Al
I have been trying for days to write a program to read a pin pin going ground and flashing a corresponding LED on another port.
The program below is about the tenth attempt and still refuses to work.
This final version ignores all but PortB pin 3 and even then just lights the C port pin 3 WHILE the button is held! No flashes!
I am ready to give up and beleive me I don't quit easily.
Any ideas please.
Code:
program carswitch2
'Pic16F874a @ 8mHz on Easypic5 dev board
main:
DIM t as byte
TRISA = %00000000
PORTA = %00000000
TRISB = %11111111
PORTB = %00000000
TRISC = %00000000
PORTC = %00000000
TRISD = %00000000
PORTD = %00000000
TRISE = %00000000
PORTE = %00000000
CMCON =0x07
ADCON1 = 0xCF
Checkpress: 'check for button pressed
IF (BUTTON(PORTB,0,1,0))then GOTO one
END IF
IF (BUTTON(PORTB,1,1,0))then GOTO two
END IF
IF (BUTTON(PORTB,2,1,0))then GOTO three
END IF
IF (BUTTON(PORTB,3,1,0))then GOTO four
END IF
IF (BUTTON(PORTB,4,1,0))then GOTO five
END IF
IF (BUTTON(PORTB,5,1,0))then GOTO six
END IF
IF (BUTTON(PORTB,6,1,0))then GOTO seven
END IF
IF (BUTTON(PORTB,7,1,0))then GOTO eight
END IF
GOTO main
one:
FOR t = 1 to 3
PORTC = %00000001
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
two:
FOR t = 1 to 3
PORTC = %00000010
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
three:
FOR t = 1 to 3
PORTC = %00000100
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
four:
FOR t = 1 to 3
PORTC = %00001000
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
five:
FOR t = 1 to 3
PORTC = %00010000
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
six:
FOR t = 1 to 3
PORTC = %00100000
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
seven:
FOR t = 1 to 3
PORTC = %01000000
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
eight:
FOR t = 1 to 3
PORTC = %10000000
delay_ms (100) 'flash corresponding led on port c to press on port b
PORTC = %00000000
NEXT t
GOTO Checkpress
end.
Thanks.............Al
Last edited: