Making a breadboard useful

Create a simple electronic circuit, using a breadboard. Then, control it from PIC.


Creating a simple electronic circuit

The outputs from GPIO controll the tuning-on/off of the LED.
RA0, the 23rd-pin at J1, is used.~ The 14th-pin at J1 is used as GND since the location of the pin is easy to access and to be identifiable.~ Please accordingly set the LED, resistor, and cable in the breadboard as they are shown in the picture below.
Please be careful with the direction of the LED as you are going to insert it into the breadboard.
The longer leg of LED is attached to BC-USB-Kit.

Preparation of the software

This is the contents of "main.c."

#include <stdio.h>
#include <stdlib.h>
#include <system.h>

#define LED_ON_BB LATAbits.LATA0

int main(int argc, char** argv) {
     int onboard = 0;
     LED_TRIS_ON_BB = 0;

     while (1){
          if (onboard>0){
               LED_ON_BB = 1;
               LED_ON_BB = 0;

          if ( BUTTON_IsPressed(BUTTON_S1) ){
               onboard =! onboard;
     return (EXIT_SUCCESS);

To learn programming, please do not try to memorize whole code as it is, but please understand the structure and meaning of the code.
In this code, the critical part is that initially TRISAbits.TRISA0 is set to 0 (zero), then, it is set to the output.
The other important part is that when LATAbits.LATA0 is set to 1, an LED lights up, and when it is set to 0, the LED turns off.


If there are no problems, each time you press the user programmable button, the other LED lights up.

Revision History

Front page   New List of pages Search Recent changes   RSS of recent changes