Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Output led fade on_led fade off and input swith.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Dec 11, 2018 5:23 am    Post subject: Output led fade on_led fade off and input swith. Reply with quote

Hello everyone, I tried the program to fade a led on and off when you press a button and nothing does the led when you press the button and check the connections.
Could you correct the program?

Code:
$regfile = "m48def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize=32



Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up

Config Pinc.5 = Input : Sw0 Alias Pinc.5 : Portc.5 = 1

Config Portb.1 = Output                                     'OC1A pin  (Portb.1 for Atmega8) prtd.5 for atmega 16

'''''''''''''''''''''''''''' MAIN ''''''''''''''''''''''''''''''''''''
 Defbyte B

 Do

    If Sw0 = 0 Then
     Gosub Fade_on
     Else
     Gosub Fade_off
    End If

 Loop
 End


'''''''''''''''''''''''''''' END MAIN ''''''''''''''''''''''''''

 Fade_on:

    For B = 255 To 1 Step -1
     Pwm1a = B
     Waitus 1500
    Next
    Stop


 Fade_off:

    For B = 1 To 255
     Pwm1a = B
     Waitus 1500
    Next
    Stop
 


Sad
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Dec 11, 2018 9:04 am    Post subject: Reply with quote

This works. Tested. If not then check LED polarity.
Code:
$regfile = "m328pdef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 16
$framesize = 64


Led Alias Portb.1 : Config Led = Output
Sw0 Alias Pinc.5 : Config Sw0 = Input : Set Portc.5

Dim Helpb As Byte

For Helpb = 0 To 30                                         'hardware test
  Toggle Led                                                'LED should blink
  Waitms 50
Next
Helpb = 0

Config Timer1 = Pwm , Pwm = 8 , Prescale = 64 , Compare_a_pwm = Clear_up

Do

 If Sw0 = 0 Then
  If Helpb < 255 Then
   Incr Helpb
   Pwm1a = Helpb
  End If
 Else
  If Helpb > 0 Then
   Decr Helpb
   Pwm1a = Helpb
  End If
 End If

 Waitms 10
Loop
End
 
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Tue Dec 11, 2018 4:09 pm    Post subject: Reply with quote

Resolved, thanks for helping EDC.

Very Happy Very Happy Very Happy
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Dec 17, 2018 5:00 pm    Post subject: Reply with quote

For those who will be reading this in the future ahahaha:
I think that problem in Printpix code is that Subs "Fade_on" and "Fade_off" dont have "Return" command...
Code will be executed like this : ->jump to the Fade_off or Fade_on label -> do the code -> not return, execute next command which will be 00...00...00 etc till reach end of Flash and program will start again at $00

Stop is the command for another purpose.
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum