PDA

View Full Version : Problem with led



savnik
- 16th January 2007, 14:42
I have conect two leds to porta.2 and porta.3.
My problem is when i press 1 or 2 keys on keyboard (PC) the led isn't turn on
My pic is 16f88


old var byte
new var byte


main:
serout porta.0, T9600, ["Enter which LED to light (0-1): ", 10, 13]
serin porta.1, T9600, #new
serout porta.0, T9600, ["LED Chosen: ", #new, 10, 13]
Pause 100
low old
high new
old = new
goto main

Acetronics2
- 16th January 2007, 14:59
Hi, Savnik

LOW and HIGH commands can't be applied to variables ... but Ports or aliases.

Alain

savnik
- 16th January 2007, 15:35
I have conect two leds to porta.2 and porta.3.
My problem is when i press 1 or 2 keys on keyboard (PC) the led isn't turn on
My pic is 16f88



new var byte
led var PORTA.2
led1 var PORTA.3

main:
serout porta.0, T9600, ["Enter which LED to light (0-1): ", 10, 13]
serin porta.1, T9600, #new
serout porta.0, T9600, ["LED Chosen: ", #new, 10, 13]
Pause 100
if new = 1 then high led
if new = 2 then high led1
goto main

I change the code and now works , but idon't like this.

skimask
- 16th January 2007, 17:37
I change the code and now works , but idon't like this.

What's wrong with it? Short, simple, functional...

sayzer
- 16th January 2007, 19:50
I see an analog port issue going around.

It happens to all of us, or does it?


Also, where do you turn OFF the LEDs?

Once you set them HIGH, when will they get set LOW?


------------------------------

skimask
- 16th January 2007, 19:56
I see an analog port issue going around.

It happens to all of us, or does it?


Also, where do you turn OFF the LEDs?

Once you set them HIGH, when will they get set LOW?


------------------------------

new var byte
led1 var PORTA.2
led2 var PORTA.3

adcon.1 = 7

main:
new = 0
serout porta.0, T9600, ["Enter which LED to light (1-2,0=Off): ", 10, 13]
serin porta.1, T9600, new
serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]
if new = "1" then
high led1 : low led2
enfif
if new = "2" then
high led2 : low led1
endif
if new = "0" then
low led1 : low led2
endif

goto main

savnik
- 16th January 2007, 20:24
I see an analog port issue going around.

It happens to all of us, or does it?
------------------------------
I have at the top of code:

CMCON = 7
ANSEL = 0




Also, where do you turn OFF the LEDs?

Once you set them HIGH, when will they get set LOW?


------------------------------
This is my problem

sayzer
- 16th January 2007, 21:30
Savnik,

Take a look at the post before yours.

skimask has it for you.


------------------------

skimask
- 16th January 2007, 21:39
Savnik,

Take a look at the post before yours.

skimask has it for you.


------------------------

I think he might've meant that he found the problem and has fixed it...

However, I could be wrong...have been before...will be again. :)

savnik
- 17th January 2007, 06:45
Savnik,

Take a look at the post before yours.

skimask has it for you.


------------------------

I test now and it's work (thanks to skimask) , but when i press the 0 turn off both leds.
I want if i press one time the 1 to turn the led1 on and if i press again the 1 to turn off the led1.The same for the led2

Archangel
- 17th January 2007, 08:05
I test now and it's work (thanks to skimask) , but when i press the 0 turn off both leds.
I want if i press one time the 1 to turn the led1 on and if i press again the 1 to turn off the led1.The same for the led2

Have you tried the toggle command?

savnik
- 17th January 2007, 12:56
Have you tried the toggle command?
No.
I try now with toggle and work.
Thank you.
I add this:
if new = 1 then toggle led1
if new = 2 then toggle led2
The only problem now is :
when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
After this no need second time to press the number 2.

skimask
- 17th January 2007, 13:54
No.
I try now with toggle and work.
Thank you.
I add this:
if new = 1 then toggle led1
if new = 2 then toggle led2
The only problem now is :
when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
After this no need second time to press the number 2.

Have you no imagination? No creative thoughts?

CMCON = 7
ANSEL = 0
adcon.1 = 7

new var byte
led1 var PORTA.2
led2 var PORTA.3

main:
new = 0
serout porta.0, T9600, ["Enter which LED to light (1-2,0=Off): ", 10, 13]
serin porta.1, T9600, new
serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]

if new = "1" then

if led1 = 1 then
led1 = 0
else
led1 = 1
endif

endif

if new = "2" then

if led2 = 1 then
led2 = 0
else
led2 = 1
endif

endif

if new = "0" then
low led1 : low led2
endif

goto main

Archangel
- 18th January 2007, 02:06
No.
I try now with toggle and work.
Thank you.
I add this:
if new = 1 then toggle led1
if new = 2 then toggle led2
The only problem now is :
when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
After this no need second time to press the number 2.

Hi Savnik,
in your code do this, put your code into nice little chunks that you can see what they do. Chunk1 put all your defines and variable declarations.
chunk 2 is start directory. chunk 3 is main loop. this will help you stay organised.In the start subdirectory give your variables a set value,
I think this should help.



CMCON = 7
ANSEL = 0
adcon.1 = 7

new var byte
led1 var PORTA.2
led2 var PORTA.3

Start:
led1 = 0
led2 = 0

main:
new = 0
serout porta.0, T9600, ["Enter which LED to light ", 10, 13]
serin porta.1, T9600, new
serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]

if new = "1" then

if led1 = 1 then
led1 = 0
else
led1 = 1
endif

endif

if new = "2" then

if led2 = 1 then
led2 = 0
else
led2 = 1
endif

endif

if new = "0" then
low led1 : low led2
endif

goto main


The commands in the start directory will run only once at startup and should set both leds in the off condition.

skimask
- 18th January 2007, 02:08
Hi Savnik,
in your code do this, put your code into nice little chunks that you can see what they do. Chunk1 put all your defines and variable declarations.
chunk 2 is start directory. chunk 3 is main loop. this will help you stay organised.In the start subdirectory give your variables a set value,
I think this should help.



CMCON = 7
ANSEL = 0
adcon.1 = 7

new var byte
led1 var PORTA.2
led2 var PORTA.3

Start:
led1 = 0
led2 = 0

main:
new = 0
serout porta.0, T9600, ["Enter which LED to light ", 10, 13]
serin porta.1, T9600, new
serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]

if new = "1" then

if led1 = 1 then
led1 = 0
else
led1 = 1
endif

endif

if new = "2" then

if led2 = 1 then
led2 = 0
else
led2 = 1
endif

endif

if new = "0" then
low led1 : low led2
endif

goto main


The commands in the start directory will run only once at startup and should set both leds in the off condition.




Now why didn't I think of that :D :) :D

savnik
- 18th January 2007, 06:29
thanks skimask and Joe S.