View previous topic :: View next topic |
Author |
Message |
Neptune769
Joined: 27 Jul 2008 Posts: 55
|
Posted: Wed May 12, 2010 3:41 am Post subject: Newbie problem with button in LED out |
|
|
Hello Everyone,
I have been trying to figure out how I could have a button on PortA.0 and a LED on PortC.0 work. I read the manual and searched the forum for a simple example that I could understand without luck. I don't know what I'm missing. I don't want someone to give me the code to fix it I just need know what to look for so I can learn to figure it out. I just don't know what to look for. Any "hints" would be greatly appreciated.
Thanks.
Dennis
Code: |
$regfile = "m8535.dat."
$crystal = 8000000
'$sim
'$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Config Porta = Input
Config Portc = Output
Porta = &B11111111
Portc = &B11111111 '1 enables internal pull up on a input
Do
Waitms 10
Porta.0 = Pinc.0 'Turns ON or Off the Led's ..
Loop
End
|
|
|
Back to top |
|
|
Ross_ValuSoft
Joined: 20 Nov 2005 Posts: 275 Location: Melbourne, Australia
|
Posted: Wed May 12, 2010 6:27 am Post subject: |
|
|
Welcome Dennis.
OK, as per your wishes, I will not tell you how to do it ... or point out your actual syntax errors. But maybe a pseudo version that will light the LED as long as you have the switch pressed.
configure the output pin connected to a LED via a current setting resistor.
configure the input pin connected to the switch and an external pullup.
set the LED to be OFF by writing a zero/low to the output pin
start a continuous testing loop
read the input pin
is the input pulled to ground?
if not ... write a zero/low to the output pin and then return to the start of the testing loop
if yes ... pause for say 25 milliseconds of "debounce" time
test again if input is pulled to ground
if not ... was just noise so return to the start of the testing loop
if yes ... write a one/high to the output pin
return to the start of the testing loop
Then you could modify your code to toggle the LED status with each button press. Different code, but similar logic testing.
Cheers,
Ross |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Wed May 12, 2010 6:47 am Post subject: |
|
|
In your example you have set port direction right.
Pin with Led is output, pin with button is input.
But think about command
Porta.0 = Pinc.0
It means: read value on Pinc.0 and assign it to Porta.0.
Is it what you want? |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed May 12, 2010 7:30 am Post subject: |
|
|
This is rather a careless mistake, you've simly reversed ports, this way you try to assign the value of the output port to the input port, which obviously will not work.
Be aware that out of the box the M8535 runs with 1MHz, and not 8MHz as set in your code. This has the effect that every Wait xxx will take 8 times as long. You won't feel it here, as it makes no difference in this code whether it's 10ms or 80ms, but in different code it may give you a hard time. If you've changed the fuses already to 8MHz, this is no issue.
Code: | $regfile = "m8535.dat." |
Remove the second dot, makes no sense. However I was surprised, that Bascom still finds the right *.dat file with this mistake. |
|
Back to top |
|
|
Neptune769
Joined: 27 Jul 2008 Posts: 55
|
Posted: Wed May 12, 2010 10:31 pm Post subject: |
|
|
Thank you all for the reply.
I did notice that I had said "porta.0 = Pinc.0" after I had posted the message but before I had any replies. The last point of the "$regfile" was not intentional. I didn't even notice it. It just shows I need to be more observant of everything. The reason for the 8MHz is because the board I am using uses a 8MHz crystal. Now for the rest I will read over the info and try this code again. Wish me luck.
Dennis |
|
Back to top |
|
|
|