PIC Programming Module USB and Traffic Light System Controller
PIC Programming Module USB and Traffic Light System Controller
Page 1 of 26
[www.lrtrobotics.comyr.com ]
Page 2 of 26
[www.lrtrobotics.comyr.com ]
Construction Procedure:
Technical Diagram
[www.lrtrobotics.comyr.com ]
Reality view
Page 4 of 26
[www.lrtrobotics.comyr.com ]
Page 5 of 26
[www.lrtrobotics.comyr.com ]
A diode / capacitor pump circuit ( D3, D4, D5 and D6 with C2, C8, C3 and C4 ) converts the 5V
p/p square wave pulses at Pump to +12V DC. This voltage runs the 4050 Buffer IC. A voltage
divider at Feedback controls the input of the 4050 from the PIC chip. Thus a +12V / +5V signal
can be switched to the Program pin of a PIC chip to place it in or out of program mode. The
ICSPDAT ( data ) and ICSPCLK ( clock ) signals transfer the data in and out ( for verification ) of
the Programmed PIC chip.
Page 6 of 26
[www.lrtrobotics.comyr.com ]
The 16 pin PIC Programming Kit incorporates the PIC16F819 microcontroller from Microchip
Technology Inc. (USA). As the PIC Programming Kit had built in FLASH MEMORY, program can
be applied by not taking it off. The board can be used to input/output signals, switches, sound,
LED's, transistor drives, relays, serial port data etc. Many configurations are possible.
Page 7 of 26
[www.lrtrobotics.comyr.com ]
Page 8 of 26
[www.lrtrobotics.comyr.com ]
SETUP Diagram
Programming
Flat Assembler
Page 9 of 26
[www.lrtrobotics.comyr.com ]
Part List
Microcontroller
-------------------1 16 pin PIC
1 20 Pin IC Socket
16V Capacitor
-------------------2 100uF 16V Capacitor
6V Battery
-------------------1 6V Battery
Switch
-------------------1 Switch
Transistor BC337
-------------------1 Transistor BC337
Capacitor
-------------------1 100nF Capacitor
Piezo Buzzer
-------------------1 Piezo Buzzer
Power Connector
-------------------1 Power Connector
Red LED
-------------------6 Red LED
Resistor
-------------------7 390 Resistor
2 10k Resistor
Page 10 of 26
[www.lrtrobotics.comyr.com ]
T2_green
T2_yellow
T2_red
Buzzer
T1_green
T1_yellow
T1_red
D4
D5
D6
D7_YellowLED
EN
RS
RW
Push_Button
PORTA, 7
PORTB, 4
PORTB, 5
PORTA, 6
PORTA, 3
PORTA, 2
PORTA, 0
PORTA, 3
PORTA, 4
PORTB, 6
PORTB, 7
PORTA, 2
PORTA, 1
PORTA, 0
PORTA, 5
;***********Declare Variables***********
I
J
K
B2
B1
B0
Hys
B3
A3
A0
A1
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
32
33
34
35
36
37
38
39
40
41
42
Page 11 of 26
[www.lrtrobotics.comyr.com ]
A2
equ
43
0x0000
InItSeTuP
0x0004
;
;***********Initialise Ports***********
InItSeTuP
__CONFIG B'11111100011000'
CLRF
PORTA
CLRF
PORTB
BSF
STATUS,RP0
MOVLW
B'10000000'
MOVWF
OPTION_REG
BCF
STATUS,RP0
XWZ1pmExy2
btfsc
PORTA,5 ;If: PORTA Bit 5 OFF Then Skip
GoTo
XWZ1pmExy2
BSF
STATUS,RP0
MOVLW
B'00110010'
MOVWF
TRISA
MOVLW
B'00000000'
MOVWF
TRISB
MOVLW
B'01110000' ;OSCCON
MOVWF
OSCCON
BCF
STATUS,RP0
call
Setup
;******************Main Program******************
START
CALL
OnOffPin20 ;
CALL
OnOffPin21 ;
CALL
TimeDelay9 ;
CALL
OnOffPin23 ;
CALL
OnOffPin22 ;
CALL
TimeDelay10 ;
CALL
OnOffPin24 ;
CALL
OnOffPin25 ;
Page 12 of 26
[www.lrtrobotics.comyr.com ]
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
GOTO
GOTO
TimeDelay11 ;
OnOffPin33 ;
OnOffPin26 ;
TimeDelay12 ;
OnOffPin27 ;
OnOffPin28 ;
TimeDelay13 ;
OnOffPin29 ;
OnOffPin30 ;
OnOffPin31 ;
START
;
$
;******************Subroutines******************
Setup
CALL
DigitalPort ;
MOVLW
100
;
CALL
DELAY
;
return
;
;----------------------------------------------LED_1Test
BSF
T1_red
;
MOVLW
100
;
CALL
HundredthDelay
;
BCF
T1_red
;
MOVLW
100
;
CALL
HundredthDelay
;
return
;
;----------------------------------------------LED_2Test
BSF
T1_yellow ;
MOVLW
100
;
CALL
HundredthDelay
;
BCF
T1_yellow ;
MOVLW
100
;
CALL
HundredthDelay
;
return
;
;----------------------------------------------LED_3Test
BSF
T1_green ;
MOVLW
100
;
CALL
HundredthDelay
;
BCF
T1_green ;
MOVLW
100
;
CALL
HundredthDelay
;
Page 13 of 26
[www.lrtrobotics.comyr.com ]
return
;
;----------------------------------------------LED_4Test
BSF
T2_red
;
MOVLW
100
;
CALL
HundredthDelay
BCF
T2_red
;
MOVLW
100
;
CALL
HundredthDelay
return
;
;----------------------------------------------LED_5Test
BSF
T2_yellow ;
MOVLW
100
;
CALL
HundredthDelay
BCF
T2_yellow ;
MOVLW
100
;
CALL
HundredthDelay
return
;
;----------------------------------------------LED_6Test
BSF
T2_green ;
MOVLW
100
;
CALL
HundredthDelay
BCF
T2_green ;
MOVLW
100
;
CALL
HundredthDelay
return
;
;----------------------------------------------Buzzer_1Test
BSF
Buzzer
;
MOVLW
100
;
CALL
HundredthDelay
BCF
Buzzer
;
MOVLW
100
;
CALL
HundredthDelay
return
;
;----------------------------------------------DigitalPort
BSF
STATUS,RP0 ;
MOVLW
6
;
MOVWF
ADCON1
;
BCF
STATUS,RP0 ;
return ;
;-----------------------------------------------
Page 14 of 26
[www.lrtrobotics.comyr.com ]
DELAY
MOVWF
J
;
Dloop
;
DECFSZ
I,F
;
GOTO
Dloop
;
DECFSZ J,F
;
GOTO
Dloop
;
return
;
;----------------------------------------------HundredthDelay
MOVWF
K
;
Loop100th
;
MOVLW
100
;
MOVWF
J
;
outerLoop
;
MOVLW
248
;
MOVWF
I
;
innerLoop
;
DECFSZ
I,F
;
GOTO
innerLoop ;
DECFSZ J,F
;
GOTO
outerLoop ;
DECFSZ K,F
;
GOTO
Loop100th ;
return ;
;----------------------------------------------OnOffPin
;MACRO_MODULE*
;TYP, 0
;MOD, 1
;IOS
;CAP, On Off Pin
;DSC, The 'ON OFF PIN module sets the pin in the 'OUTPUT PIN' box to either ON or OFF.
return
;
;----------------------------------------------OnOffPin0
BSF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin1
BSF
T2_red
;
CALL
OnOffPin ;
return
;
;----------------------------------------------Page 15 of 26
[www.lrtrobotics.comyr.com ]
TimeDelay
;MACRO_MODULE*
;TYP, 14
;MOD, 3
;USR, A0:00
;USR, A1:00
;USR, A2:00
;USR, A3:00
;CAP, Delay
;DSC, The TimeDelay module will pause the program for the amount of time specified in the
selected fields.
MOVLW
1
MOVWF
B3
; All pins on PORTA to digital I/O
MOVF
A0, W
MOVWF
A0
; check for zero
btfsc
STATUS,Z ;
GOTO
Seconds ;
MinsLoop
;
CALL
MinDelay ;
DECFSZ A0,F
;
GOTO
MinsLoop ;
Seconds
;
MOVF
A1, W
MOVWF
A1
; check for zero
btfsc
STATUS,Z ;
GOTO
HunsLoop ;
SecsLoop
;
CALL
SecDelay ;
DECFSZ A1,F
;
GOTO
SecsLoop ;
HunsLoop
;
MOVF
A2, W
MOVWF
A2
; check for zero
btfsc
STATUS,Z ;
GOTO
TenKLoop ;
MOVF
A2, W
;
CALL
HunSecDelay ;
TenKLoop
;
MOVF
A3, W
MOVWF
A3
; check for zero
btfsc
STATUS,Z ;
return
;
CALL
TenKDelay ;
return
;
;----------------------------------------------Page 16 of 26
[www.lrtrobotics.comyr.com ]
MinDelay
MOVLW
60
MOVWF
Hys
;
MinLoop
;
CALL
SecDelay ;
DECFSZ Hys,F
;
GOTO
MinLoop ;
return
;
;----------------------------------------------SecDelay
MOVLW
100
;
CALL
HunSecDelay ;
return
;
;----------------------------------------------HunSecDelay
MOVWF
B2
;
TenThouLoop
;
;delays for a set number of centiseconds(100ths)
;W=number of 100ths to delay
MOVLW
20
MOVWF
B1
;
Loop100th1
;
MOVLW
248
;
MOVWF
B0
;
LoopNop
;
NOP
;
DECFSZ B0,F
;
GOTO
LoopNop ;
DECFSZ B1,F
;
GOTO
Loop100th1 ;
DECFSZ B2,F
;
GOTO
TenThouLoop ;
return
;
;----------------------------------------------TenKDelay
Loop1
;
DECF
B3,F
;
btfsc
STATUS,Z ;
GOTO
offset
;
MOVLW
48
MOVWF
B0
;
Loop2
;
NOP
;
DECFSZ B0,F
;
GOTO
Loop2
;
Page 17 of 26
[www.lrtrobotics.comyr.com ]
DECFSZ A3,F
;
GOTO
Loop1
;
return ;
offset
;
MOVLW
36
MOVWF
B0
;
GOTO
Loop2
;
return
;
;----------------------------------------------TimeDelay0
CLRF
A0
;
MOVLW
05
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin2
BSF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin3
BSF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay1
CLRF
A0
;
MOVLW
07
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin4
BSF
T1_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin5
BSF
T2_yellow ;
CALL
OnOffPin ;
Page 18 of 26
[www.lrtrobotics.comyr.com ]
return
;
;----------------------------------------------Add
;MACRO_MODULE*
;TYP, 3
;MOD, 3
;USR, A0:
;USR, B0:
;OUT, A0
;CAP, Addition
;DSC, The 'Add' module adds the value in the first box to the value in the second box and stores the
result as the name in the 'SAVE RESULT AS' box. A new or existing name can be used.
MOVF
B0, W
;
CLRF
A1
;
ADDWF
A0,F
;
btfsc
STATUS,C ;
MOVLW
255
btfsc
STATUS,C ;
MOVWF
A0
;
MOVF
A0, W
;
return
;
;----------------------------------------------TimeDelay2
CLRF
A0
;
MOVLW
03
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin6
BCF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin7
BCF
T2_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin8
BCF
T1_red
;
CALL
OnOffPin ;
return ;
Page 19 of 26
[www.lrtrobotics.comyr.com ]
;----------------------------------------------OnOffPin9
BCF
T2_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------All_Red_5s
CALL
OnOffPin0 ;
CALL
OnOffPin1 ;
CALL
TimeDelay0 ;
CALL
OnOffPin8 ;
CALL
OnOffPin9 ;
return
;
;----------------------------------------------OnOffPin10
BCF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin11
BCF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------All_Green_7s
CALL
OnOffPin2 ;
CALL
OnOffPin3 ;
CALL
TimeDelay1 ;
CALL
OnOffPin10 ;
CALL
OnOffPin11 ;
return ;
;----------------------------------------------OnOffPin12
BCF
T1_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin13
BCF
T2_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------All_Yellow_3s
CALL
OnOffPin4 ;
CALL
OnOffPin5 ;
Page 20 of 26
[www.lrtrobotics.comyr.com ]
CALL
TimeDelay2 ;
CALL
OnOffPin12 ;
CALL
OnOffPin13 ;
return
;
;----------------------------------------------OnOffPin14
BSF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin15
BSF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay3
CLRF
A0
;
MOVLW
07
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return
;
;----------------------------------------------TimeDelay4
CLRF
A0
;
CLRF
A1
;
MOVLW
30
MOVWF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin16
BSF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin17
BSF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay5
CLRF
A0
;
Page 21 of 26
[www.lrtrobotics.comyr.com ]
CLRF
A1
;
MOVLW
30
MOVWF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin18
BCF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin19
BCF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay6
CLRF
A0
;
CLRF
A1
;
MOVLW
30
MOVWF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------All_Green_f1x
CALL
OnOffPin16 ;
CALL
OnOffPin17 ;
CALL
TimeDelay5 ;
CALL
OnOffPin19 ;
CALL
OnOffPin18 ;
CALL
TimeDelay6 ;
return ;
;----------------------------------------------All_Green_f3x
CALL
TimeDelay7 ;
CALL
All_Green_f1x
;
CALL
All_Green_f1x
;
CALL
All_Green_f1x
;
return ;
;----------------------------------------------TimeDelay7
CLRF
A0
;
CLRF
A1
;
Page 22 of 26
[www.lrtrobotics.comyr.com ]
MOVLW
30
MOVWF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return
;
;----------------------------------------------OnOffPin20
BSF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin21
BSF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay8
CLRF
A0
;
MOVLW
11
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------TimeDelay9
CLRF
A0
;
MOVLW
07
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin22
BSF
T2_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay10
CLRF
A0
;
MOVLW
03
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
Page 23 of 26
[www.lrtrobotics.comyr.com ]
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin23
BCF
T2_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin24
BCF
T2_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin25
BSF
T2_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay11
CLRF
A0
;
MOVLW
01
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin26
BSF
T1_green ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay12
CLRF
A0
;
MOVLW
07
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin27
BCF
T1_green ;
CALL
OnOffPin ;
return ;
Page 24 of 26
[www.lrtrobotics.comyr.com ]
;----------------------------------------------OnOffPin28
BSF
T1_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------TimeDelay13
CLRF
A0
;
MOVLW
03
MOVWF
A1
;
CLRF
A2
;
CLRF
A3
;
CALL
TimeDelay ;
return ;
;----------------------------------------------OnOffPin29
BCF
T1_yellow ;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin30
BCF
T2_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin31
BSF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin32
BCF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------OnOffPin33
BCF
T1_red
;
CALL
OnOffPin ;
return ;
;----------------------------------------------END
Page 25 of 26
[www.lrtrobotics.comyr.com ]
It WORKS!
Page 26 of 26
[www.lrtrobotics.comyr.com ]