Photovoltaic System Management
Photovoltaic System Management
Photovoltaic System Management
1
CONTENT
ABSTRACT
INTRODUCTION
LITERATURE SURVEY
EXISTING SYSTEM
PROPOSED SYSTEM
BLOCK DIAGRAM
WORKING PRINCIPLE
HARDWARE REQUIREMENTS
SOFTWARE REQUIREMENTS
APPLICATION
CONCLUSION
REFERENCES
2
ABSTRACT
3
CHAPTER - I
1.1 INTRODUCTION:
4
CHAPTER - II
2. LITERATURE SURVEY:
This information may indicate that consumers are not averse to significantly
changing their spending habits with the advent of new technologies. According to the US
Bureau of Labor Statistics, the average homeowner spent approximately 11% more on
entertainment (including cell phone and internet services). Data indicate that consumers
are willing to spend more on hybrid vehicles than on similarly sized traditional vehicles
for reasons other than economic payback. Diverse motivations can lead to the same end
goal. For instance, a consumer may purchase a hybrid vehicle to decrease carbon
emissions, reduce dependency on foreign oil, save money, or simply as a status symbol.
Regardless, driving a hybrid vehicle contributes to a more sustainable energy future by
reducing oil consumption and greenhouse gas emissions. Similarly, marketing or societal
influences may motivate consumers to invest in smart home technologies. The authors
5
contend that cost and the lack of perceived value have combined to slow the adoption of
smart homes. However, the perceived value of a smart home is likely to vary across
populations.
Now the entire earth is, so to speak, situ three of the most prominent issues facing
the world today are escalating climate change, energy security and meeting the increasing
global demand for electrical energy generated from renewable sources. The renewable
energy is growing technology for meeting the demands of energy consumption to solve
the problems of fossil fuels and at the same time reduce the pollution in the atmosphere.
In case of fossil fuels once it is used that cannot regenerated means it is converted into
electricity and is used by consumers. Where as in case of renewable sources the energy
generated is unlimited. Hence, the importance of renewable energy is becoming a great
technology and today the world seeing to develop these technologies. Now a day many
companies are seeing that to increase the efforts on development of renewable sources by
6
constructing smart grids having sustainable growth and connecting those smart grids to
the commercial electricity grids. In this paper, introduced an efficient energy distribution
system to distribute the energy generated from the renewable sources. In order to meet
the current problems the energy generated from the renewable sources to maintain it
constant, it was connected to a battery and inverter. In this research, we have
implemented a prototype system for the ideas. The preliminary tests show that this
approach is promising for real applications.
The penetration of renewable sources in the power system network in the power
system has been increasing in the recent years. One of the solutions being proposed to
improve the reliability and performance of these systems is to integrate energy storage
device into the power system network. This paper discusses the modeling of photovoltaic
and status of the storage device such as lead acid battery for better energy management in
the system. The dynamic switching process performed the energy management for the
grid-connected system. The renewable energy sources (RES) are clean with low
environmental impact than the conventional energy source. RES such as wind, solar,
biomass, hydro and geothermal are available in nature as a non-depleting source. The
solar Photovoltaic (PV) cell is an electronic device that essentially converts the solar
energy of sunlight into electric energy or electricity. Photovoltaic system consists of
many cells, panels and array. The large-scale PV plants are used for electricity generation
that is fed into the grid and load. Such system, typically consist of one or more PV panels
a DC/AC power Converter/Inverter. Additionally such system could also include
maximum power point (MPP) and storage devices.
Intensive efforts have been made recently in transforming the power grid into
smart grid by means of incorporating extensive information and communication
infrastructures. In this paper a versatile stochastic optimization approach has been
proposed for smart grid, to suffice the residential customers in an efficient energy
management comprising high penetration of renewable and distributed energy sources,
market based online electricity pricing, large scale storage of energy and high quality
demand side management, mitigating monetary expense. The terminology Boost
converter used in this paper increases the throughput of solar panel voltage.
Smart energy meter, an added advantage of the proposed system provides a two
way communication between the utility board and residential unit. The simulation results
8
indicate an appreciable tradeoff between storage capacity and cost saving. This proposed
energy consumption scheduling algorithm ensures, generating scheduling solutions
within 10 seconds for fast household appliance applications. The electrical power grid is
by nature is a complex adaptive system and it regards with significant amount of
uncertainties The existing grid faces some sensitive problems which are major factors of
concern. They can be specifically mentioned as follows: limited delivery system. High
cost of power outage and power quality interruption. Inefficiency at managing peak load.
Increase in global warming and hazardous emissions. This negative impact of global
warming and greenhouse effects is indeed a curse to the entire existence of life on earth.
9
2.6 Home Energy Management Systems in Future Smart Grids
We present a detailed review of various Home Energy Management Schemes
(HEM,s). HEM, will increase savings, reduce peak demand and Pto Average Ratio
(PAR). Among various applications of smart grid technologies, home energy
management is probably the most important one to be addressed. Various steps have been
taken by utilities for efficient energy consumption. New pricing schemes like Time of
Use (ToU), Real Time Pricing (RTP), Critical Peak Pricing (CPP), Inclining Block Rates
(IBR) etc have been devised for future smart grids. Home appliances and/or distributed
energy resources coordination (Local Generation) along with different pricing schemes
leads towards efficient energy consumption. This paper addresses various communication
and optimization based residential energy management schemes and different
communication and networking technologies involved in these schemes.
10
real time pricing and energy expense. IHEM allow communication between the consumer
and controller through Wireless Sensor Home Area Network (WSHAN). Main idea of In
Home Energy Management (IHEM) application is to find solution for Optimization based
Residential Energy Management (OREM) scheme and also to reduce the cost of energy
usage at home. Comparison of IHEM and OREM is carried to reduce energy expense to
ensure efficient demand supply. Evaluation is done based on the performance of IHEM
under the presence of local energy generation capability, real-time pricing, and for
prioritized appliances to determine the cost of energy expense. A smart grid delivers
electricity from suppliers to consumers using digital technology with two-way
communications to control appliances at consumers' homes to save energy, reduce cost
and increase reliability and transparency. Using wireless Sensor Networks (WSNs) has
many benefits, including unmetered access to information, support for mobility, reduced
cost and complexity associated with wiring and maintenance, and support for
interoperability. While many of these benefits apply to the grid, there are a number of
challenges that remain.
The milestone in the process of transition from the traditional grid to the smart
grid is the integration of information and communication technologies (ICT) to the power
grid. The advances in ICT can be employed to increase automation, integrate distributed
renewable resources, secure the grid infrastructure, adopt electric vehicles (EVs), and
enable efficient demand-side energy management. First, it has been hard to handle the
large number of residential units without communication, sensors, and efficient
automation tools. Second, the impact of demand response programs has been considered
to be relatively small when compared with their implementation cost. However in the
smart grid, smart meters, low-cost sensors, smart appliances, and communications set the
stage for novel residential energy management techniques that involve communications
and interaction between consumers, devices, and the grid. Residential energy
management, smart appliances, WSHANs, and their integration to smart grid applications
are becoming popular topics as the governments and the utilities are urging for migration
11
to the smart grid. In this paper, we introduce the OREM and the IHEM schemes to reduce
the share of the appliances in the energy bills and to reduce their contribution to the peak
load. We show that the IHEM application decreases the contribution of the appliances to
the energy bill, significantly.
12
CHAPTER – III
SYSTEM ANALYSIS
The thermal power stations are causing pollution, which severely affects mankind
and nature. These power stations result in causing many diseases. Also natural resources
like coal, oil, radio-active materials etc. will get extinct in near future. The other existing
power generating systems like Hydro-Electricity power generating plant cannot afford
much power, as it is season based, although it causes less pollution.
3.1.1 Disadvantage:
It effects environments
More pollution
Less efficient
Limited capacity
13
3.2 Proposed System:
All the natural wastage energies are used for production of Electricity. Thus, the
Electrical Power or Electricity is available with a minimum cost and pollution free to
anywhere in the world at all times. This project will expose a novel step in the generation
of electricity and availability of natural resources without disturbing the ecological
balance. This project describes a novel and developing Electrical Power Generation
mechanism by photovoltaic Solar Energy. The solar energy is used to store in the battery.
Then it will be used to run the electrical loads. This solar power generating system is
suitable for Industries and domestic areas.
3.2.1 Advantage:
Solar photovoltaic (SPV) systems can also increase the reliability of the system
It can also reduce the noises
Less cost
High efficient
14
CHAPTER - IV
15
4.2 WORKING PRINCIPLE:
The input 230V AC voltage applied to the step down transformer it step down into
12v Ac. The switch is connected with secondary side of step down transformer. Bridge
rectifier is converting AC into pulsating DC of 12V.In Bridge Rectifier analog input is
connected to the switch and positive, negative edge is connected to the ceramic capacitor.
Ceramic capacitor is connected for noise rectification.1000uf Ceramic capacitor is used
to filter the harmonics in the power supply line. Capacitor is connected to the voltage
regulator. The 7805 voltage regulator has 3 pins. First pin is 12v input pin, second pin is
ground pin and third pin is 5v output pin. Input 5v is given to PIC 16F877a
microcontroller. Here power generating through renewable energy like solar. The aim of
this project is to design and implement a power generation system using solar energy.
Here two solar panels is used for power generation. The Solar panel receives solar
energy. The received energy are low voltage, so boost converter will increase the voltage.
Filter is used to avoid the harmonics in that power. Then this power will store in a
battery. Rectifier is used to convert ac to dc. 1000mf capacitor is used to filter the
harmonics in that stored power. Microcontroller runs only 5v. So, voltage regulator IC
7805 is used to regulate 12v to 5v. Then 5v input gives to microcontroller. Inverter is
used to convert dc to ac. Switch is used to on the electrical load. In case any problem
occurs in the battery, then it cannot to run the load. Therefore, here gives a solution for
that problem. When battery fails, automatically relay activates the TNEB power supply
will give the power to run the load.
16
CHAPTER - V
1) Power Supply
2) Switch
3) Rectifier
4) 1000 mf Capacitor
6) LCD Display
8) Solar panel
9) Boost Converter
10) Relay
11) Light
14) TNEB
17
CHAPTER-VI
6. HARDWARE DESCRIPTION:
18
A switch is an electrical component that can break an electrical circuit,
interrupting the current or diverting it from one conductor to another. the mechanism of a
switch may be operated directly by a human operator to control a circuit (for example, a
light switch or a keyboard button), may be operated by a moving object such as a door-
operated switch, or may be operated by some sensing element for pressure, temperature
or flow. A relay is a switch that is operated by electricity. Switches are made to handle a
wide range of voltages and currents; very large switches may be used to isolate high-
voltage circuits in electrical substations.
6.3 Rectifier
Rectifiers have many uses, but are often found serving as components of
DC power supplies and high-voltage direct current power transmission systems.
Rectification may serve in roles other than to generate direct current for use as a source of
power. As noted, detectors of radio signals serve as rectifiers. In gas heating
systems flame rectification is used to detect presence of a flame.
Because of the alternating nature of the input AC sine wave, the process of
rectification alone produces a DC current that, though unidirectional, consists of pulses of
current. Many applications of rectifiers, such as power supplies for radio, television and
computer equipment, require a steady constant DC current (as would be produced by
19
a battery). In these applications the output of the rectifier is smoothed by an electronic
filter (usually a capacitor) to produce a steady current.
A more complex circuitry device that performs the opposite function, converting
DC to AC, is called an inverter.
6.4Capacitor
When there is a potential difference across the conductors (e.g., when a capacitor
is attached across a battery), an electric field develops across the dielectric, causing
positive charge +Q to collect on one plate and negative charge −Q to collect on the other
plate. If a battery has been attached to a capacitor for a sufficient amount of time, no
current can flow through the capacitor. However, if a time-varying voltage is applied
across the leads of the capacitor, a displacement current can flow.
20
Fig. 1 Voltage Regulator IC 7805
LCD (Liquid Crystal Display) screen is an electronic display module and find a
wide range of applications. A 16x2 LCD display is very basic module and is very
commonly used in various devices and circuits. These modules are preferred overseven
segments and other multi segment LEDs. The reasons being: LCDs are economical;
easily programmable; have no limitation of displaying special & even custom
characters (unlike in seven segments).
21
Fig.2 LCD Display
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines.
In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers,
namely, Command and Data.
The command register stores the command instructions given to the LCD. A
command is an instruction given to LCD to do a predefined task like initializing it,
clearing its screen, setting the cursor position, controlling display etc. The data register
stores the data to be displayed on the LCD. The data is the ASCII value of the character
to be displayed on the LCD.
Pin Description:
22
6.7 PIC MICROCONTROLLER
Flash
23
OTP (One-time-programmable)
ROM (Read-only-memory)
ROM less
Input - Output (I/O) Pin Count
4–18 pins
20–28 pins
32–44 pins
45 and above pins
• Analog comparators
24
• External and internal interrupts
• Internal oscillator
• PWM output
There are three package types are available: DIP, PLCC, and QFP. This book
assumes that we all use the DIP because of its best fit to breadboard or proto-board.
25
6.7.4 PIC 16F877A (Architecture of PIC16F877A)
26
Fig. 4 Architecture of 16F877A
There are three memory blocks in each of these PIC micro MCUs. The Program
Memory and Data Memory have separate buses so that concurrent access can occur.
27
6.7.5.1 Program memory organization
28
The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the Special Function Registers. Bits RP1 (STATUS<6>) and RP0
(STATUS<5>) are the bank select bits.
Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are
reserved for the Special Function Registers. Above the Special Function Registers are
General Purpose Registers, implemented as static RAM.
The register file can be accessed either directly or indirectly through the File
Select Register FSR.
The Special Function Registers are registers used by the CPU and peripheral
modules for controlling the desired operation of the device. These registers are
implemented as static RAM. The Special Function Registers can be classified into two
sets; core (CPU) and peripheral.
The STATUS register contains the arithmetic status of the ALU, the RESET status
and the bank select bits for data memory. The STATUS register can be the destination for
any instruction, as with any other register.
29
If the STATUS register is the destination for an instruction that affects the Z, DC
or C bits, then the write to these three bits is disabled. These bits are set or cleared
according to the device logic. The TO and PD bits are not writable, therefore, the result
of an instruction with the STATUS register as destination may be different than intended.
The INTCON Register is a readable and writable register, which contains various
enable and flag bits for the TMR0 register overflow, RB Port change and External
RB0/INT pin interrupts.
The PIE1 register contains the individual enable bits for the peripheral interrupts.
The PIR1 register contains the individual flag bits for the peripheral interrupts.
The PIE2 register contains the individual enable bits for the CCP2 peripheral
interrupt, the SSP bus collision interrupt, and the EEPROM write operation interrupt.
30
6.7.6.7 PIR2 register
The PIR2 register contains the flag bits for the CCP2 interrupt, the SSP bus
collision interrupt and the EEPROM write operation interrupt.
The Power Control (PCON) Register contains flag bits to allow differentiation
between a Power-on Reset (POR), a Brown-out Reset (BOR), a Watch-dog Reset (WDT)
and an external MCLR Reset.
Although solar is becoming more popular everyday people still don’t know how
solar panels work. Certain competing energy concerns have campaigns to discredit and
confused consumers on how solar energy is generated. There are many considerations in
regards to solar and distinctions between residential and industrial, between being off the
grid and connecting the grid. This simple guide will outline how Solar Panels Work.
Here’s a quick “how solar panels work” guide to the steps that it takes to turn sunlight
into electricity using solar panels: Every day, light hits your roof’s solar panels with
photons (particles of sunlight). The panel converts those photons into electrons of direct
current (“DC”) electricity. Naturally, the sunnier it is, the more energy is produced by the
panels. Those produced electrons flow out of the panel and into an inverter and other
electrical safety devices The inverter converts that “DC” power into alternating current
or “AC” power. AC power is the kind of electric juice that your television, computer, and
toasters use when plugged into the wall outlet. A bi-directional meter keeps track of the
all the power your solar system produces. Any solar energy that you don’t use
immediately will go back into the grid through the meter. Then at night or on cloudy
days, that extra solar juice is credited back to your bill. So, net metering is similar to
having a virtual battery-backup system (we explain more about grid-tied solar home solar
31
systems later). Solar panels that can avoid shade, can maximize sun coverage will
produce the most solar energy power.
6.9Boost Converter
6.10Relay
32
A type of relay that can handle the high power required to directly control an
electric motor or other loads is called a contactor. Solid-state relays control power circuits
with no moving parts, instead using a semiconductor device to perform switching. Relays
with calibrated operating characteristics and sometimes multiple operating coils are used
to protect electrical circuits from overload or faults; in modern electric power systems
these functions are performed by digital instruments still called "protective relays".
6.11 Light
The main source of light on Earth is the Sun. Sunlight provides the energy that
green plants use to create sugars mostly in the form of starches, which release energy into
the living things that digest them. This process of photosynthesis provides virtually all the
energy used by living things. Historically, another important source of light for humans
has been fire, from ancient campfires to modern kerosene lamps. With the development
of electric lights & power systems, electric lighting has effectively replaced firelight.
Some species of animals generate their own light, a process called bioluminescence. For
example, fireflies use light to locate mates, and vampire squids use it to hide themselves
from prey.
The primary properties of visible light are intensity, propagation direction, frequency
or wavelength spectrum, and polarization, while its speed in a vacuum, 299 792 458
meters per second, is one of the fundamental constants of nature. Visible light, as with all
33
types of electromagnetic radiation (EMR), is experimentally found to always move at this
speed in vacuum.
Primary (single-use or "disposable") batteries are used once and discarded; the
electrode materials are irreversibly changed during discharge. Common examples are the
34
alkaline battery used for flashlights and a multitude of portable devices. Secondary
(rechargeable batteries) can be discharged and recharged multiple times; the original
composition of the electrodes can be restored by reverse current. Examples include the
lead-acid batteries used in vehicles and lithium ion batteries used for portable electronics.
Batteries come in many shapes and sizes, from miniature cells used to power
hearing aids and wristwatches to battery banks the size of rooms that provide standby
power for telephone exchanges and computer data centers. According to a 2005 estimate,
the worldwide battery industry generates US$48 billion in sales each year, with 6%
annual growth. Batteries have much lower specific energy (energy per unit mass) than
common fuels such as gasoline. This is somewhat offset by the higher efficiency of
electric motors in producing mechanical work, compared to combustion engines.
35
CHAPTER-VII
7. SOFTWARE REQUIREMENTS
1) Proteus Software: For schematic circuit design, PCB design and simulation.
2) Keil μvision Software: Keil provides a broad range of development tools like ANSI c
compiler, macro assemblers, debuggers and simulators, IDE, the real-time operating
systems and evaluation boards for 8051, arm.
36
VSM - Virtual System Modeling lets co simulate embedded software for popular
micro-controllers alongside hardware design.
Up to know we have discussed about the basics and software description. Now
we are entering into the designing section. Run the ISIS professional program by clicking
the icon on the desktop, then this splash screen will appear.
At first sight, Proteus may appear similar to Basic because of its straight syntax,
but similarities are limited to the surface:
Proteus has a fully functional, procedural approach; variables are untyped, do not
need to be declared, can be local or public and can be passed by value or by reference;
All the typical control structures are available (if-then-else; for-next; while-loop;
repeat-until; switch-case);
Data types supported by Proteus are only three: integer numbers, floating point
numbers and strings.
37
Access to advanced data structures (files, arrays, queues, stacks, AVL trees, sets
and so on) takes place by using handles, i.e. integer numbers returned by item creation
functions.
No data types: all variables can be used as integer numbers, floating point numbers or
strings; variables are interpreted according to the functions being applied – Proteus keeps
different representations of their values between calls, to decrease execution time in case
of frequent conversions between one type and the other;
38
CHAPTER - VIII
8. CIRCUIT DIAGRAM:
12V DC GND 5V DC
R1
TR1 1k
BOOST CONVERTER
BR1 U2
P 7805
240v
STEP DOWN C3 1 3
AC VI VO
D1
12V AC 25v/1ooomf GND
T/F pwr Led
INPUT 12V DC
2
C1
U1
13 33
OSC1/CLKIN RB0/INT
33pf X1 14
OSC2/CLKOUT RB1
34
CRYSTAL 35 R3
RB2
2 36
C2 RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
4
RA2/AN2/VREF-/CVREF RB5
38 330 Ohm
5 39
RA3/AN3/VREF+ RB6/PGC
6 40
33pf 7
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RB7/PGD
15 D2
8
RC0/T1OSO/T1CKI
16 12+
9
RE0/AN5/RD
RE1/AN6/WR
RC1/T1OSI/CCP2
RC2/CCP1
17 NC LED
10 18
R2
RE2/AN7/CS RC3/SCK/SCL
23 ELECTRICAL LOAD
1
RC4/SDI/SDA
24 I/P COM
MCLR/Vpp/THV RC5/SDO
RC6/TX/CK
25 RELAY
1K 26
11
RC7/RX/DT GND NO
VDD RD0/PSP0
19
20
RD1/PSP1
21
RD2/PSP2
VSS RD3/PSP3
22
P
12 27
RV1 LCD DISPLAY RD4/PSP4
RD5/PSP5
28
29
RD6/PSP6
30
RD7/PSP7 240V AC
PIC16F877A
VDD
VSS
VEE
RW
1K
RS
D0
D1
D2
D3
D4
D5
D6
D7
E
N
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Battery
Inverter
L1
12V
Rectifier
TNEB AC Supply
39
CHAPTER-IX
9. CONCLUSION:
In this project, a renewable energy based solar power system, will be highly
effective in all places, especially in commercial areas where need of electricity is more. It
causes no effect on nature i.e. pollution free. It is also useful to minimize power supply
load i.e. cut power charge. By using this system, we can save electricity charge because
very less maintenance. The designing of this equipment is done in such a way that it is
very compact and acts as user friendly. When it is manufactured in a large scale, cost of
this integrated natural resources power generation system is affordable. Therefore, it is
the most reliable renewable power or electricity resources with less expenditure.
9.1APPLICATION:
40
CODING
#define MX_PIC
#define MX_USES_UINT8 1
#define MX_USES_SINT16 0
#define MX_USES_CHAR 0
#define MX_USES_FLOAT 0
#define MX_USES_SINT32 0
#define MX_USES_BOOL 1
#define MX_USES_UINT16 1
#define MX_USES_UINT32 0
//Defines for microcontroller
#define P16F877A
#define FC_CAL_PIC
#define MX_ADC
#define MX_ADC_TYPE_1
#define MX_ADC_BITS_10
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#define MX_SPI_1
#define MX_SPI_1_MISO_PORT portc
#define MX_SPI_1_MISO_TRIS trisc
#define MX_SPI_1_MISO_PIN 4
#define MX_SPI_1_MOSI_PORT portc
#define MX_SPI_1_MOSI_TRIS trisc
#define MX_SPI_1_MOSI_PIN 5
#define MX_SPI_1_CLK_PORT portc
#define MX_SPI_1_CLK_TRIS trisc
41
#define MX_SPI_1_CLK_PIN 3
#define MX_SPI_1_SS_PORT portc
#define MX_SPI_1_SS_TRIS trisc
#define MX_UART_1
#define MX_UART_1_TX_PORT portc
#define MX_UART_1_TX_TRIS trisc
#define MX_UART_1_TX_PIN 6
#define MX_UART_1_RX_PORT portc
#define MX_UART_1_RX_TRIS trisc
#define MX_UART_1_RX_PIN 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_1
#define MX_I2C_1_SDA_PORT portc
#define MX_I2C_1_SDA_TRIS trisc
#define MX_I2C_1_SDA_PIN 4
#define MX_I2C_1_SCL_PORT portc
#define MX_I2C_1_SCL_TRIS trisc
#define MX_I2C_1_SCL_PIN 3
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_PSCA1
#define MX_PWM_PSCA4
#define MX_PWM_PSCA16
#define MX_PWM_1_PORT portc
#define MX_PWM_1_TRIS trisc
#define MX_PWM_1_PIN 2
#define MX_PWM_2_PORT portc
42
#define MX_PWM_2_TRIS trisc
#define MX_PWM_2_PIN 1
//Functions
#define MX_CLK_SPEED 20000000
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x2007, 0x3f3a
#endif
#ifdef HI_TECH_C
__CONFIG(0x3f3a);
#endif
//Macro function declarations
//Variable declarations
#define FCV_FALSE (0)
#define FCV_TRUE (1)
MX_UINT16 FCV_CON1 = (0x0);
MX_UINT16 FCV_NUM = (0xa);
MX_UINT16 FCV_SW;
MX_UINT16 FCV_TH;
MX_UINT16 FCV_DIS;
MX_UINT16 FCV_SW1;
MX_UINT16 FCV_ADC;
43
MX_UINT16 FCV_SEC = (0x0);
MX_UINT16 FCV_NUM1 = (0xf);
MX_UINT16 FCV_CON = (0x0);
//ADC(0): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = Which ADC Channel
c = Acquisition time
d = Conversion Speed
e = VRef+ Option
f = VRef Voltage x 0.01V
******************************/
//Common Defines
#define ADC_1_MX_ADC_CHANNEL 1
#define ADC_1_MX_ADC_ACTIME 40
#define ADC_1_MX_ADC_CONVSP 3
#define ADC_1_MX_ADC_VREFOP 0
#define ADC_1_MX_ADC_VREFVOL 500
#ifndef MX_ADC_CHANNEL_1
#define MX_ADC_CHANNEL_1 //Inform CAL ADC channel 1 is now in use.
#endif
#ifndef MX_ADC_REF //Inform CAL ADC peripheral is
now in use
#define MX_ADC_REF
#endif
extern void FC_CAL_Enable_ADC (MX_UINT8 Channel, MX_UINT8 Conv_Speed,
MX_UINT8 Vref, MX_UINT8 T_Charge);
extern MX_UINT16 FC_CAL_Sample_ADC (MX_UINT8 Sample_Mode);
extern void FC_CAL_Disable_ADC (void);
44
//ADC(0): //Macro function declarations
void FCD_ADC0_SampleADC();
MX_UINT8 FCD_ADC0_ReadAsByte();
MX_UINT16 FCD_ADC0_ReadAsInt();
MX_FLOAT FCD_ADC0_ReadAsVoltage();
void FCD_ADC0_ReadAsString(MX_CHAR* FCR_RETVAL, MX_UINT8
FCR_RETVAL_SIZE);
void FCD_ADC0_ADC_RAW_Configure_Channel();
MX_UINT8 FCD_ADC0_ADC_RAW_Sample_Channel_Byte();
MX_UINT16 FCD_ADC0_ADC_RAW_Sample_Channel_Int();
MX_UINT8 FCD_ADC0_ADC_RAW_Average_Channel_Byte(MX_UINT8 NumSamples,
MX_UINT8 DelayUs);
MX_UINT16 FCD_ADC0_ADC_RAW_Average_Channel_Int(MX_UINT8 NumSamples,
MX_UINT8 DelayUs);
void FCD_ADC0_ADC_RAW_Disable_Channel();
//LCDDisplay(0): //Defines:
/**** Macro Substitutions ****
a = Unique Component Reference Number
b = D1 Port Letter
c = D2 Port Letter
d = D3 Port Letter
e = D4 Port Letter
f = RS Port Letter
g = E Port Letter
h = Data 1_Pin
i = Data 2 Pin
j = Data 3 Pin
k = Data 4 Pin
l = RS Pin
45
m = Enable Pin
n = Row Count
o = Column Count
******************************/
//component connections
#define LCD_2__PORT0 portb
#define LCD_2__PORT1 portb
#define LCD_2__PORT2 portb
#define LCD_2__PORT3 portb
#define LCD_2__PORT4 portb
#define LCD_2__PORT5 portb
#define LCD_2__TRIS0 trisb
#define LCD_2__TRIS1 trisb
#define LCD_2__TRIS2 trisb
#define LCD_2__TRIS3 trisb
#define LCD_2__TRIS4 trisb
#define LCD_2__TRIS5 trisb
#define LCD_2__BIT0 5
#define LCD_2__BIT1 4
#define LCD_2__BIT2 3
#define LCD_2__BIT3 2
#define LCD_2__RS 7
#define LCD_2__E 6
#define LCD_2__ROWCNT 2
#define LCD_2__COLCNT 16
#ifdef _BOOSTC
#define LCD_2__DELAY delay_10us(10)
#endif
46
#ifdef _C2C_
#define LCD_2__DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_2__DELAY __delay_us(120)
#endif
#ifndef LCD_2__DELAY
#define LCD_2__DELAY delay_us(100)
#endif
//LCDDisplay(0): //Macro function declarations
void FCD_LCDDisplay0_RawSend(MX_UINT8 in, MX_UINT8 mask);
void FCD_LCDDisplay0_Start();
void FCD_LCDDisplay0_Clear();
void FCD_LCDDisplay0_PrintASCII(MX_UINT8 Character);
void FCD_LCDDisplay0_Command(MX_UINT8 in);
void FCD_LCDDisplay0_Cursor(MX_UINT8 x, MX_UINT8 y);
void FCD_LCDDisplay0_PrintNumber(MX_SINT16 Number);
void FCD_LCDDisplay0_PrintString(MX_STRING String, MX_UINT8 MSZ_String);
void FCD_LCDDisplay0_ScrollDisplay(MX_UINT8 Direction, MX_UINT8 Num_Positions);
void FCD_LCDDisplay0_ClearLine(MX_UINT8 Line);
void FCD_LCDDisplay0_RAM_Write(MX_UINT8 nIdx, MX_UINT8 d0, MX_UINT8 d1,
MX_UINT8 d2, MX_UINT8 d3, MX_UINT8 d4, MX_UINT8 d5, MX_UINT8 d6, MX_UINT8
d7);
//LED(0): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = LED Port Letter
c = LED Pin Number
d = LED Active Polarity
47
******************************/
#define LED_3__LED_PORT portd
#define LED_3__LED_TRIS trisd
#define LED_3__LED_PIN 2
#define LED_3__LED_POLE 1
//LED(0): //Macro function declarations
void FCD_LED0_LEDOn();
void FCD_LED0_LEDOff();
//LED(1): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = LED Port Letter
c = LED Pin Number
d = LED Active Polarity
******************************/
#define LED_4__LED_PORT portd
#define LED_4__LED_TRIS trisd
#define LED_4__LED_PIN 3
#define LED_4__LED_POLE 1
//LED(1): //Macro function declarations
void FCD_LED1_LEDOn();
void FCD_LED1_LEDOff();
//SWITCH(0): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = Switch Port Letter
c = Switch Pin Number
d = Switch Polarity Control
48
e = Switch Debounce Delay Value (us)
******************************/
#define Switch_5_SW_PORT portc
#define Switch_5_SW_TRIS trisc
#define Switch_5_SW_PIN 3
#define Switch_5_SW_POLE 0
#define Switch_5_SW_DELAY 0 * 1000
//SWITCH(0): //Macro function declarations
MX_UINT8 FCD_SWITCH0_ReadState();
void FCD_SWITCH0_WaitUntilHigh();
void FCD_SWITCH0_WaitUntilLow();
//SWITCH(1): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = Switch Port Letter
c = Switch Pin Number
d = Switch Polarity Control
e = Switch Debounce Delay Value (us)
******************************/
#define Switch_6_SW_PORT portd
#define Switch_6_SW_TRIS trisd
#define Switch_6_SW_PIN 0
#define Switch_6_SW_POLE 0
#define Switch_6_SW_DELAY 0 * 1000
//SWITCH(1): //Macro function declarations
MX_UINT8 FCD_SWITCH1_ReadState();
void FCD_SWITCH1_WaitUntilHigh();
void FCD_SWITCH1_WaitUntilLow();
49
//Definitions for RS232 UART slot allocation
#ifndef MX_UART_REF1
#define MX_UART_REF1
#define RS232_8_MX_UART_UREF 1
#define MX_UART_CHANNEL_1 1
#define MX_UART_TX_PIN_1 0
#define MX_UART_TX_PORT_1 porta
#define MX_UART_TX_TRIS_1 trisa
#define MX_UART_RX_PIN_1 0
#define MX_UART_RX_PORT_1 porta
#define MX_UART_RX_TRIS_1 trisa
#define MX_UART_FLOWEN_1 0
#define MX_UART_CTS_PIN_1 4
#define MX_UART_CTS_PORT_1 portc
#define MX_UART_CTS_TRIS_1 trisc
#define MX_UART_RTS_PIN_1 0
#define MX_UART_RTS_PORT_1 portc
#define MX_UART_RTS_TRIS_1 trisc
#define MX_UART_BAUD_1 9600
#define MX_UART_DBITS_1 8
#define MX_UART_RETURN_1 0
#define MX_UART_ECHO_1 0
#define MX_UART_INT_1 0
#else
#ifndef MX_UART_REF2
#define MX_UART_REF2
#define RS232_8_MX_UART_UREF 2
#define MX_UART_CHANNEL_2 1
50
#define MX_UART_TX_PIN_2 0
#define MX_UART_TX_PORT_2 porta
#define MX_UART_TX_TRIS_2 trisa
#define MX_UART_RX_PIN_2 0
#define MX_UART_RX_PORT_2 porta
#define MX_UART_RX_TRIS_2 trisa
#define MX_UART_FLOWEN_2 0
#define MX_UART_CTS_PIN_2 4
#define MX_UART_CTS_PORT_2 portc
#define MX_UART_CTS_TRIS_2 trisc
#define MX_UART_RTS_PIN_2 0
#define MX_UART_RTS_PORT_2 portc
#define MX_UART_RTS_TRIS_2 trisc
#define MX_UART_BAUD_2 9600
#define MX_UART_DBITS_2 8
#define MX_UART_RETURN_2 0
#define MX_UART_ECHO_2 0
#define MX_UART_INT_2 0
#else
#ifndef MX_UART_REF3
#define MX_UART_REF3
#define RS232_8_MX_UART_UREF 3
#define MX_UART_CHANNEL_3 1
#define MX_UART_TX_PIN_3 0
#define MX_UART_TX_PORT_3 porta
#define MX_UART_TX_TRIS_3 trisa
#define MX_UART_RX_PIN_3 0
#define MX_UART_RX_PORT_3 porta
51
#define MX_UART_RX_TRIS_3 trisa
#define MX_UART_FLOWEN_3 0
#define MX_UART_CTS_PIN_3 4
#define MX_UART_CTS_PORT_3 portc
#define MX_UART_CTS_TRIS_3 trisc
#define MX_UART_RTS_PIN_3 0
#define MX_UART_RTS_PORT_3 portc
#define MX_UART_RTS_TRIS_3 trisc
#define MX_UART_BAUD_3 9600
#define MX_UART_DBITS_3 8
#define MX_UART_RETURN_3 0
#define MX_UART_ECHO_3 0
#define MX_UART_INT_3 0
#else
#ifndef MX_UART_REF4
#define MX_UART_REF4
#define RS232_8_MX_UART_UREF 4
#define MX_UART_CHANNEL_4 1
#define MX_UART_TX_PIN_4 0
#define MX_UART_TX_PORT_4 porta
#define MX_UART_TX_TRIS_4 trisa
#define MX_UART_RX_PIN_4 0
#define MX_UART_RX_PORT_4 porta
#define MX_UART_RX_TRIS_4 trisa
#define MX_UART_FLOWEN_4 0
#define MX_UART_CTS_PIN_4 4
#define MX_UART_CTS_PORT_4 portc
#define MX_UART_CTS_TRIS_4 trisc
52
#define MX_UART_RTS_PIN_4 0
#define MX_UART_RTS_PORT_4 portc
#define MX_UART_RTS_TRIS_4 trisc
#define MX_UART_BAUD_4 9600
#define MX_UART_DBITS_4 8
#define MX_UART_RETURN_4 0
#define MX_UART_ECHO_4 0
#define MX_UART_INT_4 0
#endif
#endif
#endif
#endif
//LED(2): //Defines:
/**** Macro Substitutions ****
a = Unique Reference
b = LED Port Letter
c = LED Pin Number
d = LED Active Polarity
******************************/
#define LED_9__LED_PORT portc
#define LED_9__LED_TRIS trisc
#define LED_9__LED_PIN 5
#define LED_9__LED_POLE 1
//LED(2): //Macro function declarations
void FCD_LED2_LEDOn();
void FCD_LED2_LEDOff();
//ADC(0): //Macro implementations
void FCD_ADC0_SampleADC()
53
{
//unused
}
void FCD_LCDDisplay0_Start()
{
FC_CAL_Bit_Low_DDR(LCD_2__PORT0, LCD_2__TRIS0, LCD_2__BIT0);
FC_CAL_Bit_Low_DDR(LCD_2__PORT1, LCD_2__TRIS1, LCD_2__BIT1);
FC_CAL_Bit_Low_DDR(LCD_2__PORT2, LCD_2__TRIS2, LCD_2__BIT2);
FC_CAL_Bit_Low_DDR(LCD_2__PORT3, LCD_2__TRIS3, LCD_2__BIT3);
FC_CAL_Bit_Low_DDR(LCD_2__PORT4, LCD_2__TRIS4, LCD_2__RS);
FC_CAL_Bit_Low_DDR(LCD_2__PORT5, LCD_2__TRIS5, LCD_2__E);
Wdt_Delay_Ms(12);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x32, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x2c, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x06, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x0c, 0);
Wdt_Delay_Ms(2);
//clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
54
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Clear()
{
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintASCII(MX_UINT8 Character)
{
FCD_LCDDisplay0_RawSend(Character, 0x10);
}
void FCD_LCDDisplay0_Command(MX_UINT8 in)
{
FCD_LCDDisplay0_RawSend(in, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Cursor(MX_UINT8 x, MX_UINT8 y)
{
#if (LCD_2__ROWCNT == 1)
y=0x80;
#endif
#if (LCD_2__ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
55
#endif
#if (LCD_2__ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;
#if (LCD_2__COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif
#if (LCD_2__COLCNT == 20)
else if (y==2)
y=0x94;
else
y=0xd4;
#endif
#endif
FCD_LCDDisplay0_RawSend(y+x, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintNumber(MX_SINT16 Number)
{
MX_SINT16 tmp_int;
MX_UINT8 tmp_byte;
if (Number < 0)
{
56
FCD_LCDDisplay0_RawSend('-', 0x10);
Number = 0 - Number;
}
tmp_int = Number;
if (Number >= 10000)
{
tmp_byte = tmp_int / 10000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 10000;
tmp_byte--;
}
}
if (Number >= 1000)
{
tmp_byte = tmp_int / 1000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 1000;
tmp_byte--;
}
}
if (Number >= 100)
{
tmp_byte = tmp_int / 100;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
57
while (tmp_byte > 0)
{
tmp_int = tmp_int - 100;
tmp_byte--;
}
}
#if (LCD_2__ROWCNT == 2)
rowcount=40;
#endif
#if (LCD_2__ROWCNT == 4)
#if (LCD_2__COLCNT == 16)
rowcount=16;
#endif
#if (LCD_2__COLCNT == 20)
rowcount=20;
#endif
#endif
//Start at beginning of the line
FCD_LCDDisplay0_Cursor (0, Line);
//Send out spaces to clear line
for (count = 0; count < rowcount; count++)
FCD_LCDDisplay0_RawSend(' ', 0x10);
//Move back to the beginning of the line.
FCD_LCDDisplay0_Cursor (0, Line)
}
void FCD_LCDDisplay0_RAM_Write(MX_UINT8 nIdx, MX_UINT8 d0, MX_UINT8 d1,
MX_UINT8 d2, MX_UINT8 d3, MX_UINT8 d4, MX_UINT8 d5, MX_UINT8 d6, MX_UINT8
d7)
{
58
//set CGRAM address
FCD_LCDDisplay0_RawSend(64 + (nIdx << 3), 0);
delay_ms(2);
//write CGRAM data
FCD_LCDDisplay0_RawSend(d0, 0x10);
FCD_LCDDisplay0_RawSend(d1, 0x10);
FCD_LCDDisplay0_RawSend(d2, 0x10);
FCD_LCDDisplay0_RawSend(d3, 0x10);
FCD_LCDDisplay0_RawSend(d4, 0x10);
FCD_LCDDisplay0_RawSend(d5, 0x10);
FCD_LCDDisplay0_RawSend(d6, 0x10);
FCD_LCDDisplay0_RawSend(d7, 0x10);
//Clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
delay_ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
delay_ms(2);
}
//LED(0): //Macro implementations
void FCD_LED0_LEDOn()
{
#if( LED_3__LED_POLE == 1)
//Active high polarity
FC_CAL_Bit_High_DDR( LED_3__LED_PORT , LED_3__LED_TRIS , LED_3__LED_PIN );
#else
//Active low polarity
FC_CAL_Bit_Low_DDR( LED_3__LED_PORT , LED_3__LED_TRIS , LED_3__LED_PIN );
#endif
}
59
void FCD_LED0_LEDOff()
{
#if( LED_3__LED_POLE == 1)
//Active high polarity
FC_CAL_Bit_Low_DDR( LED_3__LED_PORT , LED_3__LED_TRIS , LED_3__LED_PIN
);
#else
//Active low polarity
FC_CAL_Bit_High_DDR( LED_3__LED_PORT , LED_3__LED_TRIS , LED_3__LED_PIN );
#endif
}
//LED(1): //Macro implementations
void FCD_LED1_LEDOn()
{
#if( LED_4__LED_POLE == 1)
//Active high polarity
FC_CAL_Bit_High_DDR( LED_4__LED_PORT , LED_4__LED_TRIS , LED_4__LED_PIN );
#else
//Active low polarity
FC_CAL_Bit_Low_DDR( LED_4__LED_PORT , LED_4__LED_TRIS , LED_4__LED_PIN );
#endif
}
void FCD_LED1_LEDOff()
{
#if( LED_4__LED_POLE == 1)
//Active high polarity
FC_CAL_Bit_Low_DDR( LED_4__LED_PORT , LED_4__LED_TRIS , LED_4__LED_PIN
);
#else
//Active low polarity
FC_CAL_Bit_High_DDR( LED_4__LED_PORT , LED_4__LED_TRIS , LED_4__LED_PIN );
60
#endif
}
//SWITCH(0): //Macro implementations
MX_UINT8 FCD_SWITCH0_ReadState()
{
MX_UINT8 switchval, old_switchval;
#if Switch_5_SW_DELAY > 0
MX_UINT16 del_count = 0;
#endif
FC_CAL_Bit_In_DDR( Switch_5_SW_PORT , Switch_5_SW_TRIS , Switch_5_SW_PIN );
switchval = FC_CAL_Bit_In( Switch_5_SW_PORT , Switch_5_SW_PIN );
//Convert pin to input
old_switchval = switchval;
#if Switch_5_SW_DELAY > 0
while (del_count < Switch_5_SW_DELAY)
//Debounce input
{
delay_us(1);
FC_CAL_Bit_In_DDR( Switch_5_SW_PORT , Switch_5_SW_TRIS , Switch_5_SW_PIN );
switchval = FC_CAL_Bit_In( Switch_5_SW_PORT , Switch_5_SW_PIN );
//Sample input
if (switchval == old_switchval) //Is
switch the same state?
del_count = del_count + 1; //Increment
counter
else
del_count = 0; //Else
reset counter
old_switchval = switchval;
//Update the old state
}
61
#endif
#if Switch_5_SW_POLE == 0
if (switchval)
//Invert logic if required
switchval = 0;
else
switchval = 1;
#endif
return (switchval);
//Return state of switch as least significant bit
}
void FCD_SWITCH0_WaitUntilHigh()
{
MX_UINT8 switchval, old_switchval;
#if Switch_5_SW_DELAY > 0
MX_UINT16 del_count = 0;
#endif
//Call Component Macro
//Call Component Macro: SW=ReadState()
FCV_SW = FCD_SWITCH0_ReadState();
//Call Component Macro
//Call Component Macro: SW1=ReadState()
FCV_SW1 = FCD_SWITCH1_ReadState();
//Decision
//Decision: SW = 0?
if (FCV_SW == 0)
{
//Calculation
//Calculation:
62
// CON = 1
FCV_CON = 1;
} else {
//Decision
//Decision: SW1 = 0?
if (FCV_SW1 == 0)
{
//Calculation
//Calculation:
// CON1 = 1
FCV_CON1 = 1;
// } else {
}
}
//Decision
//Decision: CON1 = 1?
if (FCV_CON1 == 1)
{
//Call Component Macro
//Call Component Macro: Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);
//Decision
//Decision: SEC = 1?
if (FCV_SEC == 1)
{
//Call Component Macro
//Call Component Macro: LEDOff()
63
FCD_LED0_LEDOff();
} else {
//Call Component Macro
//Call Component Macro: LEDOn()
FCD_LED0_LEDOn();
}
//Call Component Macro
//Call Component Macro: PrintString("TIME:")
FCD_LCDDisplay0_PrintString("TIME:", 5);
//Call Component Macro
//Call Component Macro: PrintNumber(NUM1)
FCD_LCDDisplay0_PrintNumber(FCV_NUM1);
//Call Component Macro
//Call Component Macro: PrintString(" ")
FCD_LCDDisplay0_PrintString(" ", 1);
//Calculation
//Calculation:
// NUM1 = NUM1 - 1
FCV_NUM1 = FCV_NUM1 - 1;
//Delay
//Delay: 1 s
delay_s(1);
//Decision
//Decision: NUM1 = 0?
if (FCV_NUM1 == 0)
{
//Decision
64
//Decision: SEC = 1?
if (FCV_SEC == 1)
{
//Calculation
//Calculation:
// SEC = 0
// CON1 = 0
// NUM1 = 15
FCV_SEC = 0;
FCV_CON1 = 0;
FCV_NUM1 = 15;
//Call Component Macro
//Call Component Macro: LEDOff()
FCD_LED1_LEDOff();
//Call Component Macro
//Call Component Macro: LEDOff()
FCD_LED0_LEDOff();
//Call Component Macro
//Call Component Macro: ClearLine(1)
FCD_LCDDisplay0_ClearLine(1);
//Delay
//Delay: 1 s
delay_s(1);
//Goto Connection Point
//Goto Connection Point: [A]: A
goto FCC_Main_A;
// } else {
}
65
//Call Component Macro
//Call Component Macro: PrintString("TIME:")
FCD_LCDDisplay0_PrintString("TIME:", 5);
//Call Component Macro
//Call Component Macro: PrintNumber(NUM)
FCD_LCDDisplay0_PrintNumber(FCV_NUM);
//Call Component Macro
//Call Component Macro: PrintString(" ")
FCD_LCDDisplay0_PrintString(" ", 1);
//Calculation
//Calculation:
// NUM = NUM - 1
FCV_NUM = FCV_NUM - 1;
//Delay
//Delay: 1 s
delay_s(1);
//Decision
//Decision: NUM = 0?
if (FCV_NUM == 0)
{
//Decision
//Decision: SEC = 1?
if (FCV_SEC == 1)
{
//Calculation
//Calculation:
// SEC = 0
// CON = 0
66
// NUM = 10
FCV_SEC = 0;
FCV_CON = 0;
FCV_NUM = 10;
//Call Component Macro
//Call Component Macro: LEDOff()
FCD_LED1_LEDOff();
//Call Component Macro
//Call Component Macro: LEDOff()
FCD_LED0_LEDOff();
//Call Component Macro
//Call Component Macro: ClearLine(1)
FCD_LCDDisplay0_ClearLine(1);
//Delay
//Delay: 1 s
delay_s(1);
//Goto Connection Point
//Goto Connection Point: [A]: A
goto FCC_Main_A;
// } else {
}
//Calculation
//Calculation:
// NUM = 10
// SEC = 1
FCV_NUM = 10;
FCV_SEC = 1;
//Call Component Macro
67
//Call Component Macro: LEDOn()
FCD_LED1_LEDOn();
68
FCD_LCDDisplay0_PrintNumber(FCV_DIS);
}
//Call Component Macro
//Call Component Macro: PrintString(" ")
FCD_LCDDisplay0_PrintString(" ", 1);
//Decision
//Decision: adc > 825?
if (FCV_ADC > 825)
{
//Call Component Macro
//Call Component Macro: Clear()
FCD_LCDDisplay0_Clear();
//Call Component Macro
//Call Component Macro: Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);
//Delay
//Delay: 500 ms
delay_ms(255);
delay_ms(245);
//Call Component Macro
//Call Component Macro: SendRS232Char(26)
FCD_RS2320_SendRS232Char(26);
//Delay
//Delay: 1 s
delay_s(1);
//Loop
//Loop: While 1
while (1)
69
{
}
// } else {
}
}
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}
70
REFERENCES:
[2] B. Delfino and F. Fornari, “Modeling and Control of an Integrated Fuel Cell-Wind
Turbine System,” in Proc. 2003 IEEE Bologna Power Tech Conf., pp. 23-26.
[3] A. Rowe and X. Li, “Mathematical Modeling of Proton Exchange Membrane Fuel
Cells,” Journal of Power Sources, pp. 82-96, 2001.
[5] O. Ulleberg, "Stand-alone Power Systems for the Future: Optimal Design, Operation
and Control of Solar-Hydrogen Energy Systems," Ph.D. dissertation, Norwegian
University of Science and Technology, 1997.
[8] D. B. Nelson, M. H. Nehrir, and C. Wang, “Unit Sizing and Cost Analysis of Stand
Alone Hybrid Wind/PV/FC Power Systems,” Renewable Energy, pp. 1641-1656, 2006.
[9] B. C. Kuo, Automatic control systems, 7th ed. New York: Prentice Hall Inc, 1995.
[10] Hung-Cheng Chen, Jian-Cong Qiu, and ChiaHao Liu “Dynamic Modeling and
Simulation of Renewable Energy Based Hybrid Power Systems,” DRPT, April 2008, pp.
2803-2809.
71
[11] Takyin Taky Chan, “Transient analysis of integrated solar/diesel hybrid power
system using MATLAB Simulink,” School of Electrical Engineering, Victoria
University.
[12] Guangming LI, Yuanrui CHEN, Tao LI “The Realization of Control Subsystem in
the Energy Management of Wind/Solar Hybrid Power System,” 3rd International
Conference on Power Electronics Systems and Applications, 2009.
72