Micro - Pin 1 at C6
Vdd Jumper - a6 to +rail
Vss Jumper - j6 to -rail
Green Jumper - j7 to j12
330 ohm - i12 to i18
Red LED - Anode j18, Cathode -rail
Green Jumper - i8 to i13
330 ohm - i13 to i20
Yellow LED - Anode j20, Cathode -rail
Blue Jumper - f9 to f15
330 ohm - g15 to g23
Green LED - Anode j23, Cathode -rail
The software is quite simple because it uses some of
the commands that make PICBASIC PRO easier to use
than many other compilers. The first steps involve making
the I/O digital. When the PIC12F683 is first powered up,
the I/O defaults to analog mode. The I/O pins share a
connection to both analog and digital features. The ANSEL
= 0 command line sets all the I/O pins to digital mode.
it turns off. The yellow is connected to the GP1 pin.
HIGH GPIO.1 ‘Yellow LED on
PAUSE 1000 ‘Delay 1 second
LOW GPIO.1 ‘Yellow LED off
The final step is to loop back to the main label to light
the red LED and repeat the process.
GOTO main ‘Loop Back to Red LED
The logical next step is to change the delays to make
the traffic light fit your application. If you wanted to make
a real traffic light from a project like this, then the delays
need to be a lot longer. There are three unused I/O pins, so
adding three more LEDs for another crossing lane of traffic
would be an option. Unfortunately, the GP3 pin is an input-only pin and cannot drive an LED. This is an example of
where a larger-pin microcontroller might be a better choice.
ANSEL = 0 ‘ Set I/O to digital
The PIC12F683 also has an internal comparator which
can be shut down with the CMCON0 = 7 line.
CMCON0 = 7 ‘ Comparator off
The main program loop begins with the label “main”
followed by a colon. We will use this as a marker in a
future GOTO command line.
The I/O pins on the PIC12F683 are referred to as general-purpose I/O pins, or GPIO. The internal register that controls
these pins individually is also called the GPIO register. These
can be controlled by writing to the GPIO register directly,
but we would also need to set up the TRISIO register inside
the PIC12F683. The TRISIO determines whether the pins
are digital-input or digital-output pins. Both of these are
automatically controlled with the HIGH or LOW command.
The GPIO.0 is the nickname for the GP0 pin. The
software uses the HIGH command to place a high signal
on that pin. This will light the LED. The PICBASIC PRO
compiler doesn’t care if you use capitals or lower case
letters for the commands. The red LED is lit first for two
seconds and then shut off to create the stoplight portion
of the traffic light. All actions are on the GP0 pin which is
connected to the red LED.
HIGH GPIO.0 ‘Light Red LED
PAUSE 2000 ‘Delay 2 second
LOW GPIO.0 ‘Red LED off
The green LED is next and it is lit for the same amount of
time as the red LED. The green LED is connected to the GP2 pin.
HIGH GPIO.2 ‘Green LED on
PAUSE 2000 ‘Delay 2 second
LOW GPIO.2 ‘Green LED off
Finally, the yellow LED is lit for a short time and then
SENSING A SWITCH
Many projects require some kind of human interface
to control the operation. A momentary pushbutton switch
is a very common way to do this. It can start and stop
the operation, or speed up or slow down what the
microcontroller is controlling. In order to do this,
however, the software needs to recognize that a switch
was pressed. This project shows a simple method of
sensing a momentary pushbutton switch.
The software must monitor the switch continuously as
part of the main loop of code, and then respond. In this
project, the software lights an LED until the switch is
pressed, at which point the LED shuts off. As long as the
switch is pressed, the LED will stay off. As soon as the
switch is released, the LED will once again light up. The
completed project is shown in Figure 4.
The hardware uses the same red LED connections as
the traffic light project. The addition of the switch is
shown in the schematic in Figure 5. The switch is wired
as a low-side switch which means the circuit has a pull-up
■ FIGURE 3. LED Traffic
November 2009 57