Learn To Write Code For 8051, Arduino, AVR, dsPIC, PIC, STM32 ARM Microcontroller, etc.
Coding Embedded Controller With C/C++.
Printed Circuit Board (PCB) Project For Electronics Hobbyists.
Using a prototype board for micro-controller firmware testing could save time and safer. Putting an on-board device programmer with prototype board could be more satisfy for electronic hobbyists.
I have some PIC18 and PIC16 series of micro-controllers left from previous projects. I don't know what to do with them anymore. So I put them on single board to PIC program testing next time I need them without checking their pin diagram, and wiring them on bread board.
PCB Front View
PCB Back View
I designed a PCB with a
PICKit2 device programmer (with AVR ISP header)
+5VDC and +3.3VDC low drop out power supply
RS-232 to TTL logic converter
I2C DS1307 RTC and 24LC08 EEPROM
4-bit LCD (HD4478)
3-digit 056'common cathode multiplexing display
One passive buzzer with transistor driver (using CCP1 PWM output pin of PIC16F876A)
8-LED that connects to PORTC of PIC16F876A
A 4x4 keypad matrix that connects to PORTB of PIC16F876A
Three analog inputs (one LM35 and two potentiometers) that connect to RA0...RA1 of PIC16F876A.
A 28-pin IC socket for 28-pin PIC devices
A 20-pin IC socket for 20-pin PIC devices
A 18-pin IC socket for 18-pin PIC devices
A 14-pin IC socket for 14-pin PIC devices
And a 8-pin IC socket for 8-pin PIC devices
This board seem to be a large PCB with two copper layer near a size of an A4 paper that I'm not yet fabricate it. It need a PCB fabrication service.
Schematic
I use Protues VSM Release 8.16 SP3 to design draw its circuit diagram. Some components are not in its original libraries. So I find and download some devices symbol, footprints and 3D objects from snapeda website. I separate its schematic into A4 sheets.
Sheet #1
Sheet #2
Sheet #3
Sheet #4
Sheet #5
This board could fit,
28-pin PIC microcontrollers: PIC16F876A, PIC16F886, etc.
20-pin PIC microcontrollers: PIC16F1459(USB), PIC16F690, etc.
18-pin PIC microcontrollers: PIC16F1827, PIC16F84A, PIC16F818, etc.
14-pin PIC microcontrollers: PIC16F630, PIC16F676, etc.
8-pin PIC microcontrollers: PIC12F629, PIC12F675, PIC12F683, etc.
These are some mid-range PIC micro-controllers I have at my own workshop.
Printed Circuit Board (PCB)
This board size is 8.02x6.30 inches that could be a little bit expensive to order from any professional PCB fabrication service. But if we need to use it with classmate or friend the share cost is cheaper.
Top Copper non-mirror
Bottom Copper
Top Silk
I preview this PCB on an online Gerber viewer software.
I have been using PCBWay for many years now. PCBWay fabricate PCBs at low cost,
fast processing time for only 24 hours, and fast delivery time using
any carrier options. This double side 10cmx10cm can be fabricate at only
5USD for 5 to 10pcs by PCBWay. It's a standard PCB with silk screen and
solder mask.
NXP PCF8574 is a remote digital inputs outputs expander. The interfacing method is implemented using the two-wire Inter Integrated Circuit (I2C) with the frequency up to 100 kHz. It has an 8-bit digital input output port. It's input output port is quasi-bidirectional. It does not require direction control.
A sample of program PIC12F629 connects to PCF8574 via software I2C Interface
Samples of PCF8574AP I bought from on line store
PCF8574AP Pin Diagram
Each pin of this 16-pin DIP device lists below.
Pin description of PCF8574 (from datasheet)
Supply voltage for this device ranges from 2.5 V to 6 V, typically 5 V for hobbyist prototyping. It's commonly found in input/output driving, keypad, and character LCD interface converter.
Programming For PCF8574
To interface to I2C devices on bus, we must know about it's device read/write address follows by an I2C start condition. It's read/write address varied with three bits A2, A1 and A0. These three pins must pull high or low externally, to make a specific slave address. The address lists below.
PCF8574 slave address
With these three bits, we could make three different slave address.
PCF8574 address map
Writing to the port of PCF8574 make its digital port as output. After a start condition, we must send the device slave address as listed above, follows by an 8-bit output value.
Write mode (output)
To read from this device, we put its read address, follows by data reading. For example, when we connect A2, A1 and A0 to VSS the device write address is 0x40 with the read address 0x41.
The INT (interrupt) pin is an output from PCF8574. It's open drain. This pin create a low signal when there's any logic state changed at input to the port of PCF8574.
Connecting the INT to Microcontroller
CCS PICC Coding
CCS PICC is a C compiler for 8-bit and 16-bit PICMicro. It's fast and easy to use with a lot of library. There are both hardware and software library. In the case of I2C, any device with I2C (for example PIC16F818) we can use hardware library or software library. Hardware I2C library is fast and reliable. Software I2C library work slower because it use program routine. Sometimes, it cause data corrupt. But with software I2C library, we can select any two-pin within the device.
PIC12F629 is an 8-pin 8-bit PICMicro in the Mid-Range family. It doesn't have I2C module shipped. However, we can use software I2C library instead.
Pin Diagram
In this example, I read data from the lower nibble of PCF8574 input and output to its higher nibble to the port.
Schematic Diagram
Source Code.
#include<12F629.h>
/*Use internal RC oscillator*/
#fuses INTRC_IO
#use delay(clock=4M)
/*implementing the software-base I2C*/
#use i2c(scl=pin_a0,sda=pin_a1,FORCE_SW)
void main(void){
char rcvData=0;
while(1){
/*Turn on lower nibble high
for digital input*/
i2c_start();
i2c_write(0x40);
i2c_write(rcvData|0x0F);
i2c_stop();
/*Read the input state of
lower nibble*/
i2c_start();
i2c_write(0x41);
rcvData=i2c_read();
i2c_stop();
/*Shift the inputs right
to the output*/
rcvData<<=4;
/*Write Data to output*/
i2c_start();
i2c_write(0x40);
i2c_write(0x0F);
i2c_stop();
/*Turn on lower nibble high
for digital input*/
i2c_start();
i2c_write(0x40);
i2c_write(rcvData|0x0F);
i2c_stop();
/*wait for 100 mS*/
delay_ms(100);
}
}
Click here to download the complete example. This example uses the ATMega32 to interfaces with the PCF8574A using its TWI module.
PIC12F685 is an 8-pin DIP PIC microcontroller. However, it has a lot peripherals such as 10-bit ADC, timer, large program memory and EEPROM.
It has up to 6 inputs/outputs, if we internal RC oscillator, and disabling the master clear reset (/MCLR) pin.
Since it has only 6 inputs/outputs, we need more output expanding. I use six 74HC595 shift register to drive 6 digits seven-segment display.
The overall 74HC595 combination interface to the PIC12F685 with only three pins:
serial clock
serial data
and latch pin
The PIC12F685 shifts data to the display system serially using these three pins.
LM35 is an analog temperature sensor, comes with three pins:
DC supply voltage
analog temperature data out
DC supply ground
The DC supply voltage ranges from +4 V to +30 V. But it is typically supplied at +5 V.
The analog temperature output is +10 mV per degree Celsius. With a 10-bit ADC module of PIC12F685 could precisely convert the analog temperature.
In this application, I use the temperature sensor to condition a DC fan. The fan will turn on if the temperature exceed 30 degree Celsius.
Schematic diagram,
PIC12F683 CPU supplied at +5 V DC, clocked at 4 MHz
internal RC oscillator.
The display system driven by the 74HC595 shift register,
implementing only three MCU pins.
LM35 supplied at +5 V DC, fed the analog temperature
data to the MCU's pin GP4.
A DC fan output controlled by MCU's pin GP5.
It will turn on at the temperature above +30 degree
Celsius.
In this situation the system could only read the non negative temperature data, due to insufficient analog configuration pins.
The source code is written in CCS PICC compiler. The compiler has a lot of libraries. The 74HC595 is implemented with the compiler ready-to-use library.
0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
unsigned int16 converter;
long adcResult;
float temperature;
setup_oscillator(OSC_4MHz);
output_low(FAN);
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);
delay_ms(10);
read_adc(adc_start_only);
while(1){
adcResult=read_adc();
while(!adc_done());
//convert the analog voltage to temperature
temperature = (5.0*adcResult/1024)*1000;
converter=(int16)temperature;
//display the temperature data
shiftData[0]=ssd[converter/1000];
if(converter<1000) shiftData[0]=0;
shiftData[1]=ssd[(converter%1000)/100];
if(converter<100) shiftData[1]=0;
shiftData[2]=ssd[(converter%100)/10]|0x80;
shiftData[3]=ssd[converter%10];
shiftData[4]=0b01100011;
shiftData[5]=0b00111001;
write_expanded_outputs(&shiftData);
//conditioning the fan
if((temperature/10)>30) output_high(FAN);
else output_low(FAN);
delay_ms(1000);
}
}
The overall program require 44% of the 2048 word of the PIC12F683 program memory.
Simulation screen shot,
The temperature reading is 29.7 degree Celsius.
The DC fan is turned off.