Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I hate to say it, but still nothing...
' * Project name:
' Button_Test
' * Copyright:
' (c) Mikroelektronika, 2005.
' * Description:
' This code demonstrates how to use Button library. Program toggles LEDs
' on PORTD, upon falling edge on PORTB's RB1 pin.
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board: EasyPic4
' Oscillator: HS, 08.0000 MHz
' Ext. Modules: -
' SW: mikroBasic v6.0
' * NOTES:
' - In order to work properly, in this example, ports B and D must have pull down
' resistors, also jumper jp20 on EasyPic4 board has to be in VCC position (that is,
' the voltage level to be applied when a button is pressed should be high (VCC)).
program Button_Test
dim oldstate as byte
main:
oldstate = 0
TRISB = 0xFF
TRISD = 0
PORTD = 0x0F
while true
if (Button(PORTB, 1, 1, 1)) then
oldstate = 1
end if
if (oldstate = 1) and (Button(PORTB, 1, 1, 0)) then
PORTD = not PORTD
oldstate = 0
end if
wend
end.
Code was written for 16F877a and I'll have to wait til' monday before I go back to work to get one. Meanwhile I tried to change portd to porta (since the 16F628 doesn't have a portd)
and that didn't work. the only thing that happened was leds ra0 to ra3 lit up. Jumpers were all in the right place. I also have a Easy Pic 5 at work and I'll swap to that platform...
The last 2 test programs on page 3 of this mess work. I tried both boards EP 4&5 and they reacted the same. Post #10 on page 3 makes a led come on and latches it on with 628.
Post # 14 page 3 toggles leds on/off on portd with the 877. I don't know whats different now from the other night? I tried the code from the previous posts and that still didn't work.
All that said ,it appears the EP 4 is ok, my comprehension skills on the other hand?????
TRISA = %00000001
TRISB = %10110000
PortB = %00100100
The last 2 test programs on page 3 of this mess work. I tried both boards EP 4&5 and they reacted the same. Post #10 on page 3 makes a led come on and latches it on with 628.
Post # 14 page 3 toggles leds on/off on portd with the 877. I don't know whats different now from the other night? I tried the code from the previous posts and that still didn't work.
All that said ,it appears the EP 4 is ok, my comprehension skills on the other hand?????
program Button_Test
dim oldstate as byte
main:
oldstate = 0 "don't know"
TRISB = 0xFF "tri state on port b ?"
TRISD = 0 " portd as output"
PORTD = 0x0F " portd off? "
while true
if (Button(PORTB, 1, 1, 1)) then "portb.1, input high?, no clue
oldstate = 1 " update oldstate to high"
end if
if (oldstate = 1) and (Button(PORTB, 1, 1, 0)) then "if high, button portb.1, high?, ?
PORTD = not PORTD " portd = low?
oldstate = 0
end if
wend
end
Not sure about above code but:
PORTD = 0x0F " portd off? " Actually 0x00 would be off
Example reads RB0, to which the button is connected; on transition from 1 to 0 (release of button), PORTD is inverted:
while true
if Button(PORTB, 0, 1, 1) then
oldstate = 255
end if
if oldstate and Button(PORTB, 0, 1, 0) then
PORTD = not(PORTD)
oldstate = 0
end if
wend
program bt
CMCON = 7
trisa = 0x0f
trisb = 0
if button(porta, 0, 1, 1) then ' if button pressed
portb = %11111111 ' turn on all leds
delay_ms(1000) 'wait 1 sec
portb = %00000000 ' turn off all leds
delay_ms(1000) 'wait 1 sec
end if
end.
I'm finally getting there!!
This works, all leds flash while button held down
Thanks for the help
Code:program bt CMCON = 7 trisa = 0x0f trisb = 0 if button(porta, 0, 1, 1) then ' if button pressed portb = %11111111 ' turn on all leds delay_ms(1000) 'wait 1 sec portb = %00000000 ' turn off all leds delay_ms(1000) 'wait 1 sec end if end.