I m begginer i need help.
I need to LED lights turn on and turn off after pressing the button. This means that a push button and LED is turned on first A push button and switches off LED1. This is necessary for all LED and buttons.
program LED_GENERATOR
' Declarations section
symbol LED1 = PORTA.3
symbol SWT1 = PORTA.1
symbol LED2 = PORTA.2
symbol SWT2 = PORTA.0
symbol LED3 = PORTA.7
symbol SWT3 = PORTA.4
symbol LED4 = PORTA.6
symbol SWT4 = PORTA.5
symbol LED5 = PORTB.0
symbol SWT5 = PORTB.5
symbol LED6 = PORTB.1
symbol SWT6 = PORTB.4
symbol LED7 = PORTB.2
symbol SWT7 = PORTB.6
symbol LED8 = PORTB.3
symbol SWT8 = PORTB.7
main:
TRISA = %00110011
PORTA = %00000000
TRISB = %11110000
PORTB = %00000000
' Main program
cmcon =%00000111 'Comparators Off
vrcon =%00000000
intcon =%00000000
You could use a switch state latch and parallel switch state logic to detect the "new press" state while ignoring the other switch states (no more waiting for a switch to be released). Then toggle flag bits (from on-to-off or from off-to-on) for each "new press" state.
The example below shows this toggle switch emulation using eight I/O pins for both switches and LEDs;
Regards...
Code:
; /* Lighted Push Button Switches (emulated toggle switches)
; *
; * swnew ____---____-----___ sample active lo switches
; * swold _____---____-----__ switch state latch
; * delta ____-__-___-____-__ changes, press or release
; * newhi ____-______-_______ filter out 'release' bits
; * flags _____-------_____-- toggle flag bits for main
; * trisb -----_______-----__ toggle tris bits for LEDs
; */
; while(1)
; { delay_ms(25); // 25 msec sample intervals
; trisb = 0xFF; // set PORTB to inputs
; swnew = ~portb; // sample active lo switches
; swnew ^= swold; // changes, press or release
; swold ^= swnew; // update switch state latch
; swnew &= swold; // filter out 'release' bits
; flags ^= swnew; // toggle flags bits for main
; portb = 0; // keep PORTB latch bits = '0'
; trisb ^= flags; // light only "active" LEDs
; }
Granted..... But as I said the OP was working in basic... How are we to assume that " swnew ^= swold; " is known to someone who uses basic. It's C shorthand... We are here trying to help.
P.S. I use Oshonsoft myself.... Perhaps I didn't get the point across.
Are you sure about that Ian? When I was playing with Swordfish BASIC several years ago, it had all those operators (XOR, AND, OR, etc.)...
Granted..... But as I said the OP was working in basic... How are we to assume that " swnew ^= swold; " is known to someone who uses basic. It's C shorthand... We are here trying to help.
P.S. I use Oshonsoft myself.... Perhaps I didn't get the point across.