Documente Academic
Documente Profesional
Documente Cultură
1
@ clrf PORTB ; Clear PortB latches
'
'
'
' Set Variables Options
'
'
CMCON = %00000111 ' Set Port A to all analogue
'
INTF VAR INTCON.1 ' RB0 Interrupt flag
INTE VAR INTCON.4 ' RB0 Interrupt Enable
Angle VAR WORD ' Delay in firing triac
'
'
' Port B
Triac VAR PortB.1 ' Output - to opto-triac
Up VAR PORTB.7 ' Input - Increase brightness
Down VAR PORTB.6 ' Input - Decrease brightness
'
'
' Incon Register Definitions
' -------------------------------
' 7=1 Global Interrupt Enable
' 6=0 Peripheral Interrupts Disabled
' 5=0 TMR0 Interrupt Disabled
' 4=1 RB0 Interrupt Enabled
' 3=1 RB4-RB7 Port change Interrupt Enabled
' 2=0 TMR0 Flag Reset
' 1=0 RB0 Flag Reset
' 0=0 RB4-RB7 Flag Reset
'
' Option Register Definitions
' --------------------------------
OPTION_REG = %11000000
' 7=0 Port B Pullups Enable
' 6=0 Interrupt Edge Select Bit
' 5=0 TMR0 Clock Source Select Bit
' 4=0 TMR0 Source Edge Select Bit
' 3=0 Prescaler Assignment Bit
' 2=0 Prescaler Rate Select Bit
' 1=0 Prescaler Rate Select Bit
' 0=0 Prescaler Rate Select Bit
'
'
'
Triac = 0 ' Triac off
Angle = 0 '
OPTION_REG = %11001001 ' WDT enabled 1:2 (36mS timeout )
'
2
On Interrupt Goto myint ' Define interrupt handler
INTCON = %10010000 'Enable RB0 interrupt
'
Angle = 1000 '
Goto loop ' Start of program
'
'
'
'****************************************
' Interrupt handler
'****************************************
Disable ' No interrupts past this point
myint:
IF INTF = 1 THEN ' If Interrupt flag set
PAUSEUS Angle ' Delay triac firing
HIGH Triac ' Triac ON
PAUSEUS 100 '
LOW Triac ' Triac OFF
ENDIF '
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable ' Re-enable interrupts
'
'
'
'----------------------------------------------
' Start of main program
'----------------------------------------------
'Check switch settings
'
Loop:
CLEARWDT ' Reset if timeout
IF (Up = 1) AND (Down = 1) THEN Loop ' Do nothing
IF (Up = 1) AND (Down = 0) THEN Dimit ' Decrease lamp intensity
IF (Up = 0) AND (Down = 1) THEN Upit ' Increase lamp intensity
IF (Up = 0) AND (Down = 0) THEN Loop ' Do nothing
GOTO Loop
'
'
'
Dimit: IF (Angle = 10000) THEN LOOP ' If not at min brightness
Angle = Angle + 2 ' Increase turn on delay
GOTO LOOP '
'
'
Upit: IF (Angle = 1000) THEN LOOP ' If not at max brightness
Angle = Angle - 2 ' decrease turn on delay
GOTO LOOP '
'
END
3
1 2 3 4
1
D1
4 x 1N4007
JP1 +5V
4 2
A 1 A
2
HEADER 2 R1 R2
240V 100K, 1W 10K
3
U2A U2B
1 2 3 4
ZC
74ALS04 74ALS04
U1
K3020
0V
R4 R5 +5V +5V
470 330
U4
240v Live 1 18
B 2 RA2/AN2/VREF RA1/AN1 17 R10 R11 B
3 RA3/AN3/CMP1 RA0/AN0 16 10K 10K
ZC RA4/T0CKI/CMP2 RA7/OSC1/CLKIN
4 RA5/MCLR/THV RA6/OSC2/CLKOUT 15
R3
39 Q1 C2 U3 6 13
47nF, X2, 400V R9 7 RB0/INT RB7/T1OS1 12
TIC226D RB1/RX/DT RB6/T1OSO/T1CKI
330 8 11
RB2/TX/CK RB5
9 RB3/CCP1 RB4/PGM 10
C1 4N25 PIC16F627
0V S1 S2
10nF, X2, 400V
C3
UP DOWN
1
470K 470K 47 D2
240V
JP2 JP3LOAD 4 x 1N4007 U5
1 1 78L05
4 2 1 3
2 2 Vin Vout +5V
GND
HEADER 2 HEADER 2
D3
C4 C5
22uF 1uF
3
2
9.1V, 500mW
0V
240v Neutral
Title
D D