Sei sulla pagina 1di 14

Pertandingan MySkills Ke-7

PERTANDINGAN MySkills

2013 (ELECTRONICS)

14 JAM

PERINGKAT AKHIR

NAMA: __________________________________________ NO. KP:__________________________________________

JABATAN PEMBANGUNAN KEMAHIRAN KEMENTERIAN SUMBER MANUSIA

Pertandingan MySkills Ke-7

Project : Programmable Incubator Time Limit: 14 hrs


This Project accesses each competitor to design PCB, assemble project; write an Embedded C code and test the developed prototype.

Project Description:
The incubator regulates temperature and humidity based on three (3) preset modes detailed in Table 1. The system monitors present temperature and humidity via the SHT 25 (I2C based Humidity and Temperature Sensor). Based on the selectable preset Mode, the incubator regulates system temperature and humidity. The block diagram of the incubator is shown in Fig. 1. Temperature is regulated by regularly switching ON and OFF the heater (bulb) which driven by the system through solid state relay (SSR). While humidity is controlled by switching ON or OFF the EXHAUST fan or MIX fan. The purposes of the EXHAUST and MIX fan to decrease and increase the system humidity respectively. On top of it, Start/Stop and MODE buttons were provided to start or stop the system and for incremental selecting of MODE. Each pressing of MODE button changes the MODE by a step of one (1). In the case of the present MODE is at a maximum (2) level, another pressing of MODE button resulting in the MODE resetting to 0. The complete schematic diagram is provided in Fig. 2.

Fig. 1: Block Diagram of the Programable Incubator

Table 1: Relationship of temperature and humidity with the selected mode.


Type of birds Chicken Goose Dove MODE 0 1 2 TEMPERATURE 28 0.5C 30 0.5C 32 0.5C HUMIDITY(min) 10% 12% 14% HUMIDITY(max) 14% 16% 18%

Pertandingan MySkills Ke-7

LCD1
LM016L +5v Vo VEE

+5v Vo Pin16 (lcd)

PICKIT3

J1
66226-006 PWM0 1 2

+12v

J4

RV1
VSS VDD VEE 10K RS RW E D0 D1 D2 D3 D4 D5 D6 D7

Output For AC 240V bulb 200w control via Solid State Relay

J2 D2
1N4001 1 2

R5
1 2 3 4 5 6 33R

SIL-156-02

U5:A
4066 MCLR +5V PGD PGC Pin15 (lcd) PWM1 +5v Vo C IO 12 1 X Y 2

Output For 12V DC Auxiliary Fan (EXHAUST Fan) SIL-100-02

Q3 R8
120R IRF540N

1 2 3

4 5 6 IO2 IO 1 IO 0

VEE

IO 4 IO 5 IO 6 IO 7

7 8 9 10 11 12 13 14

R9
10k

R7
10k +5v Vo +5v Vo

13

+5v Vo

+12v

R6
1k

J3 Q1
BC547

R3
10k

R4
10k +5v Vo IO 10 IO 11 +5v Vo

D3
1N4001

1 2

Output For 12V DC Auxiliary Fan (MIX Fan)

U5:B
4066 11 X C Y 10

SIL-100-02

Q2 R10
120R IRF540N

R12
10k

R13
10k

+5v Vo

100n

100n

SCL SDA

1 2 3 4

SHT25 HUMIDITY & TEMPERATURE SENSOR - I2C SIL-156-04

OSC1

OSC2

SDA SCL IO8 IO9

SS ANA0 ANA1 ANA2 ANA3 T0CKI ANA4 OSC2 OSC1

U1
2 3 4 5 6 7 14 13 33 34 35 36 37 38 39 40 RA0/AN0 RC0/T1OSO/T1CKI RA1/AN1 RC1/T1OSI/CCP2/UOE RA2/AN2/VREF-/CVREF RC2/CCP1/P1A RA3/AN3/VREF+ RC4/D-/VM RA4/T0CKI/C1OUT/RCV RC5/D+/VP RA5/AN4/SS/LVDIN/C2OUT RC6/TX/CK RA6/OSC2/CLKO RC7/RX/DT/SDO OSC1/CLKI RB0/AN12/INT0/FLT0/SDI/SDA RB1/AN10/INT1/SCK/SCL RB2/AN8/INT2/VMO RB3/AN9/CCP2/VPO RB4/AN11/KBI0/CSSPP RB5/KBI1/PGM RB6/KBI2/PGC RB7/KBI3/PGD RD0/SPP0 RD1/SPP1 RD2/SPP2 RD3/SPP3 RD4/SPP4 RD5/SPP5/P1B RD6/SPP6/P1C RD7/SPP7/P1D RE0/AN5/CK1SPP RE1/AN6/CK2SPP RE2/AN7/OESPP RE3/MCLR/VPP 15 16 17 23 24 25 26 19 20 21 22 27 28 29 30 8 9 10 1 T1CKI PWM1 PWM0 +12v TX/RC6 RX/RC7 SDO IO0 IO1 IO2 IO3 IO4 IO5 IO6 IO7 IO16 IO17 IO18 MCLR 1N4001

+12v

D1
1

7805 VI GND VO 3 Coupling for microcontroller

12VDC 2A Adaptor
0v

C6
25v/22uF

C7
25V/22uF

C8
25V/22uF

+5v

+5v

MCLR

U2

+5V

12

C12

MODE

C13

START/STOP

J5

R11
10k

X1 C3 C2
27p 100n

R2
680

IO10 IO11 IO12 IO13 IO14 IO15 PGM PGC PGD VUSB

+12v

U3
7805 1 VI GND VO 3

16MHz +5v Vo

C4
100n

R1
10k

C1
27p

C5
220n MCLR

18

VUSB PIC18F4550

C10
25v/22uF

C11
25V/22uF

Fig. 2: Schematic Diagram of the Programable Incubator

Pertandingan MySkills Ke-7

Task 1 Design a single-sided Printed Circuit Board (PCB) based on the GIVEN schematic diagram in Fig 2. Task 2 Assemble components on the designed PCB. Task 3 Build and fix the prototype with all the accessories Task 4 Write an embedded C code as follows. Use the provided drivers. 4.1. Upon Power Up / Reset; heater, EXHAUST and MIX fan should be OFF. The preset power (P) and Mode (M) should be OFF and 0 respectively. These are displayed on the LCD following the format shown below.

Note: XX is the preset temperature YY is the preset humidity 4.2. Upon pressing of the Start/Stop Button (PB1) for the first time; P must indicates ON. System regulates heat and humidity based on in the preset Mode in task 4.1. The display must be update as shown below.

Note: XX is the preset temperature YY is the preset humidity 4.3. Continuously pressing the Start/Stop Button (PB1), P toggling. System turns ON if previous P is OFF or vice versa. Each changing in P should be accompanied by changing of the string ON to OFF or vice versa.

Pertandingan MySkills Ke-7

4.4.

If the MODE button (PB2) is pressed, M advances by one (1). It rolls off to 0 when it reaches 3. The display must be updated for each changing in M.

Task 5

Test and verify the functionality of the designed protoype

Marking scheme: Item 1 2 3 4 5 6 Description


Funtionality of Developed Protoype Quality of Wiring Quality of Component Assembly Quality of Soldering Design of PCB board Quality of Mechanical Assembly

Weight 50% 6% 6% 6% 20% 12% 5

Score

Pertandingan MySkills Ke-7

Parts List (Table 2) Item 1 Parts name and value RESISTORS CORBON TYPE 1/4W 5%

Qty

Reference number

33R 120R 680R 1K 10K Trim Pot Preset PCB Type 10K

1 2 1 1 8 1

CAPACITORS

22uF 25v (Electrolytic) 100nF (ceramic) 220nF (ceramic) 27pF (ceramic)

6 4 1 2

SEMICONDUCTOR COMPONENTS PIC 18F4550 c/w socket Voltage Regulator 7805 c/w Heatsink IC 4066 Transistor BC547 MOSFET IRF540N C/W Heatsink Diod IN4001 1 2 1 1 2 3 1

OTHERS Copper board 25cm x 11cm LPKF single sided PCB FR4 229x305x1.5mm with reference hole fiber glass type LCD LM016L Crystal 16Mhz 6 pin PCB Header 45 degree bend Random turn ON Solid State Relay CSW2410FPGSH-10 12V DC Auxiliary Fan Saiz 80mm X 80mm X 25mm Normaly Open PCB Miniture Push Button Switch 16 Pin Female Header 16 Pin Male Header 6

1 1 1 1 2 3 1 1

Pertandingan MySkills Ke-7

AC Bulb C/W Screw type Lamp Holder - 240VAC 200Watt Connector - Header 2 PIN Connector - Header 5 PIN Ribbon cable - 16 way 10 meter Aqua Star Aquarium Tank completed with top cover material is Acrylic ,Saiz 30 x 18 x 25.5cm DC Adapter C/W female conector 12VDC 2A SHT25 HUMIDITY & TEMPERATURE SENSOR - I2C

1 3 1 1 1 1 1

The competitor needs to prepare the following equipments, machinery, installations and materials. Item
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Qty
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Material
Soldering Iron and equipment Soldering Iron Stand Solder wick or Solder Remover Brush Pincer Nipper Wire Stripper Scissors Tweezers IC pick PCB stand Parts box Precise screwdriver Screw driver Screw driver Spanner Safety Glasses

Description

Notes

For trimmer resistor + type - type

Pertandingan MySkills Ke-7

Filename: main file.c


#include "header file 1.h" // include files and global variables void main(void){ short char CmpTest; unsigned char i=0; ADCON1= 0b001111; CMCON = 0b00000111; Initialize_LCD(); send_control(0x82); putr_lcd("Given Codes"); send_control(0xc3); putr_lcd("PKM 2013");

// Digital I/O // off comparator pg 234 // Must be called prior to usage of LCD

while(1){ }// while } //Main /* ---------------------End of File --------------------------*/

Filename: header file 1.h


#include <p18f4550.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <delays.h> #include <math.h> #include <adc.h> #include <stdio.h> #include <delays.h> #include <pwm.h> #include <timers.h> #include <i2c.h> #include "lcd 2x16 COM2013.c" #include "SHT 25.c" #pragma config FOSC=XT_XT, PWRT = OFF,BOR = OFF, MCLRE = ON, ICPRT = OFF, WDT=OFF, LVP=OFF, DEBUG=OFF /* ---------------------End of File --------------------------*/

Filename: lcd 2 x 16 COM3013.c


/* Filename: lcd 2x16 COM2013.c Date: 20/12/2012 Author: Ismail b. Adam Email: ismail_adam@yahoo.com Revision: 1 Depedency: lcd 2x16 COM2013.h */ #include "lcd 2x16 COM2013.h" //continue

Pertandingan MySkills Ke-7


//continuation /*Provide 18 instruction cycles for LCD internal delay*/ void DelayFor18TCY( void ) { unsigned char i; for (i=0; i<38; i++) Nop(); }

unsigned char check_busy(void){ LCD_RS = 0; LCD_RW = 1; LCD_DATA_TRIS |= 0x0f0; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); if (LCD_DATA&0x80){ LCD_E = DelayFor18TCY(); LCD_E = DelayFor18TCY(); LCD_E = DelayFor18TCY(); return 1; } else{ LCD_E = DelayFor18TCY(); LCD_E = DelayFor18TCY(); LCD_E = DelayFor18TCY(); return 0; } } void send_control(char CMD){ while(check_busy()); LCD_DATA_TRIS &= 0x0f; LCD_DATA &= 0x0f; LCD_DATA |= (CMD&0xf0); LCD_RS = 0; LCD_RW = 0; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); LCD_E = 0; DelayFor18TCY(); LCD_DATA &= 0x0f; LCD_DATA |= ((CMD<<4) & 0xf0); DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); LCD_E = 0; DelayFor18TCY(); } 0; 1; 0;

// Logic 0 // Logic 1 // Set data line as input // pull high clock // if b7 high // pull down clock // complete for another nibble // pull high clock // pull down clock

0; 1; 0;

// if b7 low // pull down clock // complete for another nibble // pull high clock // pull down clock

// Set data line as output // clear previous higher nibble on data line // put higher nibble // Logic 0 // Logic 0 // pull high clock // pull down clock // clear previous higher nibble on data line // put lower nibble // pull high clock // pull down clock

//continue

Pertandingan MySkills Ke-7


//continuation void Four_bit_only (char x){ while(check_busy()); LCD_DATA_TRIS &= 0x0f; LCD_DATA &= 0x0f; LCD_DATA |= (x & 0xf0); LCD_RS = 0; LCD_RW = 0; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); LCD_E = 0; DelayFor18TCY(); }

// Set data line as output // clear previous higher nibble on data line // put higher nibble // Logic 0 // Logic 0 // pull high clock // pull down clock

void send_data(char x){ while(check_busy()); LCD_DATA_TRIS &= 0x0f; // Set data line as output LCD_DATA &= 0x0f; // clear previous higher nibble on data line LCD_DATA |= x & 0xf0; // put higher nibble LCD_RS = 1; LCD_RW = 0; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); LCD_E = 0; DelayFor18TCY(); LCD_DATA &= 0x0f; LCD_DATA |= ((x<<4) & 0xf0); DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); LCD_E = 0; DelayFor18TCY(); } char read_data(void){ char x; while(check_busy()); LCD_DATA_TRIS |= 0xf0; LCD_RS = 1; LCD_RW = 1; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); x = LCD_DATA&0xf0; LCD_E = 0; DelayFor18TCY(); LCD_E = 1; DelayFor18TCY(); x |= (LCD_DATA>>4) &0x0f; LCD_E = 0; return x; } // Logic 1 // Logic 0 // pull high clock // pull down clock // clear previous higher nibble on data line // put lower nibble // pull high clock // pull down clock

// Set data line as input // Logic 1 // Logic 1 // pull high clock

// pull down clock // pull high clock

// pull down clock

//Continue

10

Pertandingan MySkills Ke-7


//continuation /* Print the string from the buffer pointed by pointer*/ void puts_lcd(char *pointer){ while(*pointer){ send_data(*pointer); pointer++; } } // print till null encountered

void putr_lcd(const rom char *pointer){ while(*pointer){ // WHILE NOT NULL CHARACTER send_data(*pointer); pointer++; } } void Initialize_LCD(void){ LCD_DATA_TRIS = 0b00000000; LCD_E = 0; LCD_RS = 0; LCD_RW = 0; Delay1KTCYx(250); Four_bit_only(0b00100000); send_control(0b00101000); send_control(0b00001110 ); send_control(0b00000110); }

// Set all // // // // // // // //

lines as output Logic 0 Logic 0 Logic 0 15ms (1)1st Function Set (2)2nd Function Set (3)Display & cursor (4)Entry mode - inc

- 4-bit (entry 1 T12) - 4-bit, 2 lines, 5X7 (entry 6 T6) on/off (entry 4 T6) addr, no shift (entry 3 T6)

/*---------------------End of lcd 2 x 16 COM2013.c --------------------------------------------*/

Filename: lcd 2 x 16 COM3013.h


/* Filename: lcd 2x16 COM2013.h Date: 20/12/2012 Author: Ismail b. Adam Email: ismail_adam@yahoo.com Revision: 1 Depedency: delay.h This free 2 x 16 LCD driver are provided as is without any guarantees or warranty. Although the author has attempted to find and correct any bugs in the codes, the author is not responsible for any damage or losses of any kind caused by the use or misuse of the codes. The author is under no obligation to provide support, service, corrections, or upgrades to the programs. */ /* definitions of PINs connected to 2 x 16 LCD*/ #define LCD_DATA PORTD #define LCD_DATA_TRIS TRISD #define LCD_E PORTDbits.RD0 // EN signal for LCD #define TRIS_LCD_E TRISDbits.TRISD0 #define LCD_RS PORTDbits.RD2 // RS signal for LCD #define TRIS_LCD_RS TRISDbits.TRISD2 #define LCD_RW PORTDbits.RD1 // RW signal for LCD #define TRIS_LCD_RW TRISDbits.TRISD1

//continue

11

Pertandingan MySkills Ke-7


//continuation void DelayFor18TCY( void ); /*Provides 18 instruction cycles for LCD internal delay*/ unsigned char check_busy(void); /* Checks busy flag which is b7 of the LCD lines. It returns 1 on busy or 0 on not busy. It could be called as: while(check_busy()); // wait here till not busy */ void send_control(char CMD); /* Sends command (RS=0 and RW =0) to LCD. Returns: None Example used: send_control(x); where x is any character that define as LCD command For detail please refer to HD44780U (LCD-II) - page 199*/ void Four_bit_only(char CMD); /* Sends only the higher nibble of the given character. Returns: None Example used: Four_bit_only(x:y); sends x only to LCD */ void send_data(char x); /* Sends data (RS=1 and RW =0) to LCD. Returns: None Example used: send_data(x); where x is any character to be displayed on the LCD For detail please refer to HD44780U (LCD-II) - page 199*/ char read_data(void); /* Reads data (RS=1 and RW =1) from the set address. Returns: Character whuch is pointed by the CURSOR Example used: x = read_data(); Note: x must be defined as character*/ void puts_lcd(char *pointer); /* Prints the string from the buffer pointed by pointer. The string can be defined on the program RAM/register as char array1[]="Just testing"; Returns: None Example used: puts_lcd(array1); */ void putr_lcd(const rom char *pointer); /* Prints the string from the buffer pointed by pointer. The string can be defined on the program ROM as char const rom array1[]="Just testing"; Returns: None Example used: 1. putr_lcd(array1); 2. putr_lcd("ASC 2012); */ void Initialize_LCD(void); /*Initializes the LCD and must be called once by the main function. For detail please refer to HD44780U (LCD-II) - page 207*/ /*---------------------End of lcd 2 x 16 COM2013.h --------------------------------------------*/

12

Pertandingan MySkills Ke-7

Filename: SHT 25.h

#define Trig_T_HM #define Trig_H_HM

0b11100011 0b11100101

unsigned int read_temperature(void); unsigned int read_humidity(void); /* ---------------------End of File --------------------------*/

Filename: SHT 25.c


unsigned int read_temperature(void){ char TempHI,TempLO,CHK_SUM; StartI2C(); IdleI2C(); WriteI2C(add2write); IdleI2C(); WriteI2C(Trig_T_HM); IdleI2C(); WriteI2C(add2read); IdleI2C(); TempHI = ReadI2C(); IdleI2C(); AckI2C(); IdleI2C(); TempLO = ReadI2C(); IdleI2C(); AckI2C(); IdleI2C(); // // wait till bus idle // trigger Temperature // wait till bus idle // // wait till bus idle // get the MSB // Send back Acknowledge // get the LSB // Send back Acknowledge

// begin I2C communication // wait till bus idle

CHK_SUM = ReadI2C(); // get the Checksum IdleI2C(); NotAckI2C(); // Send back Acknowledge IdleI2C(); StopI2C(); // stop all I2C communications return (TempHI<<8)+ TempLO } //continue

13

Pertandingan MySkills Ke-7

//continuation

unsigned int read_humidity(void){ char HumHI,HumLO,CHK_SUM; StartI2C(); IdleI2C(); WriteI2C(add2write); IdleI2C(); WriteI2C(Trig_H_HM); IdleI2C(); WriteI2C(add2read); IdleI2C(); HumHI = ReadI2C(); IdleI2C(); AckI2C(); IdleI2C(); HumLO = ReadI2C(); IdleI2C(); AckI2C(); IdleI2C(); //

// begin I2C communication // wait till bus idle // wait till bus idle // trigger Humidity // wait till bus idle // // wait till bus idle // get the MSB // Send back Acknowledge // get the LSB // Send back Acknowledge

CHK_SUM = ReadI2C(); // get the Checksum IdleI2C(); NotAckI2C(); // Send back Acknowledge IdleI2C(); StopI2C(); // stop all I2C communications return (HumHI<<8)+ HumLO } /* ---------------------End of File --------------------------*/

14

Potrebbero piacerti anche