Код: Выделить всё
Case 0 :Код: Выделить всё
Case 0 :Код: Выделить всё
$regfile = "m8def.dat "
$crystal = 1000000
Ddrb = &B000111
Config Portd.3 = Input
Config Int0 = Low Level
Ds Alias Portb.0
Sh_cd Alias Portb.1
St_cp Alias Portb.2
Buton Alias Pind.2
On Int0 Butonp
Enable Interrupts
Enable Int0
Declare Sub 74hc595(byval Pin As Integer)
Dim Led As Integer
Dim Ifect As Byte
Led = 0
Ifect = 0
Do
Call 74hc595(led)
Rotate Led , Right , 1
Waitms 800
Loop
End
Sub 74hc595(byval Pin As Integer) 'Ïðîöåäóðà çàãðóçêè äàíûõ âðåãèñòð
Shiftout Ds , Sh_cd , Pin , 3 , 16
Set St_cp
Waitms 1
Reset St_cp
End Sub
Butonp: 'Îáðàáîòêà íàæàòèÿ êíîïêè
Waitms 30
While Buton = 0 'Îæèäàíèå îòïóñêàíèÿ êíîïêè
Wend
Ifect = Ifect + 1 'Âûáð ýôåêòà
If Ifect = 5 Then
Ifect = 0
End If
Select Case Ifect
Case 1 :
Led = &B0111111111111111
Case 2 :
Led = &B1000000000000000
Case 3 :
Led = &B1010101010101010
Case 4 :
Led = &B0011001100110011
Case 0 :
Led = &B1001100011100001
End Select
Gifr = 64
Waitms 1
Returnuser2007 писал(а):ШИМ работает так...
Код: Выделить всё
For Count = 0 To 255 ' шагая, увеличиваем счетчик яркости
Compare1a = Count ' грузим счетчик в регистр сравнения ШИМ
Waitms 20 ' задержка смены яркости
Next
Код: Выделить всё
$regfile = "m8def.dat"
$crystal = 8000000
Config Portd.6 = Output
Config Pind.2 = Input
Config Pind.3 = Input
Shim_up Alias Pind.3
Shim_down Alias Pind.2
Dim X As Byte , Tik As Byte
Config Timer2 = Timer , Prescale = 1
Enable Timer2
On Timer2 Pwms
Start Timer2
Enable Interrupts
X = 7
Do
If Shim_up = 0 Then
Waitms 70
If Shim_up = 0 Then Incr X
End If
If X > 14 Then X = 14
If Shim_down = 0 Then
Waitms 70
If Shim_down = 0 Then Decr X
End If
If X < 1 Then X = 1
Loop
End
Pwms:
Incr Tik
If Tik = 16 Then
Tik = 0
Reset Portd.6
End If
If Tik > X Then Set Portd.6
Return
EndTRIOD писал(а):Подскажите как отследить нажатие кнопки.
Суть втом что использую контролер Attiny85. Осталось свободными только два контакта, на одном который INT0 есть кнопка и она обрабатывается в прирывании. И нужно ещё одну повесить на PORTB0. В основном цыкле обработать не получается иза больших задержек до 700ms в другом месте. Получается что кнопку надо долго держать. Как ещё можно обработать нажатие кнопки?
Код: Выделить всё
$regfile = "m8def.dat "
$crystal = 1000000
Config Portb.0 = Input
Config Portb.1 = Input
Config Portb.3 = Output
Config Portb.2 = Output
Config Portb.4 = Output
Config Debounce = 30
Ds Alias Portb.2
Sh_cd Alias Portb.3
St_cp Alias Portb.4
Buton Alias Pinb.0
Speedb Alias Pinb.1
Declare Sub 74hc595(byval Pin As Word)
Dim Led As Word ' Ýôåêò
Dim Ifect As Byte 'Íîìåð ýôåêòà
Dim Speed As Word 'Ñêîðîñòü
Led = 32768
Ifect = 0
Speed = 300
Restore Ifecti
Debounce Buton , 0 , Butonp
Do
Call 74hc595(led)
Rotate Led , Right , 1
Waitms Speed
Loop
End
Sub 74hc595(byval Pin As Word) 'Ïðîöåäóðà çàãðóçêè äàíûõ âðåãèñòð
Shiftout Ds , Sh_cd , Pin , 3 , 16
Set St_cp
Waitms 1
Reset St_cp
End Sub
Butonp: 'Îáðàáîòêà íàæàòèÿ êíîïêè
Ifect = Ifect + 1 'Âûáð ýôåêòà
If Ifect = 4 Then
Ifect = 0
Restore Ifecti
End If
Read Led
Waitms 1
Return
Ifecti:
Data 32767% , 43690% , 28086%TRIOD писал(а):А то я попыталя сделать через DEBOUNCE, но вобще не работает...
edm2007 писал(а):TRIOD писал(а):А то я попыталя сделать через DEBOUNCE, но вобще не работает...
Я что-то не совсем понял, а как в данном случае опрос кнопки-то работает?
TRIOD писал(а):Ну вроде на сколько я понимаю. При нажатии кнопки на порту PB0 появляется 0 и програма должна прыгнуть на метку Butonp.
да только чтото не переходит, что с SUB что без SUB.
aleksandr-zh писал(а):kip96 писал(а):Ещё заметил что при пустом индикаторе и и сильной контрастности только 8 квадратиков темнеют.
так и должно быть
попробуйте в настройках ЖКИ указать большее количество символов в строке и только одну строку
Например, 20х1 или 40х1
TRIOD писал(а):А разву debounce надо вставлять в основной цикл? Если я правильно пинимаю даная функция вроде должна активировать прирывание по таймеру с проверкой состояния указоного порта и спереходом на нужную метку. Вроде так внутри компилятора организована Debounce.
Mark Alberts (разработчик BASCOM) с вами не согласен!TRIOD писал(а):Если я правильно пинимаю даная функция вроде должна активировать прирывание по таймеру с проверкой состояния указоного порта и спереходом на нужную метку. Вроде так внутри компилятора организована Debounce.
When you specify the optional parameter SUB, a GOSUB to label is performed instead of a GOTO.
The DEBOUNCE statement tests the condition of the specified pin and if true there will be a delay for 25 mS and the condition will be checked again. (eliminating bounce of a switch)
When the condition is still true and there was no branch before, it branches to specified the label.
When the condition is not true, or the logic level on the pin is not of the specified level, the code on the next line will be executed.
When DEBOUNCE is executed again, the state of the switch must have gone back in the original position before it can perform another branch. So if you are waiting for a pin to go low, and the pin goes low, the pin must change to high, before a new low level will result in another branch.
Each DEBOUNCE statement, which uses a different port, uses 1 BIT of the internal memory to hold its state. And as the bits are stored in SRAM, it means that even while you use only 1 pin/bit, a byte is used for storage of the bit.
DEBOUNCE will not wait for the input value to met the specified condition. You need to use BITWAIT if you want to wait until a bit will have a certain value.
So DEBOUNCE will not halt your program while a BITWAIT can halt your program if the bit will never have the specified value. You can combine BITWAIT and DEBOUNCE statements by preceding a DEBOUNCE with a BITWAIT statement.
aleksandr-zh писал(а):kip96 писал(а):Ещё заметил что при пустом индикаторе и и сильной контрастности только 8 квадратиков темнеют.
так и должно быть