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.
LM35 is an analog temperature sensor creating a linear analog voltage output of 10 mV per degree Celsius with the accuracy of 0.25 degree Celsius. Since the raw temperature data is analog voltage, reading temperature value accomplished by an ADC input of a microcontroller. Reading the temperature from this device is not complex as another digital temperature sensor with SPI, I2C or one-wire protocol.
This temperature sensor supplied the voltage between 4 to 30 V DC. It converts the temperature between -55 to 150 degree Celsius. Since it's linear, the output raw temperature voltage is negative whenever the temperature is below zero degree Celsius. For example, a -1 degree Celsius temperature creates an analog raw temperature voltage output of -0.01 V.
PIC16F88 Programming And Interfacing With CCS PICC
PIC16F88 comes with 10-bit ADC inside. Using a full +5 V voltage reference, the step voltage is 0.0048 V per step of the 1024 digital value. It has seven analog input channels, include it's two external voltage reference pins.
A reference image of PIC16F88-I/P. I posses one's bought from Futurlec.
This 18-pin small embedded controller fit to some small project like here.
Schematic Diagram
From this schematic diagram, I list some basic function of the MCU below.
Creates an output PWM signal from RB0-CCP1 to fed the negative voltage converter. This negative voltage fed the VREF- pin of ADC Module inside the MCU itself. Because we need to read a negative raw voltage temperature data.
Read the temperature voltage from LM35 fed to RA0-AN0, and convert it into a readable value in degree Celsius.
Displays the temperature on a character LCD
Tests the temperature input with the pre-set value store the the EEPROM. When it exceed the pre-set value, a relay driver connects to RA1 is set high. The preset value could be adjust using two buttons connect to RA6 and RA7, respectively.
Since we require two reference voltage VREF+ and VREF-. It's necessary to create a stable DC voltage. In this case, I only use two 2.5 V zener diodes to stabilize two voltage points:
A -2.5 V terminal to fed VREF- pin
A +2.5 V terminal to fed VREF+ pin
Voltage references circuit
A positive +2.5 V reference voltage is created from the positive supply voltage VDD of +5 V. Another negative -2.5 V reference voltage is create from a negative -5 V voltage source. This -5 V voltage source created by the negative voltage creator. It's driven by the PWM signal generated by PIC16F88. The signal is 1 kHz in frequency and 10% duty cycles.
C source code lists below.
#include<16F88.h>
#device adc=10
#fuses INTRC_IO,NOWDT
#use delay(clock=8M)
/*Use CCP1 Module with the frequency of
1 kHz and 50% duty cycle*/
#use pwm(CCP1,FREQUENCY=1000,DUTY=10)
#define LCD_ENABLE_PIN PIN_B3
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include<lcd.c>
#define INC (input(pin_A6))==0
#define DEC (input(pin_A7))==0
int8 temp=0;
char degree=223;
int16 readAdc;
float temperature;
/*A function to read and convert temperature*/
void tempConvert(void){
readadc=read_adc(ADC_START_AND_READ);
while(!adc_done());
temperature=(readadc*5.0)/1024;
temperature=temperature-2.5;
temperature*=100;
lcd_gotoxy(1,2);
printf(LCD_PUTC,"%0.2f %cC",temperature,degree);
}
/*Restore LCD text string*/
void lcdRestore(void){
lcd_gotoxy(1,1);
printf(LCD_PUTC,"Temperature ");
}
/*Display temperature at second line*/
void tempDisplay(void){
lcd_gotoxy(1,1);
printf(LCD_PUTC,"Set Temperature ");
lcd_gotoxy(1,2);
printf(LCD_PUTC,"%d %cC ",temp,degree);
}
/*Setting the temperature point to turn on
fan and store in EEPROM*/
void temperatureSetup(void){
/*Increment*/
if(INC){
temp+=1;
tempDisplay();
write_eeprom(0,temp);
delay_ms(500);
lcdRestore();
}
/*Decrement*/
if(DEC){
temp-=1;
tempDisplay();
write_eeprom(0,temp);
delay_ms(500);
lcdRestore();
}
}
void main(void){
int16 tempSetter;
/*Optional parameter for setting up
the internal oscillator*/
setup_oscillator(OSC_8MHz);
output_B(0x00);
output_A(0x00);
/*RA1 is output*/
set_tris_A(0xFD);
set_tris_b(0x00);
lcd_init();
pwm_on();
setup_adc_ports(sAN0|VREF_VREF);
setup_adc(adc_clock_internal);
set_adc_channel(0);
delay_ms(100);
lcdRestore();
delay_ms(100);
temp=read_eeprom(0);
while(1){
tempConvert();
temperatureSetup();
tempSetter=(int)temperature;
if(tempSetter>temp) output_high(pin_A1);
else output_low(pin_A1);
delay_ms(50);
}
}
I made a screen copy of this program.
A screen shot of this program
The overall program requires 50% of Flash memory and 12% of on-chip RAM. For more efficiency, choosing another MCU with smaller flash size is a good option.