Device = 18F1220
Clock = 8
Config OSC = INTIO2 // Use the Internal Oscillator
Include "utils.bas"
Dim sw As PORTB.3 // Assign an alias for the switch
Dim LED1 As PORTB.7 // Assign an alias for "LED"
Dim LED2 As PORTB.6
Dim LED3 As PORTB.5
Dim LED4 As PORTB.4
// Start Of Program...
OSCCON = %01111111 // Sets up the internal oscillator
SetAllDigital // Make all Pins digital I/O's
Low(LED1) // Make the LED pin an output and set it low
Low(LED2)
Low(LED3)
Low(LED4)
While sw = 1
wend
While true
Repeat
Until Sw = 1
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
Wend
Device = 18F1220
Clock = 8
Config OSC = INTIO2 // Use the Internal Oscillator
Include "utils.bas"
Dim sw As Bit
Dim previous As Bit //saves previous key press
Dim key As Bit //saves new press
Dim Sw1 As PORTB.3 // set port for switch
Dim LED1 As PORTB.7 // Assign an alias for "LED"
Dim LED2 As PORTB.6
Dim LED3 As PORTB.5
Dim LED4 As PORTB.4
OSCCON = %01111111 // sets up the internal oscillator
key=0 // sets key to 0
While true // test to see if true
DelayMS(10) //delay for key press
previous=key //moves value to save in previous
key=Sw1 // reads new value
If(key=1 And previous=0) Then // see if true
sw = 1
Else sw = 0 // turns Led on if true
EndIf
Wend
sw = 0
While true
Repeat
Until sw = 1
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
Wend
Device = 18F1220
Clock = 8
Config OSC = INTIO2 // Use the Internal Oscillator
Include "utils.bas"
Dim sw As Bit
Dim previous As Bit //saves previous key press
Dim key As Bit //saves new press
Dim Sw1 As PORTB.3 // set port for switch
Dim LED1 As PORTB.7 // Assign an alias for "LED"
Dim LED2 As PORTB.6
Dim LED3 As PORTB.5
Dim LED4 As PORTB.4
OSCCON = %01111111 // sets up the internal oscillator
key=0 // sets key to 0
While true // test to see if true
DelayMS(10) //delay for key press
previous=key //moves value to save in previous
key=Sw1 // reads new value
If(key=1 And previous=0) Then // see if true
sw = 1
Else sw = 0 // turns Led on if true
EndIf
Wend
[COLOR="Red"]
//program will NEVER get here
sw = 0
While true
Repeat
Until sw = 1
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
Wend[/COLOR]
Device = 18F1220
Clock = 8
Config OSC = INTIO2 // Use the Internal Oscillator
Include "utils.bas"
Dim previous As Bit //saves previous key press
Dim key As Bit //saves new press
Dim Sw1 As PORTB.3 // set port for switch
Dim LED1 As PORTB.7 // Assign an alias for "LED"
OSCCON = %01111111 // sets up the internal oscillator
key=0
While true
DelayMS(10)
previous=key
key=Sw1
If(key=1 And previous=0) Then
Toggle(LED1)
EndIf
Wend
sw = 0
While true
Repeat
Until sw = 1
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
Wend
] You are so rightThat code makes absolutely no sense. What are you trying to do?
If(key=1 And previous=0) Then
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
EndIf
Device = 18F1220
Clock = 8
Config OSC = INTIO2 // Use the Internal Oscillator
Include "utils.bas"
Dim previous As Bit //saves previous key press
Dim key As Bit //saves new press
Dim Sw1 As PORTB.3 // set port for switch
Dim LED1 As PORTB.7 // Assign an alias for "LED"
Dim LED2 As PORTB.6
Dim LED3 As PORTB.5
Dim LED4 As PORTB.4
OSCCON = %01111111 // sets up the internal oscillator
SetAllDigital // Make all Pins digital I/O's
Low(LED1) // Make the LED pin an output and set it low
Low(LED2)
Low(LED3)
Low(LED4)
key=1
While true
DelayMS(10)
previous=key
key=Sw1
If(key=0 And previous=1) Then
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
DelayMS(500) // Delay for half a second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0 // Delay for half a second
DelayMS(500)
EndIf
Wend
Dim Count as integer
Count=0
While true
delayMS(10)
if (Sw1=1) then //if switch pressed then
Count=Count+1 //flash LEDs
if(Count<50) then //is it first 0.5S
LED1 = 1 // Turn on the LED
LED2 = 1
LED3 = 1
LED4 = 1
Else //if second half of second
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0
Endif
if(Count=100) then //reset after 1 second
Count=0
endif
else //else if key not pressed
Count=0 //reset count
LED1 = 0 // Turn off the LED
LED2 = 0
LED3 = 0
LED4 = 0
EndIf
Wend
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?