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.
In industrial control or consumer electronic product, measuring the temperature is usually required. A thermometer used for measuring the temperature comes with many interfaces, analog and digital interface.
For digital interface there are many options. In this example, I use ds1621 digital thermometer manufactured by Maxim Integrated.
This temperature sensor comes with 8 pin integrated circuit. It is also available in DIP package, a good choice for bread board prototyping and hobbyist. The communication interface is inter integrated circuit.
If we use degree Celsius it could sample the temperature between -55 to +125 degree Celsius with a 0.5 degree Celsius step. Using the Fahrenheit unit equivalence, the temperature sampling ranges from -67 to 257 degree Fahrenheit.
The supply voltage ranges from 2.7 to 5.5 V. In usual prototyping, it's normally supplied at 5 V DC.
Pin diagram of ds1621
Programming interface
Currently of microcontrollers come with a rich of peripherals including the communication interfaces like inter integrated circuit (I2C). For some old age microcontrollers like PIC16F628A, the I2C is absent.
With CCS PICC compiler, the I2C interface could be implemented using I2C module inside the MCU. Anyway, without the I2C module any MCU with sufficient program memory could emulate this interface using an I2C library that use bit banging method.
In this example, the MCU read the temperature data from ds1621 thermometer. Temperature data is displayed on a 16x2 lines character LCD. Timer 0 schedule the temperature reading and displaying for every one minute.
Schematic diagram. CPU clock at 4 MHz. Thermometer connects to PIC16F628A via RA0
and RA1. PortB connects to LCD using 4-bit mode. Clock pins left unconnected due
to 4 MHz internal clock sources is used.
The PICC source code:
#include <16F628A.h>
#fuses INTRC
#use delay(clock=4000000)
//i2c pins
#define DAL_SCL PIN_A0
#define DAL_SDA PIN_A1
//LCD pins
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <ds1621.c>
#include<lcd.c>
BYTE value;
BYTE cntInterrupts=0;
float celsius;
/*this function activates
every one second
*/
void displayResult(void){
value = read_temp();
/*convert to degree Celsius*/
celsius = 5.0*(value-32)/9;
lcd_gotoxy(1,2);
printf(LCD_PUTC,"%.1f degree C\r\n",celsius);
}
void main() {
/*timer 0 is prescaled to 1:256*/
setup_timer_0( RTCC_DIV_256);
/*turn on timer 0 interrupt*/
enable_interrupts(INT_TIMER0);
/*turn on global interrupt control*/
enable_interrupts(GLOBAL);
/*clear timer 0 interrupt flage*/
clear_interrupt(INT_TIMER0);
/*initialize the ds1621 function*/
init_temp();
/*initialize the LCD function*/
lcd_init();
lcd_gotoxy(1,1);
printf(LCD_PUTC,"Temperature: ");
while(1){
/*if it's one second*/
if(cntInterrupts>=15){
displayResult();
cntInterrupts=0;
}
}
}
#INT_TIMER0
void overflowISR(void){
/*Each interrupt occurs every 65 mS*/
cntInterrupts++;
/*Clear flag*/
clear_interrupt(INT_TIMER0);
}
A test program read 27.7 degree Celsius from ds1621 thermometers.
CCS PICC have a ready to use example, demonstrating the technique of using timer 1 external pulses counting to make a 50 MHz frequency meter.
The ex_freq.c explained the the process of making frequency meter using timer 1 of PIC16F877 with a one second delay. The output data is presented in serial terminal.
We can use timer 1 of PIC16F628A to count external digital input pulses. With this advantage, we can make a simple frequency meters, measuring the number of pulses per second.
In this example, I switch the CPU to PIC16F628A with the same build-in timer 1. A 16x2 character LCD uses to present the frequency and period.
PIC16F628A supplied at +5V, clocks at 20 MHz.
Digital Clock pulse feds into pin RB6 Timer 1 Clock In.
SW1 hold the current frequency/period Value,
when shorted to ground
C Source code and simulation file could be download here: