You are on page 1of 11

Pertandingan Myskills Ke-7

PERTANDINGAN MySkills 2013

(ELECTRONICS)

6 JAM PERINGKAT PRA-KELAYAKAN

NAMA: __________________________________________

NO. KP:__________________________________________

JABATAN PEMBANGUNAN KEMAHIRAN KEMENTERIAN SUMBER MANUSIA 1

Project : Heater Display Input Panel Time Limit: 6 hrs This project accesses each competitor to design, assemble, write an embedded C code and test project. Project Description: In this project, three (3) switches were provided for user preference. If the correct selection is made by pressing any of the push button, the selected option will be displayed on the first row of the LCD. This is done by centered displaying the string represents the selection made such HOT for HOT selection. Buzzer is activated two (2) times at the end of selection. In the case of more than one (1) button were pressed, the string ERROR will be centered displaying on the second row of the LCD; buzzer beeps for three (3) times.

Figure 1 (Block Diagram)

Pertandingan Myskills Ke-7

Schematic Diagram
MCLR

Coupling for microcontroller


OSC1 OSC2

+5v

+5v

PICKIT3

LCD1
LM016L +5v IO
VEE

X1 C6 C5
27p 100nF

680R

J1
66226-006

16MHz

C7
100nF

R8
10k
1 2 3 4 5 6 VSS VDD VEE RS RW E D0 D1 D2 D3 D4 D5 D6 D7

C4
27p

R10
33R

C8
220n
MCLR MCLR +5V PGD PGC

1 2 3

4 5 6

7 8 9 10 11 12 13 14

+5v IO

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 T1CKI PWM1 PWM0

TX/RC6 RX/RC7 SDO IO0 IO1 IO2 IO3 IO4 IO5 IO6 IO7 IO16 IO17 IO18 MCLR

IO10 IO11 IO12 IO13 IO14 IO15 PGM PGC PGD VUSB

1N4001

18

VUSB PIC18F4550

8 9 10 1

C9
25v/22uF 0v

GND

19 20 21 22 27 28 29 30

+12v

U2 D2
+12v 1 7805 VI VO 3

+5V

C10
25V/22uF

C11
25V/22uF

Figure 2

pin15 (lcd)

VEE

IO2 IO 1 IO 0

IO 4 IO 5 IO 6 IO 7

pin16 (lcd)

R9

+5v IO

Pertandingan MySkills Ke-7

Marking scheme: Item 1 2 3 4 5 Description Design circuit Functionality Component assembly Soldering quality Wiring/jumper quality Weight 30% 40% 10% 10% 10% Score

Parts List (Table 1)

ITEM 1

PARTS NAME AND VALUE RESISTORS CORBON TYPE 1/4W 5% 33R 120R 200R 390R 680R 1K 10K 12K 20K Trim pot preset 10K PCB type CAPACITORS 10uF 25v (Electrolytic) 22uF 25v (Electrolytic) 10nF 100nF (ceramic) 220nF (ceramic) 27pF (ceramic) SEMICONDUCTOR COMPONENTS PIC 18F4550 c/w socket Voltage regulator 7805 c/w heatsink Transistor 2N3904 Transistor 2N3903 Diode IN4001 Diode IN4008 Diode IN914 OTHERS Strip board 25cm x 11cm LCD LM016L Crystal 16MHz

QTY 3 3 3 3 3 2 1 3 3 1

REFERENCE NUMBER

4 3 2 5 1 2 1 1 1 1 1 1 1 2 1 1

6 pin PCB Header 45 degree bend Buzzer 12Vdc PCB type Normaly Open PCB Miniture Push Button Switch 16 Pin Female Header 16 Pin Male Header Microchip PIC Kit 3 downloader

1 1 4 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 For trimmer resistor + type - type Description Notes

Filename: main file.c


#include "header file 1.h" // include files #include "header file 2.h" // definitions, global variables and function prototypes

void main(void){ unsigned char i,count; ADCON1= 0b001111; CMCON = 0b00000111; TRIS_PB1=1; TRIS_PB2=1; TRIS_PB3=1; TRIS_PWM0=0; PWM0=0; Initialize_LCD(); send_control(0x82); putr_lcd("Given Codes"); send_control(0xc3); putr_lcd("PKM 2013"); // Digital I/O // off comparator pg 234 // setting Push Button as input and PWM as output

// Must be called prior to usage of LCD

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

Filename: header file 1.h


#include #include #include #include #include #include <p18f4550.h> <string.h> <stdlib.h> <stdio.h> <delays.h> "lcd 2x16 COM2013.c"

#pragma config FOSC = HSPLL_HS // HS oscillator, PLL enabled (HSPLL) #pragma config PLLDIV = 4 // Divide by 4 (16 MHz oscillator input) #pragma config CPUDIV = OSC4_PLL6 // [Primary Oscillator Src: /4][96 MHz PLL Src: /6] #pragma config USBDIV = 2 // USB clock comes from 96 MHz PLL output / 2 #pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor #pragma config IESO = OFF // Disable Oscillator Switchover mode #pragma config PWRT = OFF // Disable Power-up timer #pragma config BOR = OFF // Disable Brown-out reset #pragma config VREGEN = ON // Use internal USB 3.3V voltage regulator #pragma config WDT = OFF // Disable Watchdog timer #pragma config MCLRE = ON // Enable MCLR Enable #pragma config LVP = OFF // Disable low voltage ICSP #pragma config ICPRT = OFF // Disable dedicated programming port (44-pin devices) #pragma config CP0 = OFF // Disable code protection /* ---------------------End of File --------------------------*/

Filename: header file 2.h


#define #define #define #define #define #define #define #define PB1 PORTBbits.RB2 PB2 PORTBbits.RB3 PB3 PORTBbits.RB4 PWM0 PORTCbits.RC2 TRIS_PB1 TRISBbits.TRISB2 TRIS_PB2 TRISBbits.TRISB3 TRIS_PB3 TRISBbits.TRISB4 TRIS_PWM0 TRISCbits.TRISC2

unsigned char x, y; /* This function delay the system for the duration determines by i and system clock while checking RB2RB5, if RB3-RB5 different to previous RB3-RB5, the function terminated by returning 1 */ unsigned short char delay_jab(void){ unsigned char i; for(i=0; i<100; i++){ x=PORTB>>2&0B0111; if (x!=y) return 1; Delay10KTCYx(1); } return 0; } /* To use pins RC4 and RC5 as digital inputs, the USB module must be disabled (UCON<3> = 0) and the on-chip USB transceiver must be disabled (UCFG<3> = 1 /* ---------------------End of File --------------------------*/

Filename: lcd 2 x 16 COM3013.c


/* Filename: lcd 2x16 COM2013.c Date: 20/12/2012 Author: Myskills JPK Revision: 1 Depedency: lcd 2x16 COM2013.h */ #include "lcd 2x16 COM2013.h" //continue

//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

//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

//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: Myskills JPK 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

10

//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 --------------------------------------------*/

11

You might also like