PDA

View Full Version : PWM with 12F675



fratello
- 27th October 2009, 19:20
Hello everyone !
Since I bought a lot of 12F675, I think to try another schematic : lighting LED using software PWM. I wrote this code ; when power on the PIC, the LED give 20 % of light ; if buton is pressed, the LED lights 40%, then 60%, then 80% and, finally, 100 %. In my dreams :( ...because in practice that don't work like I wish. I know that code is not good...so, please, help me with some suggestion. Thanks in advance.

Darrel Taylor
- 27th October 2009, 19:46
The variable used in the CASE is specified in the SELECT statement.
The CASE itself only needs the value to compare ...
select case counter
case 1
brightness=50
pwm led,brightness,cycle

case 2
brightness=100
pwm led,brightness,cycle

... etc.

fratello
- 28th October 2009, 05:30
Thank You Mr. D ! It's no e-beer on www enough for You as a gift !
Yes, indeed, I am wrong with sintax...but still don't work proper.
Maybe because of my poor english...
So :
-power on, LED lighting 20% (till power off or push button)
-push button, LED lighting 40 % (same as previous)
-push button, LED lighting 60% (same as previous)
-push button, LED lighting 80% (same as previous)
-push button, LED lighting 100% (same as previous)
-push button, LED off till power on again or push button.
It is possible ?

Darrel Taylor
- 28th October 2009, 07:15
Don't worry about your English.
It's the BASIC Language that's subject... :eek:

Let's see ... power-on 20%, push a button 40% .. etc.. etc... off after 100%


brightness = 51

Main:
WHILE buton
pwm led,brightness,cycle
WEND
if brightness != 255
brightness = brightness + 51
else
brightness = 0
endif
WHILE !buton
pwm led,brightness,cycle
WEND
GOTO Main

fratello
- 28th October 2009, 17:30
Mr.Darrel, You are my guardian angel from far and away !!!
Works verry good. Thank You from the bottom of my heart !
P.S. : " if brightness != 255 then".

Darrel Taylor
- 28th October 2009, 18:25
You're welcome fratello,


P.S. : " if brightness != 255 then".
Oops, that's what I get for not compiling it. :o
<br>