'********************************* ' Device : PIC12F675 @ device pic12F675, INTRC_OSC_NOCLKOUT, WDT_ON, MCLR_OFF, PWRT_ON, BOD_ON DEFINE OSCCAL_1K 1 ' Калибруем встроенный RC-генератор ' TRISIO = %11111011 OPTION_REG.7=0 ' Допустимые натяжения WPU=%00000011 ' Допустимые натяжения на GP0, GP1 CMCON=7 ' Выведите из строя аналоговый компаратор ANSEL=0 ' Выведите из строя аналогового преобразователя Pb_Inc var GPIO.0 ' Вклад для ПРИРАЩЕНИЯ/НА кнопке Pb_Dec var GPIO.1 ' Вклад для ДЕКРЕМЕНТА/кнопки Triac var GPIO.2 ' Выход в ворота TRIAC ACLine var GPIO.4 ' Введите FullWave исправляет линию AC line ' ' Software definition ' =================== ' ' ' MaxDelay var word TriacDelay var Word Debounce_AutoRepeatDelay var word FullBright var bit ' ' ' Interrupts definition ' ===================== ' ' ' INTCON=%10001000 ' Enable interrupt on GPIO change IOCB.4=1 ' Enable interrupt on GP4 change PIE1.0=0 ' disable TMR1 overflow interrupt T1CON=%00110100 ' Set TIMER1 ' prescaler 1:8 ' internal clock (Fosc/4) 1MHZ ' synchro internal ' we will use TIMER1 overflow ' $ffff * 8* (1/(4MHZ / 4)) = 0.524 Sec ON INTERRUPT GOTO ACDetect ' ' Hardware and variable initialisation ' ==================================== ' ' Maxdelay=6000 ' Set Maximum delay (set to 8000 for 50Hz) FullBright=0 ' disable Full Brightness flag triac=0 ' disable Triac Gate triacdelay=3000 ' Set delay to minimum gosub ResetTimer1 ' reset Timer1 ' ' Main ' ==== ' Get entry from user to Increment of Decrement intensity ' ' start: ' ' Test Increment push button ' -------------------------- ' If hold more than .5 Sec, increment triac gate delay by 500 uSec ' case else Full brightness at output ' while Pb_inc=0 gosub TestTimer1 ' test status of TIMER1 while (Pb_inc==0) AND (PIR1.0==0) 'loop while holding push button 'and no TIMER1 overflow wend if PIR1.0==1 then ' If timer overflow (pushbutton hold for > 0.5 sec), T1CON.0=0 ' disable TMR1 gosub Debounce_AutoRepeat if (triacdelayMaxDelay, fullbright=1 ' set the full brightness Flag endif else triacdelay=maxdelay ' If pushButton was hold less than .5 sec Fullbright=1 ' Set the full brightness flag endif wend gosub ResetTimer1 ' ' Кнопка Декремента Теста ' -------------------------- ' Если хранилище более, чем .5 Сек, приращение triac задержка ворот к 500 uSec ' Случаю еще, выключает выход ' while Pb_dec=0 gosub TestTimer1 ' Test status of TIMER1 while (Pb_dec==0) AND (PIR1.0==0) 'loop while holding push button 'and no TIMER1 overflow wend if PIR1.0==1 then ' If timer overflow (pushbutton hold for > 0.5 sec), T1CON.0=0 ' disable TIMER1 gosub Debounce_AutoRepeat if (triacdelay>0) then Fullbright=0 ' Reset TRIAC always ON flag triacdelay=triacdelay-100 endif else Fullbright=0 ' Reset TRIAC always ON flag triacdelay=0 endif wend gosub ResetTimer1 goto start ' ' ' TestTimer1 ' ---------- ' ' Enable TIMER1 if : ' not enable and not in overflow ' TestTimer1: if (T1CON.0==0) AND (PIR1.0==0) then 'if TIMER1 not enable 'and TIMER1 not overflow T1CON.0=1 'enable TIMER1 endif return ' ' ' ResetTimer1 ' ----------- ' ' Subroutine to clear Timer1 ' 1. Overflow flag ' 2. Disable Timer ' 3. Clear counter ' ResetTimer1: PIR1.0=0 'clear timer overflow T1CON.0=0 'disable timer TMR1L=$00 'clear counter TMR1H=$00 ' return ' ' ' Debounce_AutoRepeat ' ------------------- ' ' Подпрограмма на кнопку устранения. ' Также обеспечивать тип авто-повторения когда кнопка ' придержана. ' ' каждая задержка = 20 mSec ' Использование PAUSEUS, чтобы быть уверенно получая прерывание ACLine ' Debounce_AutoRepeat: for Debounce_AutoRepeatDelay=1 to 200 pauseus 10 next return ' ' ' ACDetect ' -------- ' ' Interrupt routine called by ACLine (GP4) pin state change ' disable ACDetect: if ACline==1 then ' Check for rising edge of AC signal if triacdelay > 0 then Triac=1 ' Activate TRIAC if FullBright==0 then ' In case Brightness flag is not set pauseus triacdelay ' do the selected delay triac=0 ' Disable TRIAC endif else triac=0 endif endif INTCON.0=0 ' Clear GPIF (interrupt on GP4 change) resume enable