2014年7月9日 星期三

Use the touchpad to control LED brightness



$regfile = "attiny13a.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4 
$framesize = 4
Dim I As Byte
Dim D As Byte
Dim A As Integer



Config Portb.4 = Input
Portb.4 = 1
Config Portb.0 = Output
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down


Label_1:
Restore Dta1
Pwm0a = 255                                                 'set darkness
A=0

Waitms 500

Do

   If Pinb.4 = 0 Then Gosub Routine
   Waitms 10
   A = A + 1
   If A = 500 Then Goto Label_2
Loop


Label_2:                                                    'adjust ok
   If Pinb.4 = 0 Then Goto Label_1
   A = 0
   Goto Label_2

End


Routine:
   Read D
   Pwm0a = D
   I = I + 1
   If I = 10 Then Restore Dta1
   If I = 10 Then I = 0
   Waitms 200
   A = 0
Return



Dta1:

Data 0
Data 195
Data 205
Data 218
Data 225
Data 235
Data 243
Data 252
Data 255