SlideShare a Scribd company logo
1 of 46
Download to read offline
Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
CHAFIC’S ELECTRO-MECH TECHNICAL SOLUTIONS
SolarPowerRegulator
User’sManual
Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
By: Chafic Bouchakra
Submitted to: Stephen Ryan
ELN9204
Section: 010
Date: April 21, 2015
Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
Table of Contents
Section Page
1.0 General Information................................................................................................................... 1
1.0 general information............................................................................................................................ 2
1.1 System Overview................................................................................................................................ 2
1.2 Point of Contact.................................................................................................................................. 2
1.3 Organization of the Manual ............................................................................................................... 2
2.0 System Summary ...............................................................................................................3
2.0 System Summary................................................................................................................................ 4
2.1 Hardware............................................................................................................................................ 4
2.2 Software ............................................................................................................................................. 4
2.3 Computer ........................................................................................................................................... 4
3.0 Visuals of the Hardware .....................................................................................................5
3.0 Containment Unit............................................................................................................................... 6
3.1 Main Circuit Board.............................................................................................................................. 6
3.2 Clock Chip Circuit Board..................................................................................................................... 7
3.3 Temperature Chip Circuit Board ........................................................................................................ 7
4.0 Electrical Circuit Schematic........................................................................................................ 8
4.0 Schematic ........................................................................................................................................... 9
5.0 Issues and Limitations................................................................................................................ 10
5.0 Hardware............................................................................................................................................ 11
5.1 Software ............................................................................................................................................. 11
6.0 Program Flowchart..................................................................................................................... 12
6.0 Software Flowchart ............................................................................................................................ 13
7.0 Program Code............................................................................................................................. 14
7.0 Main Program..................................................................................................................................... 15
7.1 Switchc program................................................................................................................................. 18
7.2 KBD_press Program............................................................................................................................ 20
7.3 Set_time Program .............................................................................................................................. 22
7.4 BCD Program ...................................................................................................................................... 24
7.5 Init_time Program .............................................................................................................................. 26
7.6 Init_rtc Program ................................................................................................................................. 29
7.7 Init_KBD Program............................................................................................................................... 33
7.8 Init_LCD Program ............................................................................................................................... 37
7.9 Prototype.H Program ......................................................................................................................... 42
1.0 General Information
Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 Page 1
1.0 General Information
1.0 General Information
Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 Page 2
1.0 GENERAL INFORMATION
This product is a solar power regulator that is installed as a bridge point between your active solar panels and the power contain-
ment unit (PCU) (or in other terms the battery pack). It is designed to monitor the voltage flow between the panels and the PCU,
displaying live updates on the LCD screen. It has the functionality to power on an internal fan to the PCU to keep it under a spe-
cific temperature threshold and to disconnect the voltage line of between the panels and the PCU if the intake voltage exceeds
the recommended voltage of the PCU or the temperature of the PCU exceeds the critical threshold.
1.1 System Overview
This solar power regulator is a self contained unit and required no additional hardware or wiring to be fully operational*.
It has a built in LCD screen, and can be either powered with batteries or an external power source.
Using a PIC16F877A Microcontroller chip this solar power regulator is designed monitor and control the flow of electricity to the
PCU while monitoring the internal temperature of the PCU.
The LCD screen on the regulator displays the time of day using the clock chip, while continuously displaying the live voltage, and
amp readings of the flow of electricity from the panel, and displays the live temperature reading of the internal PCU. While con-
tinuously checking the voltage and temperature, the internal programming will trigger the relays to disconnect the power if the
voltage or temperature exceeds the allowable threshold** in addition it powers on a fan in the PCU to maintain a suitable tem-
perature range. The voltage relay can be reset using the user interface after the manual reset button is pressed.
This product is fully operational.
*Additional hardware and software may be required to modify the programming or create a personalized custom configuration.
**The thresholds are default set to 12 volts, for the power and 80° F for the temperature. The thresholds may be reprogrammed
through the computer, using the required software and hardware (not included).
1.2 Point of Contact
At any point if you require additional assistance in the setup, programming or trouble shooting of the Solar Power Regulator, you
may contact our lead technician Chafic directly at 613-864-4454 or via email him at bouc0261@algonquinlive.com.
1.3 Organization of the Manual
This user’s manual consists of 7 sections: General Information. System Summary, Visuals of the Hardware, Electrical Circuit Sche-
matic, Issues and Limitations, Program Flowchart, and Program Code.
General Information sections explains the system, the purpose and gives contact information where more information can be
found.
System Summary section gives a quick rundown on how the program works, and lists the requirements for the hardware and
software to troubleshoot and reprogram the chip.
Visuals of the Hardware section shows the actual parts built and what the Solar Power Regulator looks like inside and out.
Electrical Circuit Schematic section shows the entire Schematic for the Solar Power Regulator.
Issues and Limitations section outlines any issues I had with the project and limitations for both the hardware and software.
Program Flowchart section is a visual display of how the program is expected to run in a flowchart form.
Program Code section is the coding for the main program and any subprograms that are required to run the regulator.
2.0 System Summary
Page 3Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
2.0 System Summary
2.0 System Summary
Page 4Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
2.1 Hardware
 1 - PIC16F877A
 1 - NE555N - Timer Chip
 1 - 6355ED - Serial I/O Real Time Clock
 1 - DS1631 - Temperature Chip
 1 - 4X3 Keypad
 1 - FOX - 20.0MHz Crystal Oscillator
 2 - 7805CT - 5 Volt Regulator
 1 - 7809CT - 9 Volt Regulator
 1 - JHD 162A - 2X16 LCD Screen
 2 - 100kΩ Resistor
 1 - 22kΩ Resistor
 1 - 20kΩ Resistor
 6 - 10kΩ Resistor
 1 - 2kΩ Resistor
 4 - 1kΩ Resistor
 1 - 330Ω Resistor
 1 - 10Ω Resistor
 1 - 10KΩ Potentiometer
 1 - 100μF Capacitor
 1 - 0.01μF Capacitor
 1 - 0.001μF Capacitor
 2 - 3904 Transistor
 4 - IN5231B - Zener Diode
 2- HLS-4078-DC5V - Relay
 1 - Push Button Switch
 3 - 9V Battery Connectors
 3 - 9V Battery
 1 - 9V DC Fan
2.2 Software
 PIC C Compiler
 PICkit 2
2.3 Computer
Minimum Requirements:
 Pentium 1 Processor
 Keyboard
 Monitor
 80 GB of storage Space
2.0 SYSTEM SUMMARY
When the Regulator is initialized it will ask you for the hour and than the minute, input the time using the keypad. It will then auto-
matically show your all the data. If it enters critical mode it will tell you to press ’*’ to reset, all you have to do then it hit ’*’ on the
keypad after you checked to see that the voltage is level and it will reset the voltage connection. The voltage connection will not
reset if the voltage and/or temperature are still past the threshold.
3.0 Visuals of the Hardware
Page 5Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
3.0 Visuals of the hardware
3.0 Visuals of the Hardware
Page 6Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
3.0 Containment Unit
This is the visual of the external containment unit.
The LCD, reset push button, keypad, visual LED and voltage
intake are all easily accessible.
Has a slot to include access to a temperature chip to meas-
ure temperature of the units environment.
3.1 Main Circuit Board
This is the main circuit PCB board it contains the microcon-
troller, it’s own 5 volt power supply, and a 9 volt power
supply to power the fan. The two relays to cut the intake
voltage and power the fan. Control the contras of the LCD
with the potentiometer on this board
All other components connect to this board.
3.0 Visuals of the Hardware
Page 7Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
3.2 Clock Chip Circuit Board
This is the 6355ED - Serial I/O Real Time Clock circuit board
with the NE555N timer.
This has its own 5 volt closed circuit power to reduce noise
caused by the NE555N timer to the rest of the circuits.
3.3 Temperature Chip Circuit Board
This is the DS1631 - Temperature Chip circuit board, It is
separated from the rest so that it can be placed within the
PCU to read its internal temperature.
4.0 Electrical Circuit Schematic
Page 8Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
4.0 Electrical circuit Schematic
4.0 Electrical Circuit Schematic
Page 9Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
5.0 Issues and Limitations
Page 10Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
5.0 Issues and Limitations
5.0 Issues and Limitations
Page 11Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
5.0 Hardware
Quick steps to ensure you do not run into any issues with the hardware and ways to figure out how to determine what the problem
is.
A chip is not working properly?
 Check power supply
 Check wiring
 Check for cold and incomplete solders
 Ensure any transistors and/or diodes are facing the right direction
Best way to determine if a specific chip or section of your circuit is working is by building it in bits and pieces and making sure it
works before adding the next section.
Test any questionable parts in a working circuit with the proper programming to ensure that it is functioning properly otherwise
replace the part.
Having the LCD wired with all 8 data pins reduced the number of ports on the PIC16 that can be used for other hardware. Reducing
the number of pins to 4 and changing the programming allows more peripherals on the PIC
I had issues getting the NE555N Timer to meet the required frequency (32.768KHz) with a duty cycle above 50% with the specific
timer circuit that was built in this project. As the 6355ED seconds need that frequency to give out accurate time readings. My sug-
gestion for this is get a proper crystal oscillator that runs at that frequency or find a clock chip with a built in precise oscillator.
5.1 Software
Space... The biggest limiting factor with the PIC and software, ensuring the software all fit within the total Rom space was essential.
Changing values and using int and char helped to save space.
Printf statements required tremendous amounts of space so limiting those is essential.
Using the switch program to when thresholds were triggered ensured flawless transition into different modes.
Breaking out of switch modes was a challenge as creating a kbd_press program was essential to create that pause in the program
to wait for a user to reset the program.
Putting the Init files on a separate chip to initialize the LCD, 6355ED, and DS1631, would save you tons of space as well, as long as
those parts maintain power and do not turn on. Which makes it very challenging to do this with this setup. So in this project they
had to stay on the main chip for simplicity and time sake, which meant I was highly limited in the complexity and depth of this soft-
ware.
6.0 Program Flowchart
Page 12Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
6.0 Program Flowchart
6.0 Program Flowchart
Page 13Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 14Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
7.0 Program Code
Page 15Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 16Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
#include <prototype.h>
#include <ds1631.c>
#include <nju6355.c>
#include <stdlib.h>
/***************************************************************************
Main Program
***************************************************************************/
void main()
{
int hour, min, sec, last_sec, volt, curr; // Sets Int for; hour, min, sec, last_sec, volt, curr
unsigned long int voltage_reading, current_reading; // Sets Unsigned long int for; voltage_reading, current_reading
unsigned long int value=0; // Sets unsigned long int for value
lcd_init(); // Initialized LCD
kbd_init (); // Initialized keypad
rtc_init (); // Initialized clock chip
init_temp(); // Initialized temperature chip
set_time (); // Prompts set time sequence
while(1) // While true execute this Loop
{
rtc_get_time (hour, min, sec ); // Retrieves time from chip
if (( sec!=last_sec )) // If Sec does not equal Last_sec then execute the following loop
{
set_adc_channel ( 1 ); // Sets Channel to Port A1
delay_us (10); // Delays 10 µs
voltage_reading = read_adc (); // Reads Voltage from A1
delay_us (10); // Delay 10 µs
volt = ((voltage_reading*12)/100) ; // Converts Voltage Reading to User Readable Number
// Sets Readable Number as Volt Int
set_adc_channel ( 3 ); // Sets Channel to Port A3
delay_us (10); // Delays 10 µs
current_reading = read_adc (); // Reads Current from A3
delay_us (10); // Delays 10 µs
7.0 Program Code
Page 17Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
curr = ((current_reading*12)/1000); // Converts Current Reading to User Readable Number
// Sets Readable Number as Curr Int
value = read_full_temp (); // Sets temp reading as value
value /= 100;
delay_ms (100); // Delay 100 ms
printf (lcd_putc, "f%c%c:%c%c:%c%c ", // Displays time on the LCD
display_first_bcd ( hour), display_second_bcd (hour),
display_first_bcd (min), display_second_bcd (min),
display_first_bcd (sec), display_second_bcd (sec));
printf (lcd_putc, "nTemp%4.2ld ", value); // Displays temp on LCD
printf (lcd_putc, "t %d V ", volt); // Displays volt on LCD
printf (lcd_putc, "U %d mA ", curr); // Displays curr on LCD
last_sec = sec; // Sets Last_sec as the Current Sec
If (volt >= 12) // If volt >= 12 then Switchc case 0 is activated
{
Switchc (0);
}
If (value >= 78) // If temp value >= 78 then fan turns ON
{
output_high (Pin_D0);
}
If (value >= 80) // If temp value >= 80 then Switchc case 1 is activated
{
Switchc (1);
}
if (value <= 77) // If temp value <= 77 then fan turns OFF
{
Output_low (Pin_D0);
}
}
}
}
7.0 Program Code
Page 18Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 19Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
Switch Program for "Voltage Overload" and "Temperature Crititcal"
***************************************************************************/
void Switchc ( int SC )
{
switch ( SC )
{
case 0:
{ // Case 0
Output_high (Pin_A2); // Disconnects input voltage
Printf (lcd_putc, "b****Overload****"); // Displays on LCD
Printf (lcd_putc, "nPress * to reset"); // Displays on LCD
Kbd_press (); // Waits for * to be pressed on keypad
Output_low (Pin_A2); // Reconnects input voltage
break; // Returns to main program
}
case 1:
{ // Case 1
Output_high (Pin_A2); // Disconnects input voltage
Output_high (Pin_D0); // Turn fan ON
Printf (lcd_putc, "b Temp CRITICAL"); // Displays on LCD
Printf (lcd_putc, "nPress * to reset"); // Displays on LCD
Kbd_press (); // Waits for * to be pressed on keypad
Output_low (Pin_D0); // Turns fan OFF
Output_low (Pin_A2); // Reconnects input voltage
break; // Returns to main program
}
}
}
7.0 Program Code
Page 20Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 21Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
Kbd_press
Here the program will cycle in a blank loop waiting for * to be pressed then
released before going back to the previous program
***************************************************************************/
void Kbd_press (void)
{
while(kbd_getc () != '*') // While * is not press, closed loop rotation
{
}
while(kbd_getc () == '*') // While * is press, closed loop rotation
{
} // Once * is released, breaks out of Kbd_press.
} // Returns to previous program
7.0 Program Code
Page 22Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 23Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
Set Time
***************************************************************************/
void set_time ()
{
int hour, min; // Sets hour, min as an Int value
Delay_ms (500);
printf ( lcd_putc, "bHour: "); hour = get_bcd();
printf ( lcd_putc, "bMin: " ); min = get_bcd ();
rtc_set_datetime ( 0, 0, 0, 0, hour, min );
} // end void set_time
char display_first_bcd (byte n )
{
return n/16+'0' ;
} // end char display_first_bcd
char display_second_bcd (byte n )
{
return n%16+'0';
} // end char display_second_bcd
7.0 Program Code
Page 24Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 25Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
BCD
***************************************************************************/
byte get_bcd()
{
char first, second;
do
{
first=kbd_getc(); // Note first is gathered from kbd_getc() Keypad Press
} while ((first<'0') || (first>'9'));
putc(first);
do
{
second=kbd_getc(); // Note first is gathered from kbd_getc() Keypad Press
} while ((second<'0') || (second>'9') && (second!='r'));
putchar(second);
if (second=='r')
return (first-'0');
else
return (((first-'0') << 4) | (second-'0'));
}
void display_bcd (byte n )
{
putc ( n/16+'0' );
putc ( n%16+'0' );
}
7.0 Program Code
Page 26Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 27Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
#ifndef DAL_SCL
#define DAL_SCL PIN_E1
#define DAL_SDA PIN_E0
#endif
#define read_temp read_full_temp // for backwards compatability
#use i2c(master, sda=DAL_SDA, scl=DAL_SCL)
void temp_config(BYTE data)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xac);
i2c_write(data);
i2c_stop();
}
void init_temp()
{
output_high(DAL_SDA);
output_high(DAL_SCL);
i2c_start();
i2c_write(0x90);
i2c_write(0x51);
i2c_stop();
temp_config(0xc);
}
signed long read_full_temp()
{ // Returns hundreths of degrees F (-67 to 257)
signed int datah, datal;
signed long data;
i2c_start();
i2c_write(0x90);
7.0 Program Code
Page 28Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
i2c_write(0xaa);
i2c_start();
i2c_write(0x91);
datah=i2c_read();
datal=i2c_read(0);
i2c_stop();
data=(signed long)datah*100;
data=data+(((datal >> 4 )*(long)50)/16);
data=data*9;
data = (data / 5) + 3200;
return(data);
}
7.0 Program Code
Page 29Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 30Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
#ifndef RTC_DATA // If RTC_DATA defined set pins
#define RTC_DATA PIN_B0 // Data pin to port B0
#define RTC_CLK PIN_C4 // CLK pin to port C4
#define RTC_CE PIN_D3 // CD pin to port D3
#define RTC_IO PIN_D2 // IO pin to port D2
#endif // end if
void rtc_init() {
output_low(RTC_CE);
output_low(RTC_IO);
}
void write_rtc_byte(BYTE data_byte, BYTE number_of_bits) {
BYTE i;
for(i=0; i<number_of_bits; ++i) {
if((data_byte & 1)==0)
output_low(RTC_DATA);
else
output_high(RTC_DATA);
data_byte=data_byte>>1;
output_high(RTC_CLK);
output_low(RTC_CLK);
}
}
BYTE read_rtc_byte(BYTE number_of_bits) {
BYTE i,data;
for(i=0;i<number_of_bits;++i) {
output_high(RTC_CLK);
shift_right(&data,1,input(RTC_DATA));
output_low(RTC_CLK);
}
return(data);
}
void rtc_set_datetime(BYTE day, BYTE mth, BYTE year, BYTE dow,
7.0 Program Code
Page 31Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
BYTE hour, BYTE min){
output_low(RTC_CLK);
output_high(RTC_IO);
output_high(RTC_CE);
write_rtc_byte(year,8);
write_rtc_byte(mth,8);
write_rtc_byte(day,8);
write_rtc_byte(dow,4);
write_rtc_byte(hour,8);
write_rtc_byte(min,8);
output_low(RTC_CE);
output_low(RTC_IO);
}
void rtc_get_date(BYTE& day, BYTE& mth, BYTE& year, BYTE& dow) {
output_low(RTC_CLK);
output_low(RTC_IO);
output_high(RTC_CE);
year=read_rtc_byte(8);
mth=read_rtc_byte(8);
day=read_rtc_byte(8);
dow=read_rtc_byte(4)>>4;
read_rtc_byte(8*3);
output_low(RTC_CE);
output_low(RTC_IO);
}
void rtc_get_time(BYTE& hr, BYTE& min, BYTE& sec) {
output_low(RTC_CLK);
output_low(RTC_IO);
output_high(RTC_CE);
read_rtc_byte(8*3+4);
hr=read_rtc_byte(8);
min=read_rtc_byte(8);
7.0 Program Code
Page 32Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
sec=read_rtc_byte(8);
output_low(RTC_CE);
output_low(RTC_IO);
}
7.0 Program Code
Page 33Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 34Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
Kbd Initialization Program
Defines Keypad Buttons
***************************************************************************/
#define col0 PIN_B3
#define col1 PIN_B2
#define col2 PIN_B1
#define row0 PIN_B7
#define row1 PIN_B6
#define row2 PIN_B5
#define row3 PIN_B4
char const KEYS[4][3] = {{'1','2','3'}, // Keypad layout:
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second
void kbd_init() {}
short int ALL_ROWS (void)
{
if (input (row0) & input (row1) & input (row2) & input (row3))
return (0);
else
return (1);
}
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
7.0 Program Code
Page 35Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
byte kchar;
byte row;
kchar='0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
switch (col) {
case 0 : output_low(col0);
output_high(col1);
output_high(col2);
break;
case 1 : output_high(col0);
output_low(col1);
output_high(col2);
break;
case 2 : output_high(col0);
output_high(col1);
output_low(col2);
break;
}
if(kbd_down)
{
if(!ALL_ROWS())
{
kbd_down=false;
kchar=last_key;
last_key='0';
}
}
else
{
if(ALL_ROWS())
{
if(!input (row0))
row=0;
7.0 Program Code
Page 36Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
else if(!input (row1))
row=1;
else if(!input (row2))
row=2;
else if(!input (row3))
row=3;
last_key =KEYS[row][col];
kbd_down = true;
}
else
{
++col;
if(col==3)
col=0;
}
}
kbd_call_count=0;
}
return(kchar);
}
7.0 Program Code
Page 37Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 38Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
/***************************************************************************
Define Ports for LCD
***************************************************************************/
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_C5
#define LCD_RS PIN_C1
#define lcd_line_two 0x40
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
/***************************************************************************
int const LCD_INIT_STRING[5]
***************************************************************************/
int const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
void lcd_send_nibble(int8 nibble)
{ // Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
7.0 Program Code
Page 39Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
}
/***************************************************************************
void lcd_send_byte(int address, int n)
***************************************************************************/
void lcd_send_byte(int address, int n)
{
output_low (LCD_RS);
delay_us (60);
if(address)
output_high (LCD_RS);
else
output_low (LCD_RS);
output_low(LCD_E);
delay_cycles(1);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
} // end lcd_send_byte
/***************************************************************************
void lcd_init(void)
***************************************************************************/
void lcd_init(void)
{
int i;
output_low(LCD_RS);
output_low(LCD_E);
delay_ms(15);
7.0 Program Code
Page 40Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
} // end for
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
} // end for
} // end lcd_init
/***************************************************************************
void lcd_putc(char c)
***************************************************************************/
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
if(y != 1)
address = lcd_line_two;
else
address=0;
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
void lcd_putc(char c)
{
switch(c)
{
7.0 Program Code
Page 41Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
case 'b':
lcd_send_byte(0,1);
delay_ms(2);
break;
case 'f':
lcd_send_byte(0, 0x80 );
break;
case 'n':
lcd_send_byte(0, 0xc0 );
break;
case 't':
lcd_send_byte(0, 0x89 );
break;
case 'U':
lcd_send_byte(0, 0xc9 );
break;
default:
lcd_send_byte(1,c);
break;
} // end switch
} // end lcd_putc
7.0 Program Code
Page 42Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
7.0 Program Code
Page 43Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
#include <16f877A.h>
#fuses HS, NOLVP, NOWDT, PUT
#use delay ( clock = 20000000 )
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)

More Related Content

What's hot

Motorola solutions ap622 access point installation guide (part no. 72 e 15780...
Motorola solutions ap622 access point installation guide (part no. 72 e 15780...Motorola solutions ap622 access point installation guide (part no. 72 e 15780...
Motorola solutions ap622 access point installation guide (part no. 72 e 15780...Advantec Distribution
 
BLDC Motor Speed Control With RPM Display
 BLDC Motor Speed Control With RPM Display BLDC Motor Speed Control With RPM Display
BLDC Motor Speed Control With RPM DisplayEdgefxkits & Solutions
 
Manual de Danfoss 2800
Manual de Danfoss 2800Manual de Danfoss 2800
Manual de Danfoss 2800Camilo Avelino
 
E bike bldc motor test set up
E bike bldc motor test set upE bike bldc motor test set up
E bike bldc motor test set upDhaneshwar Patil
 
Speed and direction control of dc motor using android mobile application chan...
Speed and direction control of dc motor using android mobile application chan...Speed and direction control of dc motor using android mobile application chan...
Speed and direction control of dc motor using android mobile application chan...chandan kumar
 
Real Time Monitoring And Controlling System
Real Time Monitoring And Controlling SystemReal Time Monitoring And Controlling System
Real Time Monitoring And Controlling Systemtheijes
 
A review paper on closed loop control of bldc motor using fuzzy logic
A review paper on closed loop control of bldc motor using fuzzy logicA review paper on closed loop control of bldc motor using fuzzy logic
A review paper on closed loop control of bldc motor using fuzzy logicIRJET Journal
 
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...IRJET - PLC based Temperature Controlling using Peltier Element for Industria...
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...IRJET Journal
 
Speed Control of Induction Motor Using PLC and SCADA System
Speed Control of Induction Motor Using PLC and SCADA SystemSpeed Control of Induction Motor Using PLC and SCADA System
Speed Control of Induction Motor Using PLC and SCADA SystemIJERA Editor
 
Intelligent mcc Siemens
Intelligent mcc Siemens Intelligent mcc Siemens
Intelligent mcc Siemens Praveen Patil
 
Drives and motors 2014
Drives and motors 2014Drives and motors 2014
Drives and motors 2014thanhtanbinh
 
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...ijistjournal
 
Speed control of single phase induction motor by android bluetooth
Speed control of single phase induction motor by android bluetoothSpeed control of single phase induction motor by android bluetooth
Speed control of single phase induction motor by android bluetoothIRJET Journal
 
Applied motion products txm24 rs232 485 brochure
Applied motion products txm24 rs232 485 brochureApplied motion products txm24 rs232 485 brochure
Applied motion products txm24 rs232 485 brochureElectromate
 
IRJET - Speed Control of DC Motor by using IoT
IRJET -  	  Speed Control of DC Motor by using IoTIRJET -  	  Speed Control of DC Motor by using IoT
IRJET - Speed Control of DC Motor by using IoTIRJET Journal
 

What's hot (20)

Motorola solutions ap622 access point installation guide (part no. 72 e 15780...
Motorola solutions ap622 access point installation guide (part no. 72 e 15780...Motorola solutions ap622 access point installation guide (part no. 72 e 15780...
Motorola solutions ap622 access point installation guide (part no. 72 e 15780...
 
BLDC Motor Speed Control With RPM Display
 BLDC Motor Speed Control With RPM Display BLDC Motor Speed Control With RPM Display
BLDC Motor Speed Control With RPM Display
 
Eaton epdu-power-distribution-units
Eaton epdu-power-distribution-unitsEaton epdu-power-distribution-units
Eaton epdu-power-distribution-units
 
Manual de Danfoss 2800
Manual de Danfoss 2800Manual de Danfoss 2800
Manual de Danfoss 2800
 
E bike bldc motor test set up
E bike bldc motor test set upE bike bldc motor test set up
E bike bldc motor test set up
 
Speed and direction control of dc motor using android mobile application chan...
Speed and direction control of dc motor using android mobile application chan...Speed and direction control of dc motor using android mobile application chan...
Speed and direction control of dc motor using android mobile application chan...
 
Real Time Monitoring And Controlling System
Real Time Monitoring And Controlling SystemReal Time Monitoring And Controlling System
Real Time Monitoring And Controlling System
 
slua748[1]
slua748[1]slua748[1]
slua748[1]
 
A review paper on closed loop control of bldc motor using fuzzy logic
A review paper on closed loop control of bldc motor using fuzzy logicA review paper on closed loop control of bldc motor using fuzzy logic
A review paper on closed loop control of bldc motor using fuzzy logic
 
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...IRJET - PLC based Temperature Controlling using Peltier Element for Industria...
IRJET - PLC based Temperature Controlling using Peltier Element for Industria...
 
Speed Control of Induction Motor Using PLC and SCADA System
Speed Control of Induction Motor Using PLC and SCADA SystemSpeed Control of Induction Motor Using PLC and SCADA System
Speed Control of Induction Motor Using PLC and SCADA System
 
Intelligent mcc Siemens
Intelligent mcc Siemens Intelligent mcc Siemens
Intelligent mcc Siemens
 
Drives and motors 2014
Drives and motors 2014Drives and motors 2014
Drives and motors 2014
 
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...
DESIGN AND DEVELOPMENT OF A LOW-COST MICROCONTROLLER BASED SINGLE PHASE WATER...
 
Speed control of single phase induction motor by android bluetooth
Speed control of single phase induction motor by android bluetoothSpeed control of single phase induction motor by android bluetooth
Speed control of single phase induction motor by android bluetooth
 
40120140501001
4012014050100140120140501001
40120140501001
 
B43050518
B43050518B43050518
B43050518
 
Manual tvoc 2
Manual tvoc 2Manual tvoc 2
Manual tvoc 2
 
Applied motion products txm24 rs232 485 brochure
Applied motion products txm24 rs232 485 brochureApplied motion products txm24 rs232 485 brochure
Applied motion products txm24 rs232 485 brochure
 
IRJET - Speed Control of DC Motor by using IoT
IRJET -  	  Speed Control of DC Motor by using IoTIRJET -  	  Speed Control of DC Motor by using IoT
IRJET - Speed Control of DC Motor by using IoT
 

Similar to User Manual - Final Project 2015

Danfoss vlt fc 101 programming guide
Danfoss vlt fc 101 programming guideDanfoss vlt fc 101 programming guide
Danfoss vlt fc 101 programming guideAnton Dlabač
 
PICOSOFT Controller Book by Allen-Bradley Rockwell Automation
PICOSOFT Controller Book by Allen-Bradley Rockwell AutomationPICOSOFT Controller Book by Allen-Bradley Rockwell Automation
PICOSOFT Controller Book by Allen-Bradley Rockwell AutomationJerwin Lopez
 
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...Pradeep Avanigadda
 
Automation of Instrument Air Distribution System using Arduino and Integrate ...
Automation of Instrument Air Distribution System using Arduino and Integrate ...Automation of Instrument Air Distribution System using Arduino and Integrate ...
Automation of Instrument Air Distribution System using Arduino and Integrate ...IRJET Journal
 
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLER
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLERSOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLER
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLERIRJET Journal
 
Q45S-Wet-H2S-OandM-Manual-Line.pdf
Q45S-Wet-H2S-OandM-Manual-Line.pdfQ45S-Wet-H2S-OandM-Manual-Line.pdf
Q45S-Wet-H2S-OandM-Manual-Line.pdfENVIMART
 
Nwa 6281 manual-20110816
Nwa 6281 manual-20110816Nwa 6281 manual-20110816
Nwa 6281 manual-20110816Yong-uk Choe
 
Temperature monitoring and controling using arduino
Temperature monitoring and controling using arduinoTemperature monitoring and controling using arduino
Temperature monitoring and controling using arduinoBablu Singh
 
Applied motion products ssm brochure
Applied motion products ssm brochureApplied motion products ssm brochure
Applied motion products ssm brochureElectromate
 
Applied motion products txm24 c brochure
Applied motion products txm24 c brochureApplied motion products txm24 c brochure
Applied motion products txm24 c brochureElectromate
 
Stepper Motor Control System
Stepper Motor Control SystemStepper Motor Control System
Stepper Motor Control SystemWanita Long
 
POWER CONSUMPTION DETECTING AND ALERTING SYSTEM
POWER CONSUMPTION DETECTING AND ALERTING SYSTEMPOWER CONSUMPTION DETECTING AND ALERTING SYSTEM
POWER CONSUMPTION DETECTING AND ALERTING SYSTEMIRJET Journal
 
IRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge ControllerIRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge ControllerIRJET Journal
 
Report on remote control home appliances.
Report on remote control home appliances.Report on remote control home appliances.
Report on remote control home appliances.Sonal Bansal
 
IRJET-Static Voltage Stabilizer
IRJET-Static Voltage StabilizerIRJET-Static Voltage Stabilizer
IRJET-Static Voltage StabilizerIRJET Journal
 

Similar to User Manual - Final Project 2015 (20)

Q gx developer_e
Q gx developer_eQ gx developer_e
Q gx developer_e
 
Danfoss vlt fc 101 programming guide
Danfoss vlt fc 101 programming guideDanfoss vlt fc 101 programming guide
Danfoss vlt fc 101 programming guide
 
PICOSOFT Controller Book by Allen-Bradley Rockwell Automation
PICOSOFT Controller Book by Allen-Bradley Rockwell AutomationPICOSOFT Controller Book by Allen-Bradley Rockwell Automation
PICOSOFT Controller Book by Allen-Bradley Rockwell Automation
 
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...
DETECTING POWER GRID SYNCHRONISATION FAILURE ON SENSING BAD VOLTAGE OR FREQUE...
 
P7 user manual
P7 user manualP7 user manual
P7 user manual
 
Automation of Instrument Air Distribution System using Arduino and Integrate ...
Automation of Instrument Air Distribution System using Arduino and Integrate ...Automation of Instrument Air Distribution System using Arduino and Integrate ...
Automation of Instrument Air Distribution System using Arduino and Integrate ...
 
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLER
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLERSOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLER
SOLAR ENERGY MEASUREMENT USING PIC MICROCONTROLLER
 
Sinamics g120 treinamento (en)
Sinamics g120 treinamento (en)Sinamics g120 treinamento (en)
Sinamics g120 treinamento (en)
 
Tài liệu đào tạo simens sinamic G120
Tài liệu đào tạo simens sinamic G120Tài liệu đào tạo simens sinamic G120
Tài liệu đào tạo simens sinamic G120
 
Q45S-Wet-H2S-OandM-Manual-Line.pdf
Q45S-Wet-H2S-OandM-Manual-Line.pdfQ45S-Wet-H2S-OandM-Manual-Line.pdf
Q45S-Wet-H2S-OandM-Manual-Line.pdf
 
Nwa 6281 manual-20110816
Nwa 6281 manual-20110816Nwa 6281 manual-20110816
Nwa 6281 manual-20110816
 
Plasma 2012 AH Controller Manual
Plasma 2012 AH Controller ManualPlasma 2012 AH Controller Manual
Plasma 2012 AH Controller Manual
 
Temperature monitoring and controling using arduino
Temperature monitoring and controling using arduinoTemperature monitoring and controling using arduino
Temperature monitoring and controling using arduino
 
Applied motion products ssm brochure
Applied motion products ssm brochureApplied motion products ssm brochure
Applied motion products ssm brochure
 
Applied motion products txm24 c brochure
Applied motion products txm24 c brochureApplied motion products txm24 c brochure
Applied motion products txm24 c brochure
 
Stepper Motor Control System
Stepper Motor Control SystemStepper Motor Control System
Stepper Motor Control System
 
POWER CONSUMPTION DETECTING AND ALERTING SYSTEM
POWER CONSUMPTION DETECTING AND ALERTING SYSTEMPOWER CONSUMPTION DETECTING AND ALERTING SYSTEM
POWER CONSUMPTION DETECTING AND ALERTING SYSTEM
 
IRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge ControllerIRJET- Design and Implementation of Solar Charge Controller
IRJET- Design and Implementation of Solar Charge Controller
 
Report on remote control home appliances.
Report on remote control home appliances.Report on remote control home appliances.
Report on remote control home appliances.
 
IRJET-Static Voltage Stabilizer
IRJET-Static Voltage StabilizerIRJET-Static Voltage Stabilizer
IRJET-Static Voltage Stabilizer
 

User Manual - Final Project 2015

  • 1. Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 CHAFIC’S ELECTRO-MECH TECHNICAL SOLUTIONS SolarPowerRegulator User’sManual
  • 2. Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 By: Chafic Bouchakra Submitted to: Stephen Ryan ELN9204 Section: 010 Date: April 21, 2015
  • 3. Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 Table of Contents Section Page 1.0 General Information................................................................................................................... 1 1.0 general information............................................................................................................................ 2 1.1 System Overview................................................................................................................................ 2 1.2 Point of Contact.................................................................................................................................. 2 1.3 Organization of the Manual ............................................................................................................... 2 2.0 System Summary ...............................................................................................................3 2.0 System Summary................................................................................................................................ 4 2.1 Hardware............................................................................................................................................ 4 2.2 Software ............................................................................................................................................. 4 2.3 Computer ........................................................................................................................................... 4 3.0 Visuals of the Hardware .....................................................................................................5 3.0 Containment Unit............................................................................................................................... 6 3.1 Main Circuit Board.............................................................................................................................. 6 3.2 Clock Chip Circuit Board..................................................................................................................... 7 3.3 Temperature Chip Circuit Board ........................................................................................................ 7 4.0 Electrical Circuit Schematic........................................................................................................ 8 4.0 Schematic ........................................................................................................................................... 9 5.0 Issues and Limitations................................................................................................................ 10 5.0 Hardware............................................................................................................................................ 11 5.1 Software ............................................................................................................................................. 11 6.0 Program Flowchart..................................................................................................................... 12 6.0 Software Flowchart ............................................................................................................................ 13 7.0 Program Code............................................................................................................................. 14 7.0 Main Program..................................................................................................................................... 15 7.1 Switchc program................................................................................................................................. 18 7.2 KBD_press Program............................................................................................................................ 20 7.3 Set_time Program .............................................................................................................................. 22 7.4 BCD Program ...................................................................................................................................... 24 7.5 Init_time Program .............................................................................................................................. 26 7.6 Init_rtc Program ................................................................................................................................. 29 7.7 Init_KBD Program............................................................................................................................... 33 7.8 Init_LCD Program ............................................................................................................................... 37 7.9 Prototype.H Program ......................................................................................................................... 42
  • 4. 1.0 General Information Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 Page 1 1.0 General Information
  • 5. 1.0 General Information Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 Page 2 1.0 GENERAL INFORMATION This product is a solar power regulator that is installed as a bridge point between your active solar panels and the power contain- ment unit (PCU) (or in other terms the battery pack). It is designed to monitor the voltage flow between the panels and the PCU, displaying live updates on the LCD screen. It has the functionality to power on an internal fan to the PCU to keep it under a spe- cific temperature threshold and to disconnect the voltage line of between the panels and the PCU if the intake voltage exceeds the recommended voltage of the PCU or the temperature of the PCU exceeds the critical threshold. 1.1 System Overview This solar power regulator is a self contained unit and required no additional hardware or wiring to be fully operational*. It has a built in LCD screen, and can be either powered with batteries or an external power source. Using a PIC16F877A Microcontroller chip this solar power regulator is designed monitor and control the flow of electricity to the PCU while monitoring the internal temperature of the PCU. The LCD screen on the regulator displays the time of day using the clock chip, while continuously displaying the live voltage, and amp readings of the flow of electricity from the panel, and displays the live temperature reading of the internal PCU. While con- tinuously checking the voltage and temperature, the internal programming will trigger the relays to disconnect the power if the voltage or temperature exceeds the allowable threshold** in addition it powers on a fan in the PCU to maintain a suitable tem- perature range. The voltage relay can be reset using the user interface after the manual reset button is pressed. This product is fully operational. *Additional hardware and software may be required to modify the programming or create a personalized custom configuration. **The thresholds are default set to 12 volts, for the power and 80° F for the temperature. The thresholds may be reprogrammed through the computer, using the required software and hardware (not included). 1.2 Point of Contact At any point if you require additional assistance in the setup, programming or trouble shooting of the Solar Power Regulator, you may contact our lead technician Chafic directly at 613-864-4454 or via email him at bouc0261@algonquinlive.com. 1.3 Organization of the Manual This user’s manual consists of 7 sections: General Information. System Summary, Visuals of the Hardware, Electrical Circuit Sche- matic, Issues and Limitations, Program Flowchart, and Program Code. General Information sections explains the system, the purpose and gives contact information where more information can be found. System Summary section gives a quick rundown on how the program works, and lists the requirements for the hardware and software to troubleshoot and reprogram the chip. Visuals of the Hardware section shows the actual parts built and what the Solar Power Regulator looks like inside and out. Electrical Circuit Schematic section shows the entire Schematic for the Solar Power Regulator. Issues and Limitations section outlines any issues I had with the project and limitations for both the hardware and software. Program Flowchart section is a visual display of how the program is expected to run in a flowchart form. Program Code section is the coding for the main program and any subprograms that are required to run the regulator.
  • 6. 2.0 System Summary Page 3Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 2.0 System Summary
  • 7. 2.0 System Summary Page 4Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 2.1 Hardware  1 - PIC16F877A  1 - NE555N - Timer Chip  1 - 6355ED - Serial I/O Real Time Clock  1 - DS1631 - Temperature Chip  1 - 4X3 Keypad  1 - FOX - 20.0MHz Crystal Oscillator  2 - 7805CT - 5 Volt Regulator  1 - 7809CT - 9 Volt Regulator  1 - JHD 162A - 2X16 LCD Screen  2 - 100kΩ Resistor  1 - 22kΩ Resistor  1 - 20kΩ Resistor  6 - 10kΩ Resistor  1 - 2kΩ Resistor  4 - 1kΩ Resistor  1 - 330Ω Resistor  1 - 10Ω Resistor  1 - 10KΩ Potentiometer  1 - 100μF Capacitor  1 - 0.01μF Capacitor  1 - 0.001μF Capacitor  2 - 3904 Transistor  4 - IN5231B - Zener Diode  2- HLS-4078-DC5V - Relay  1 - Push Button Switch  3 - 9V Battery Connectors  3 - 9V Battery  1 - 9V DC Fan 2.2 Software  PIC C Compiler  PICkit 2 2.3 Computer Minimum Requirements:  Pentium 1 Processor  Keyboard  Monitor  80 GB of storage Space 2.0 SYSTEM SUMMARY When the Regulator is initialized it will ask you for the hour and than the minute, input the time using the keypad. It will then auto- matically show your all the data. If it enters critical mode it will tell you to press ’*’ to reset, all you have to do then it hit ’*’ on the keypad after you checked to see that the voltage is level and it will reset the voltage connection. The voltage connection will not reset if the voltage and/or temperature are still past the threshold.
  • 8. 3.0 Visuals of the Hardware Page 5Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 3.0 Visuals of the hardware
  • 9. 3.0 Visuals of the Hardware Page 6Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 3.0 Containment Unit This is the visual of the external containment unit. The LCD, reset push button, keypad, visual LED and voltage intake are all easily accessible. Has a slot to include access to a temperature chip to meas- ure temperature of the units environment. 3.1 Main Circuit Board This is the main circuit PCB board it contains the microcon- troller, it’s own 5 volt power supply, and a 9 volt power supply to power the fan. The two relays to cut the intake voltage and power the fan. Control the contras of the LCD with the potentiometer on this board All other components connect to this board.
  • 10. 3.0 Visuals of the Hardware Page 7Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 3.2 Clock Chip Circuit Board This is the 6355ED - Serial I/O Real Time Clock circuit board with the NE555N timer. This has its own 5 volt closed circuit power to reduce noise caused by the NE555N timer to the rest of the circuits. 3.3 Temperature Chip Circuit Board This is the DS1631 - Temperature Chip circuit board, It is separated from the rest so that it can be placed within the PCU to read its internal temperature.
  • 11. 4.0 Electrical Circuit Schematic Page 8Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 4.0 Electrical circuit Schematic
  • 12. 4.0 Electrical Circuit Schematic Page 9Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 13. 5.0 Issues and Limitations Page 10Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 5.0 Issues and Limitations
  • 14. 5.0 Issues and Limitations Page 11Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 5.0 Hardware Quick steps to ensure you do not run into any issues with the hardware and ways to figure out how to determine what the problem is. A chip is not working properly?  Check power supply  Check wiring  Check for cold and incomplete solders  Ensure any transistors and/or diodes are facing the right direction Best way to determine if a specific chip or section of your circuit is working is by building it in bits and pieces and making sure it works before adding the next section. Test any questionable parts in a working circuit with the proper programming to ensure that it is functioning properly otherwise replace the part. Having the LCD wired with all 8 data pins reduced the number of ports on the PIC16 that can be used for other hardware. Reducing the number of pins to 4 and changing the programming allows more peripherals on the PIC I had issues getting the NE555N Timer to meet the required frequency (32.768KHz) with a duty cycle above 50% with the specific timer circuit that was built in this project. As the 6355ED seconds need that frequency to give out accurate time readings. My sug- gestion for this is get a proper crystal oscillator that runs at that frequency or find a clock chip with a built in precise oscillator. 5.1 Software Space... The biggest limiting factor with the PIC and software, ensuring the software all fit within the total Rom space was essential. Changing values and using int and char helped to save space. Printf statements required tremendous amounts of space so limiting those is essential. Using the switch program to when thresholds were triggered ensured flawless transition into different modes. Breaking out of switch modes was a challenge as creating a kbd_press program was essential to create that pause in the program to wait for a user to reset the program. Putting the Init files on a separate chip to initialize the LCD, 6355ED, and DS1631, would save you tons of space as well, as long as those parts maintain power and do not turn on. Which makes it very challenging to do this with this setup. So in this project they had to stay on the main chip for simplicity and time sake, which meant I was highly limited in the complexity and depth of this soft- ware.
  • 15. 6.0 Program Flowchart Page 12Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 6.0 Program Flowchart
  • 16. 6.0 Program Flowchart Page 13Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 17. 7.0 Program Code Page 14Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 7.0 Program Code
  • 18. 7.0 Program Code Page 15Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 19. 7.0 Program Code Page 16Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 #include <prototype.h> #include <ds1631.c> #include <nju6355.c> #include <stdlib.h> /*************************************************************************** Main Program ***************************************************************************/ void main() { int hour, min, sec, last_sec, volt, curr; // Sets Int for; hour, min, sec, last_sec, volt, curr unsigned long int voltage_reading, current_reading; // Sets Unsigned long int for; voltage_reading, current_reading unsigned long int value=0; // Sets unsigned long int for value lcd_init(); // Initialized LCD kbd_init (); // Initialized keypad rtc_init (); // Initialized clock chip init_temp(); // Initialized temperature chip set_time (); // Prompts set time sequence while(1) // While true execute this Loop { rtc_get_time (hour, min, sec ); // Retrieves time from chip if (( sec!=last_sec )) // If Sec does not equal Last_sec then execute the following loop { set_adc_channel ( 1 ); // Sets Channel to Port A1 delay_us (10); // Delays 10 µs voltage_reading = read_adc (); // Reads Voltage from A1 delay_us (10); // Delay 10 µs volt = ((voltage_reading*12)/100) ; // Converts Voltage Reading to User Readable Number // Sets Readable Number as Volt Int set_adc_channel ( 3 ); // Sets Channel to Port A3 delay_us (10); // Delays 10 µs current_reading = read_adc (); // Reads Current from A3 delay_us (10); // Delays 10 µs
  • 20. 7.0 Program Code Page 17Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 curr = ((current_reading*12)/1000); // Converts Current Reading to User Readable Number // Sets Readable Number as Curr Int value = read_full_temp (); // Sets temp reading as value value /= 100; delay_ms (100); // Delay 100 ms printf (lcd_putc, "f%c%c:%c%c:%c%c ", // Displays time on the LCD display_first_bcd ( hour), display_second_bcd (hour), display_first_bcd (min), display_second_bcd (min), display_first_bcd (sec), display_second_bcd (sec)); printf (lcd_putc, "nTemp%4.2ld ", value); // Displays temp on LCD printf (lcd_putc, "t %d V ", volt); // Displays volt on LCD printf (lcd_putc, "U %d mA ", curr); // Displays curr on LCD last_sec = sec; // Sets Last_sec as the Current Sec If (volt >= 12) // If volt >= 12 then Switchc case 0 is activated { Switchc (0); } If (value >= 78) // If temp value >= 78 then fan turns ON { output_high (Pin_D0); } If (value >= 80) // If temp value >= 80 then Switchc case 1 is activated { Switchc (1); } if (value <= 77) // If temp value <= 77 then fan turns OFF { Output_low (Pin_D0); } } } }
  • 21. 7.0 Program Code Page 18Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 22. 7.0 Program Code Page 19Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** Switch Program for "Voltage Overload" and "Temperature Crititcal" ***************************************************************************/ void Switchc ( int SC ) { switch ( SC ) { case 0: { // Case 0 Output_high (Pin_A2); // Disconnects input voltage Printf (lcd_putc, "b****Overload****"); // Displays on LCD Printf (lcd_putc, "nPress * to reset"); // Displays on LCD Kbd_press (); // Waits for * to be pressed on keypad Output_low (Pin_A2); // Reconnects input voltage break; // Returns to main program } case 1: { // Case 1 Output_high (Pin_A2); // Disconnects input voltage Output_high (Pin_D0); // Turn fan ON Printf (lcd_putc, "b Temp CRITICAL"); // Displays on LCD Printf (lcd_putc, "nPress * to reset"); // Displays on LCD Kbd_press (); // Waits for * to be pressed on keypad Output_low (Pin_D0); // Turns fan OFF Output_low (Pin_A2); // Reconnects input voltage break; // Returns to main program } } }
  • 23. 7.0 Program Code Page 20Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 24. 7.0 Program Code Page 21Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** Kbd_press Here the program will cycle in a blank loop waiting for * to be pressed then released before going back to the previous program ***************************************************************************/ void Kbd_press (void) { while(kbd_getc () != '*') // While * is not press, closed loop rotation { } while(kbd_getc () == '*') // While * is press, closed loop rotation { } // Once * is released, breaks out of Kbd_press. } // Returns to previous program
  • 25. 7.0 Program Code Page 22Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 26. 7.0 Program Code Page 23Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** Set Time ***************************************************************************/ void set_time () { int hour, min; // Sets hour, min as an Int value Delay_ms (500); printf ( lcd_putc, "bHour: "); hour = get_bcd(); printf ( lcd_putc, "bMin: " ); min = get_bcd (); rtc_set_datetime ( 0, 0, 0, 0, hour, min ); } // end void set_time char display_first_bcd (byte n ) { return n/16+'0' ; } // end char display_first_bcd char display_second_bcd (byte n ) { return n%16+'0'; } // end char display_second_bcd
  • 27. 7.0 Program Code Page 24Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 28. 7.0 Program Code Page 25Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** BCD ***************************************************************************/ byte get_bcd() { char first, second; do { first=kbd_getc(); // Note first is gathered from kbd_getc() Keypad Press } while ((first<'0') || (first>'9')); putc(first); do { second=kbd_getc(); // Note first is gathered from kbd_getc() Keypad Press } while ((second<'0') || (second>'9') && (second!='r')); putchar(second); if (second=='r') return (first-'0'); else return (((first-'0') << 4) | (second-'0')); } void display_bcd (byte n ) { putc ( n/16+'0' ); putc ( n%16+'0' ); }
  • 29. 7.0 Program Code Page 26Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 30. 7.0 Program Code Page 27Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 #ifndef DAL_SCL #define DAL_SCL PIN_E1 #define DAL_SDA PIN_E0 #endif #define read_temp read_full_temp // for backwards compatability #use i2c(master, sda=DAL_SDA, scl=DAL_SCL) void temp_config(BYTE data) { i2c_start(); i2c_write(0x90); i2c_write(0xac); i2c_write(data); i2c_stop(); } void init_temp() { output_high(DAL_SDA); output_high(DAL_SCL); i2c_start(); i2c_write(0x90); i2c_write(0x51); i2c_stop(); temp_config(0xc); } signed long read_full_temp() { // Returns hundreths of degrees F (-67 to 257) signed int datah, datal; signed long data; i2c_start(); i2c_write(0x90);
  • 31. 7.0 Program Code Page 28Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 i2c_write(0xaa); i2c_start(); i2c_write(0x91); datah=i2c_read(); datal=i2c_read(0); i2c_stop(); data=(signed long)datah*100; data=data+(((datal >> 4 )*(long)50)/16); data=data*9; data = (data / 5) + 3200; return(data); }
  • 32. 7.0 Program Code Page 29Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 33. 7.0 Program Code Page 30Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 #ifndef RTC_DATA // If RTC_DATA defined set pins #define RTC_DATA PIN_B0 // Data pin to port B0 #define RTC_CLK PIN_C4 // CLK pin to port C4 #define RTC_CE PIN_D3 // CD pin to port D3 #define RTC_IO PIN_D2 // IO pin to port D2 #endif // end if void rtc_init() { output_low(RTC_CE); output_low(RTC_IO); } void write_rtc_byte(BYTE data_byte, BYTE number_of_bits) { BYTE i; for(i=0; i<number_of_bits; ++i) { if((data_byte & 1)==0) output_low(RTC_DATA); else output_high(RTC_DATA); data_byte=data_byte>>1; output_high(RTC_CLK); output_low(RTC_CLK); } } BYTE read_rtc_byte(BYTE number_of_bits) { BYTE i,data; for(i=0;i<number_of_bits;++i) { output_high(RTC_CLK); shift_right(&data,1,input(RTC_DATA)); output_low(RTC_CLK); } return(data); } void rtc_set_datetime(BYTE day, BYTE mth, BYTE year, BYTE dow,
  • 34. 7.0 Program Code Page 31Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 BYTE hour, BYTE min){ output_low(RTC_CLK); output_high(RTC_IO); output_high(RTC_CE); write_rtc_byte(year,8); write_rtc_byte(mth,8); write_rtc_byte(day,8); write_rtc_byte(dow,4); write_rtc_byte(hour,8); write_rtc_byte(min,8); output_low(RTC_CE); output_low(RTC_IO); } void rtc_get_date(BYTE& day, BYTE& mth, BYTE& year, BYTE& dow) { output_low(RTC_CLK); output_low(RTC_IO); output_high(RTC_CE); year=read_rtc_byte(8); mth=read_rtc_byte(8); day=read_rtc_byte(8); dow=read_rtc_byte(4)>>4; read_rtc_byte(8*3); output_low(RTC_CE); output_low(RTC_IO); } void rtc_get_time(BYTE& hr, BYTE& min, BYTE& sec) { output_low(RTC_CLK); output_low(RTC_IO); output_high(RTC_CE); read_rtc_byte(8*3+4); hr=read_rtc_byte(8); min=read_rtc_byte(8);
  • 35. 7.0 Program Code Page 32Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 sec=read_rtc_byte(8); output_low(RTC_CE); output_low(RTC_IO); }
  • 36. 7.0 Program Code Page 33Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 37. 7.0 Program Code Page 34Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** Kbd Initialization Program Defines Keypad Buttons ***************************************************************************/ #define col0 PIN_B3 #define col1 PIN_B2 #define col2 PIN_B1 #define row0 PIN_B7 #define row1 PIN_B6 #define row2 PIN_B5 #define row3 PIN_B4 char const KEYS[4][3] = {{'1','2','3'}, // Keypad layout: {'4','5','6'}, {'7','8','9'}, {'*','0','#'}}; #define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where // n is the number of times you expect // to call kbd_getc each second void kbd_init() {} short int ALL_ROWS (void) { if (input (row0) & input (row1) & input (row2) & input (row3)) return (0); else return (1); } char kbd_getc( ) { static byte kbd_call_count; static short int kbd_down; static char last_key; static byte col;
  • 38. 7.0 Program Code Page 35Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 byte kchar; byte row; kchar='0'; if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) { switch (col) { case 0 : output_low(col0); output_high(col1); output_high(col2); break; case 1 : output_high(col0); output_low(col1); output_high(col2); break; case 2 : output_high(col0); output_high(col1); output_low(col2); break; } if(kbd_down) { if(!ALL_ROWS()) { kbd_down=false; kchar=last_key; last_key='0'; } } else { if(ALL_ROWS()) { if(!input (row0)) row=0;
  • 39. 7.0 Program Code Page 36Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 else if(!input (row1)) row=1; else if(!input (row2)) row=2; else if(!input (row3)) row=3; last_key =KEYS[row][col]; kbd_down = true; } else { ++col; if(col==3) col=0; } } kbd_call_count=0; } return(kchar); }
  • 40. 7.0 Program Code Page 37Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 41. 7.0 Program Code Page 38Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 /*************************************************************************** Define Ports for LCD ***************************************************************************/ #define LCD_DB4 PIN_D4 #define LCD_DB5 PIN_D5 #define LCD_DB6 PIN_D6 #define LCD_DB7 PIN_D7 #define LCD_E PIN_C5 #define LCD_RS PIN_C1 #define lcd_line_two 0x40 #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines /*************************************************************************** int const LCD_INIT_STRING[5] ***************************************************************************/ int const LCD_INIT_STRING[4] = { 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots 0xc, // Display on 1, // Clear display 6 // Increment cursor }; void lcd_send_nibble(int8 nibble) { // Note: !! converts an integer expression // to a boolean (1 or 0). output_bit(LCD_DB4, !!(nibble & 1)); output_bit(LCD_DB5, !!(nibble & 2)); output_bit(LCD_DB6, !!(nibble & 4)); output_bit(LCD_DB7, !!(nibble & 8)); delay_cycles(1); output_high(LCD_E); delay_us(2); output_low(LCD_E);
  • 42. 7.0 Program Code Page 39Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 } /*************************************************************************** void lcd_send_byte(int address, int n) ***************************************************************************/ void lcd_send_byte(int address, int n) { output_low (LCD_RS); delay_us (60); if(address) output_high (LCD_RS); else output_low (LCD_RS); output_low(LCD_E); delay_cycles(1); lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); } // end lcd_send_byte /*************************************************************************** void lcd_init(void) ***************************************************************************/ void lcd_init(void) { int i; output_low(LCD_RS); output_low(LCD_E); delay_ms(15);
  • 43. 7.0 Program Code Page 40Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 for(i=0 ;i < 3; i++) { lcd_send_nibble(0x03); delay_ms(5); } // end for lcd_send_nibble(0x02); for(i=0; i < sizeof(LCD_INIT_STRING); i++) { lcd_send_byte(0, LCD_INIT_STRING[i]); } // end for } // end lcd_init /*************************************************************************** void lcd_putc(char c) ***************************************************************************/ void lcd_gotoxy(int8 x, int8 y) { int8 address; if(y != 1) address = lcd_line_two; else address=0; address += x-1; lcd_send_byte(0, 0x80 | address); } void lcd_putc(char c) { switch(c) {
  • 44. 7.0 Program Code Page 41Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 case 'b': lcd_send_byte(0,1); delay_ms(2); break; case 'f': lcd_send_byte(0, 0x80 ); break; case 'n': lcd_send_byte(0, 0xc0 ); break; case 't': lcd_send_byte(0, 0x89 ); break; case 'U': lcd_send_byte(0, 0xc9 ); break; default: lcd_send_byte(1,c); break; } // end switch } // end lcd_putc
  • 45. 7.0 Program Code Page 42Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015
  • 46. 7.0 Program Code Page 43Chafic Bouchakra, 040-622-744, Interfacing Final Project Winter 2015 #include <16f877A.h> #fuses HS, NOLVP, NOWDT, PUT #use delay ( clock = 20000000 ) #use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)