report micro1

Upload: kechikbollock

Post on 07-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Report Micro1

    1/32

    Aim : Understanding and know to apply all knowledge, theory and practical on project that have

    learned onto project that have been given.

    1.0 Objectives

    1.1 To learn how to use TMR0 as a hardware timer

    1.2 To understand the development concept of the program by PIC development board_PICDEV

    1.3 To understand, determine and analyze the configuration of keypad and also to understand the

    configuration of LCD

    1.4 To get the knowledge and understand how to apply Analog Digital Converter (ADC)

    2.0 Equipments

    No Name Quantity

    1. Resistor 220 15

    2. Resistor 47k 6

    3. Variable Resistor 100k 1

    4. Capacitor 30p 2

    5. Capacitor 10 1

    6. Capacitor 0.1 2

    7. PIC 16F877A 1

    8. Regulator U2 1

    9. Transistor 2N2222 110. LED 8

    11. Adapter battery 9V 1

    12. Battery 3V 2

    13. LCD 1

    14. Relay 5V 1

    15. Crystal 20MHZ 1

    16. DC Power Socket 1

    19. Strip Board 2

    20. Button 9

    22. PIC Development Board

    PICDEV

    1

    23. MPLAB IDE PROGRAM 1

    24. Micro P program 1

    25. Proteus 1

    26. Jumper Wire Necessesary

    3.0 Theory

    http://en.wikipedia.org/wiki/Omegahttp://en.wikipedia.org/wiki/Omegahttp://en.wikipedia.org/wiki/Omegahttp://en.wikipedia.org/wiki/Omega
  • 8/6/2019 Report Micro1

    2/32

    3.1 Using TMR0

    The special file register 01, Timer Zero (TMR0), which can be used as a counter or timer

    which, once started, run independently of the program execution. This mean it can count inputs

    or clock pulses concurrently with the program. The counter/timer can also be set up to generate

    an interrupt when it has reached its maximum value, so that the main program does not have to

    keep checking it to see if a particular count has been reached.

    3.1.1 Register Associated With Timer0

    TMR0

    o 8 bit TMR0 Module Registero Count from 0 to 255 (00h to FFh)

    INTCON

    o GIE Global Interrupt Enable Bit- controls all possible interrupt sources

    simultaneously.

    1 - Enables all unmasked interrupts.

    0 - Disables all interrupts.

    o T0IE TMR0 Overflow Interrupt Enable Bitcontrols interrupt enabled by TMR0 overflow.

    1 - Enables the TMR0 interrupt.

    0 - Disables the TMR0 interrupt.

  • 8/6/2019 Report Micro1

    3/32

    o T0IF TMR0 Overflow Interrupt Flag Bitregisters the timer TMR0 register overflow, when

    counting starts from zero.

    1 - TMR0 register has overflowed (bit must be cleared in software).

    0 - TMR0 register has not overflowed.

    OPTION

    o TOCS Clock Select bit (Bit 5)

    1 Pulses are brought to TMR0 timer/counter input through the RA4 pin

    0 Internal cycle clock (Fosc/4)

    o TOSE Source Edge Select bit (Bit 4)

    1 Increment on high to low transition on TMR0 pin

    0 increment on low to high transition on TMR0 pin

    o PSA Prescaler Assignment bit (Bit 3)

    1 Prescaler is assigned to the WDT

    0 Prescaler is assigned to the TMR0 timer/counter

    o PS2 (Bit 2), PS1(Bit 1), PS0 (Bit 0) Prescaler Rate Select bit

    PS2 PS1 PS0 TMR0 WDT

    0 0 0 1:2 1:1

    0 0 1 1:4 1:20 1 0 1:8 1:4

    0 1 1 1:16 1:8

    1 0 0 1:32 1:16

    1 0 1 1:64 1:32

    1 1 0 1:128 1:64

    1 1 1 1:256 1:128

  • 8/6/2019 Report Micro1

    4/32

    3.2 Keypad System

    Keypads are an excellent way of entering data into the microcontroller. The keys are

    usually numbered but they could be labeled as function keys, for example in a remote control

    handset in a TV to adjust the sound or color, etc. As well as remote controls, keypads find

    applications in burglar alarms, door entry system, calculators, microwave ovens, etc. Keypads

    are usually arranged in a matrix format to reduce the number of I/O connections. A 12 keypad is

    arranged in a 3 x 4 format requiring seven connections.

    This is arranged in three columns and four rows as shown in Table 1. There are seven

    connections to the keypad C1, C2, C3, R1, R2, R3 and R4.

    Column1,C1 Column2,C2 Column3,C3

    Row1,R1 1 2 3

    Row2,R2 4 5 6

    Row3,R3 7 8 9

    Row4,R4 * 0 #

    This connection to PIC is shown in Figure 1. The keypad works in the following way:

    If, for example, key 6 is pressed then A3 will be joined to B5. For key 1, A1 would be joined to

    B4, etc. As shown in Figure 1.

  • 8/6/2019 Report Micro1

    5/32

    The figure 1 above show the 4x3 keypad size which is 3 columns and 4 rows. To tell the

    PIC which button ispressed, the PIC need to set only one of the column to be high at one time.

    Then the PIC will scan which row is at current column send the HIGH value (1) to the PIC input

    at PORTB. For example, Let say the PIC need to recognize the buttons at column 1 which the

    available button are 1, 4, 7 and *. So the PIC will send the PORTA.F1 (COLUMN 1) to HIGH

    (1). Then the PIC will scan each row of PORTB begin from PORTB.F4 (ROW 1). At this stage,

    if the scanned result is HIGH that means the pressed button is equal to 1. If the result is LOW

    (0), then the PIC will continue to scan for the next row(ROW2, ROW3, and ROW4). When all

    rows at PORTB are scanned, the PIC will send the HIGH (1) value to the next column

    (COLUMN 2 at PORTA.F2) and repeat to scan each row of port B. This process is repeated to

    all columns. When the last column(COLUMN3: PORTA.F3) is reached, PIC will scan again for

    all rows at column1, 2 and so on. The value need to submit to the columns and read the rows

    value are actually can be vary. It depends on how the keypad is designed.

    3.3 ANALOG DIGITAL CONVERTER (ADC)

    Analog-to Digital converters are among the most widely used devices for data acquisition.

    Digital computers use binary (discrete) values, but in the physical world everything is analog

    (continuous). Temperature, pressure (wind or liquid), humidity, and velocity are a few examples

  • 8/6/2019 Report Micro1

    6/32

    of physical quantities that we deal with every day.A physical quantity is converted to electrical

    (voltage, current) signals using a device called a transducer.Transducers are also referred to as

    sensors. Sensors for temperature, velocity, pressure, light, and many other natural quantities

    produce an output that is voltage (or current). Therefore, we need an analog to digital converter

    to translate the analog signals to digital numbers so that the microcontroller can read and process

    them. See the figure below:

    Microcontroller Connection to Sensor via ADC

    3.3.1 DC FOR PIC16F877A

    The PIC16F877A has eight input pins for analog digital conversions. The conversion of an

    analog input signal results in a corresponding 10-bit digital number. By selecting voltage

    references Vref- and Vref+, the minimal resolution or quality of conversion may be adjusted to

    various needs. The ADC module has four registers.

    These registers are:

    A/D Result High Register (ADRESH)

    A/D Result Low Register (ADRESL)

    A/D Control Register 0 (ADCON0)

    A/D Control Register 1 (ADCON1)

    3.3.2 ADC RESOLUTION

    PIC16F877A has 10-bit resolution. So the number of steps is: 1024 = (0000000000

    1111111111). When Vref 5V(internal voltage supply) is used, the step size is 5V/1024 =

    4.88mV. So its mean that every bit increment is equal of single step voltage increment ~

    CPUSENSOR

    SADC DISPLAY

  • 8/6/2019 Report Micro1

    7/32

    4.88mV. For example to calculate the binary value of ADC that use Vref = 5V and the analog

    input = 1.7V is by using the formula below.

    Dout = Vin / Step Size. Dout = 1.7V / 4.88mV = 348.36 348 0101011100

    Then the value of conversion is stores into the ADC registers (ADRESL and ADRESH) as

    shown in table below:

    10-bit ADC result

    ADRESH ADRESL

    01 01011100

    3.3.3 ADC IN C PROGRAMMING

    ADC (Analog to Digital Converter) module is available with a number of PIC MCU

    models. Library function Adc_Read is included to provide you comfortable work with the

    module.

    Adc_Read(unsigned short channel)

    i.e: adcresult = Adc_Read(0); //Read the 10bits of conversion value from PORTA.F0

    and put into//variable adcresult

    Before using the function, be sure to configure the appropriate TRISA bits to designate the pins

    as input. Also,configure the desired pin as analog input, and set Vref(voltage reference value).

    3.5 LCD

  • 8/6/2019 Report Micro1

    8/32

    A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light

    modulating properties ofliquid crystals (LCs). LCs do not emit light directly.

    They are used in a wide range of applications, including computer monitors,television,

    instrument panels, aircraft cockpit displays,signage, etc. They are common in consumer devices

    such as video players, gaming devices, clocks, watches, calculators, and telephones. LCDs have

    displaced cathode ray tube (CRT) displays in most applications. They are usually more compact,

    lightweight, portable, less expensive, more reliable, and easier on the eyes.[citation needed] They are

    available in a wider range of screen sizes than CRT andplasma displays, and since they do not

    use phosphors, they cannot suffer image burn-in.

    LCDs are more energy efficient and offer safer disposal than CRTs. Its low electrical

    power consumption enables it to be used in battery-powered electronic equipment. It is

    an electronically-modulated optical device made up of any number ofpixels filled with liquid

    crystals and arrayed in front of a light source (backlight) orreflectorto produce images in colour

    ormonochrome. The earliest discovery leading to the development of LCD technology, the

    discovery of liquid crystals, dates from 1888.[1] By 2008, worldwide sales of televisions with

    LCD screens had surpassed the sale of CRT units.

    LCDs with a small number of segments, such as those used in digital watches andpocket

    calculators, have individual electrical contacts for each segment. An external

    dedicated circuit supplies an electric charge to control each segment. This display structure is

    unwieldy for more than a few display elements.

    http://en.wikipedia.org/wiki/Electronic_visual_displayhttp://en.wikipedia.org/wiki/Liquid_Crystalshttp://en.wikipedia.org/wiki/Computer_monitorhttp://en.wikipedia.org/wiki/Televisionhttp://en.wikipedia.org/wiki/Flight_instrumentshttp://en.wikipedia.org/wiki/Signagehttp://en.wikipedia.org/wiki/Clockhttp://en.wikipedia.org/wiki/Calculatorhttp://en.wikipedia.org/wiki/Telephonehttp://en.wikipedia.org/wiki/Cathode_ray_tubehttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Plasma_displayhttp://en.wikipedia.org/wiki/Battery_(electricity)http://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Electro-optic_modulatorhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Light#Light_sourceshttp://en.wikipedia.org/wiki/Backlighthttp://en.wikipedia.org/wiki/Reflector_(photography)http://en.wikipedia.org/wiki/Monochromehttp://en.wikipedia.org/wiki/Liquid_crystal_display#cite_note-0http://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Electronic_circuithttp://en.wikipedia.org/wiki/Electronic_visual_displayhttp://en.wikipedia.org/wiki/Liquid_Crystalshttp://en.wikipedia.org/wiki/Computer_monitorhttp://en.wikipedia.org/wiki/Televisionhttp://en.wikipedia.org/wiki/Flight_instrumentshttp://en.wikipedia.org/wiki/Signagehttp://en.wikipedia.org/wiki/Clockhttp://en.wikipedia.org/wiki/Calculatorhttp://en.wikipedia.org/wiki/Telephonehttp://en.wikipedia.org/wiki/Cathode_ray_tubehttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Plasma_displayhttp://en.wikipedia.org/wiki/Battery_(electricity)http://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Electro-optic_modulatorhttp://en.wikipedia.org/wiki/Pixelhttp://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Liquid_crystalhttp://en.wikipedia.org/wiki/Light#Light_sourceshttp://en.wikipedia.org/wiki/Backlighthttp://en.wikipedia.org/wiki/Reflector_(photography)http://en.wikipedia.org/wiki/Monochromehttp://en.wikipedia.org/wiki/Liquid_crystal_display#cite_note-0http://en.wikipedia.org/wiki/Digital_watchhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Pocket_calculatorhttp://en.wikipedia.org/wiki/Electronic_circuit
  • 8/6/2019 Report Micro1

    9/32

    Small monochrome displays such as those found in personal organizers,

    electronic weighing scales, olderlaptop screens, and the original Nintendo Game Boy have a

    passive-matrix structure employing super-twisted nematic (STN)[16] or double-layer STN

    (DSTN) technology (the latter of which addresses a colour-shifting problem with the former),

    and colour-STN (CSTN) in which colour is added by using an internal filter. Each row or

    column of the display has a single electrical circuit. The pixels are addressed one at a time by

    row and column addresses. This type of display is calledpassive-matrix addressedbecause the

    pixel must retain its state between refreshes without the benefit of a steady electrical charge. As

    the number of pixels (and, correspondingly, columns and rows) increases, this type of display

    becomes less feasible. Very slow response times and poor contrast are typical of passive-matrix

    addressed LCDs.

    Monochrome passive-matrix LCDs were standard in most early laptops (although a few

    used plasma displays). The commercially unsuccessful Macintosh Portable (released in 1989)

    was one of the first to use an active-matrix display (though still monochrome), but passive-

    matrix was the norm until the mid-1990s, when color active-matrix became standard on all

    laptops.

    4.0 PROCEDURE

    http://en.wikipedia.org/wiki/Weighing_scaleshttp://en.wikipedia.org/wiki/Laptophttp://en.wikipedia.org/wiki/Game_Boyhttp://en.wikipedia.org/wiki/Super-twisted_nematic_displayhttp://en.wikipedia.org/wiki/Liquid_crystal_display#cite_note-Game_Boy_screen_type-15http://en.wikipedia.org/wiki/Passive_matrix_addressinghttp://en.wikipedia.org/wiki/Response_time_(technology)http://en.wikipedia.org/wiki/Weighing_scaleshttp://en.wikipedia.org/wiki/Laptophttp://en.wikipedia.org/wiki/Game_Boyhttp://en.wikipedia.org/wiki/Super-twisted_nematic_displayhttp://en.wikipedia.org/wiki/Liquid_crystal_display#cite_note-Game_Boy_screen_type-15http://en.wikipedia.org/wiki/Passive_matrix_addressinghttp://en.wikipedia.org/wiki/Response_time_(technology)
  • 8/6/2019 Report Micro1

    10/32

    4.1 First Week

    Briefing with lecture about the project

    Recieve the component for the project

    Group meeting - distributed the task into 4 person

    Buy component that not completen like transistor

    4.2 Second Week

    Make source code for the main part

    Soldering Supply, Analog Digital Converter (ADC), LED and PIC part at board

    4.3 Third Week

    Make source code at function part

    Soldering Interrupt, Keypad and LCD part into board

    Combine all the circuit to PIC circuit

    Test on Proteus software

    4.4 Fourth Week

    Troubleshooting for the code that already made

    All the circuit burned to PIC

    Test the board

    Troubleshoot the board when circuit has problem

    Project 100% done

    Make report for the project

    5.0 Result

    5.1 Circuit Diagram

  • 8/6/2019 Report Micro1

    11/32

    5.1.1 Power Suply

    5.1.2 Keypad

    5.1.3 PIC 16F877A

  • 8/6/2019 Report Micro1

    12/32

    5.1.4 LED

    5.1.5 LCD Display

  • 8/6/2019 Report Micro1

    13/32

    5.1.6 Relay and ADC

    5.1.7 INTERRUPT

  • 8/6/2019 Report Micro1

    14/32

    5.1.8 7 SEGMENT

    5.1.9 COMPLETE CIRCUIT DIAGRAM

    6.0 Data Analysis

  • 8/6/2019 Report Micro1

    15/32

    6.1 Operation Of The Circuit :-

    6.1.1 LCD

    LCD in this project is used to display each of members group names, it also used to

    display temperature based on the ADC (Analog Digital Converter) after the value has benn

    converted from Voltage to Celcius.

    The way we convert the value is by using the formula

    Voltage = ADC x 0.0048828125

    All the LED pins are connected to the PORTD at the PIC. When we give supply to the

    circuit, LCD will display team members name and matric number, and when its done, it will

    display the temperature value that has been converted from the ADC. Besides from displayed

    team members name and temperature. It also display animation type, e.g like Animation 1 or

    Animation 2 after keypad pressed.

    6.1.2 LED

    LED will function when keypad is pressed according to the pattern that has been set at the

    keypad. All the LEDs are connected to PORTA[F1,F2,F3,F5] and PORTE[F1:F3] at PIC.

    Before LED connect to the PORTA and PORTE ath PIC, LED have to connect with resistor so

    the LEDs will not damage because of the high current.

    6.1.3 Keypad

  • 8/6/2019 Report Micro1

    16/32

    There are two parts in keypad which are ROW and COLUMN . (ROW = PORTC[F3:F5],

    COLUMN = PORTC[F0:F2]). These two parts connected to the PORTC at PIC. Its function

    when its pressed and will create various pattern at LED. For thos project, we use 9 types of

    pattern.

    6.1.4 Interrupt

    Interrupt will function when button is pressed. When the button is pressed, all the operation will

    stop for the moment which are at LED and LCD which mean LED will stop running according to

    the pattern that selected by keypad for 4 seconds and after we release the button all the operation

    will continue their operation just like before we press the button.

    6.1.5 Relay

    A relay is an electrically operated switch Relays are used where it is necessary to control a

    circuit by a low-power signal (with complete electrical isolation between control and controlled

    circuits), or where several circuits must be controlled by one signal. In this project, relay function

    as detected the incoming tempurature, if tempurature is below 30 celcuis the lamp will OFF and

    when the tempurature is more that 30celcuis lamp will ON.

    7.0 Results

    http://en.wikipedia.org/wiki/Electrichttp://en.wikipedia.org/wiki/Switchhttp://en.wikipedia.org/wiki/Electrichttp://en.wikipedia.org/wiki/Switch
  • 8/6/2019 Report Micro1

    17/32

    7.1 Pictures Of Project Circuit

    7.2 Completed Source Code

  • 8/6/2019 Report Micro1

    18/32

    //Define LABEL NAME TO PORT AND VALUE

    #define COLUMN1 PORTC.F0#define COLUMN2 PORTC.F1

    #define COLUMN3 PORTC.F2

    #define ROW1 PORTC.F3#define ROW2 PORTC.F4

    #define ROW3 PORTC.F5

    #define LAMP PORTC.F6

    #define LED1 PORTA.F1

    #define LED2 PORTA.F2

    #define LED3 PORTA.F3#define LED4 PORTA.F5

    #define LED5 PORTE.F0

    #define LED6 PORTE.F1

    #define LED7 PORTE.F2

    #define seven_segment PORTB//GFEDCBA Pattern for 7 SEGMENT Common Kathod

    #define no_0 0b01111110

    #define no_1 0b00001100

    #define no_2 0b10110110#define no_3 0b10011110

    #define no_4 0b11001100

    #define no_5 0b11011010#define no_6 0b11111010

    #define no_7 0b00001110

    #define no_8 0b11111110#define no_9 0b11011110

    #define GIE INTCON.F7

    #define INTE INTCON.F4#define INTF INTCON.F1

    #define TMR0IE INTCON.F5

    #define TMR0IF INTCON.F2

    #define T0CS OPTION_REG.F5#define PSA OPTION_REG.F3

    #define PS2 OPTION_REG.F2

    #define PS1 OPTION_REG.F1#define PS0 OPTION_REG.F0

    //String for LCD Display (String value is store in PIC Program Memory)const char title[] = " *FINAL_PROJECT* ";

    const char team[] = " >>>TALIBAN>>CREW

  • 8/6/2019 Report Micro1

    19/32

    const char member1m1[] = "de090228";

    const char member2[] = "Ikhwan";

    const char member1m2[] = "de090211";const char member3[] = "Nadha";

    const char member1m3[] = "de090194";

    const char member4[] = "Reduan";const char member1m4[] = "de090223";

    const char txtcelcius[] = "Celcius";

    const char animate1[] = " Animate 1 ";const char animate2[] = " Animate 2 ";

    const char animate3[] = " Animate 3 ";

    const char animate4[] = " Animate 4 ";

    const char animate5[] = " Animate 5 ";const char animate6[] = " Animate 6 ";

    const char animate7[] = " Animate 7 ";

    const char animate8[] = " Animate 8 ";

    const char animate9[] = " Animate 9 ";//=====Global variable========

    char txt_msg[15];unsigned int adc_value;

    unsigned float voltage, celcius;

    unsigned short overflow,count; //variable value ranges 0 ~ 255

    //========functions prototype=====void interrupt(void);

    void Lengahan(unsigned int);

    void scan_keypad(void);void animate(unsigned int);

    void strcp_c(char *str1, const char *cstr2);

    void baca_adc(void);//=================================

    void main(void)

    {//Port Setup

    ADCON1 = 0b10001110; //Port AN0 as Analog input(Right Justified) output the rest is digital

    TRISA = 0b00000001;

    PORTA = 0b00000000;TRISB = 0b00000001;

    PORTB = 0b00000000;

    TRISC = 0b00111000;PORTC = 0b00000000;

    TRISD = 0b00000001;

    PORTD = 0b00000000;TRISE = 0b00000000;

    PORTE = 0b00000000;

  • 8/6/2019 Report Micro1

    20/32

    //Interrupt Setup

    GIE = 1;

    INTE = 1;TMR0IE = 1;

    T0CS = 0;

    PSA = 0;PS2 = 1; //prescale is set for 1:256

    PS1 = 1;

    PS0 = 1;TMR0 = 0;

    //Initialize PortD as LCD control port

    Lcd_Init(&PORTD); // Initialize LCD connected to PORTDLcd_Cmd(LCD_CLEAR); // Clear display

    Lcd_Cmd(LCD_CURSOR_OFF); // Turn cursor off

    strcp_c(txt_msg, title); //copy string variable into txt_msgLcd_Out(1,1,txt_msg); //display txt_msg to LCD

    Delay_ms(1000);Lcd_Cmd(LCD_CLEAR);

    strcp_c(txt_msg, team); //copy string variable into txt_msg

    Lcd_Out(1,2,txt_msg); //display txt_msg to LCD

    Delay_ms(1000);Lcd_Cmd(LCD_CLEAR);

    strcp_c(txt_msg, teams); //copy string variable into txt_msg

    Lcd_Out(2,3,txt_msg); //display txt_msg to LCDDelay_ms(800);

    Lcd_Cmd(LCD_CLEAR);

    strcp_c(txt_msg, member1);Lcd_Out(1,7,txt_msg);

    strcp_c(txt_msg, member1m1);

    Lcd_Out(2,6,txt_msg);Delay_ms(700);

    Lcd_Cmd(LCD_CLEAR);

    strcp_c(txt_msg, member2);

    Lcd_Out(1,6,txt_msg);strcp_c(txt_msg, member1m2);

    Lcd_Out(2,6,txt_msg);

    Delay_ms(700);Lcd_Cmd(LCD_CLEAR);

    strcp_c(txt_msg, member3);

    Lcd_Out(1,7,txt_msg);strcp_c(txt_msg, member1m3);

    Lcd_Out(2,6,txt_msg);

    Delay_ms(700);

    Lcd_Cmd(LCD_CLEAR);

  • 8/6/2019 Report Micro1

    21/32

    strcp_c(txt_msg, member4);

    Lcd_Out(1,7,txt_msg);

    strcp_c(txt_msg, member1m4);Lcd_Out(2,6,txt_msg);

    Delay_ms(700);

    Lcd_Cmd(LCD_CLEAR);

    while(1){

    baca_adc();

    scan_keypad();

    }}

    //===============Functions==============================

    void interrupt (void)

    {

    if (INTF == 1){

    LAMP = 1;

    Delay_ms(4000);

    LAMP= 0;INTF = 0;

    }

    if (TMR0IF == 1)overflow++;

    if (overflow == 76) //4 times overflow to get 1 second

    {if (count == 0)

    seven_segment = no_0;

    else if (count == 1)seven_segment = no_1;

    else if (count == 2)

    seven_segment = no_2;

    else if (count == 3)seven_segment = no_3;

    else if (count == 4)

    seven_segment = no_4;else if (count == 5)

    seven_segment = no_5;

    else if (count == 6)seven_segment = no_6;

    else if (count == 7)

    seven_segment = no_7;

    else if (count == 8)

  • 8/6/2019 Report Micro1

    22/32

    seven_segment = no_8;

    else if (count == 9)

    seven_segment = no_9;else if (count == 10)

    {

    count=0; //reset count to 0seven_segment = no_0;

    }

    count++;overflow = 0;

    }

    TMR0IF = 0;

    TMR0 = 0;}

    void baca_adc()

    {adc_value = ADC_Read(0);

    if(adc_value>10)

    voltage = adc_value * 0.0048828125 ;

    celcius = voltage * 20;

    FloatToStr(celcius,txt_msg);Lcd_Out(1,1,txt_msg);

    strcp_c(txt_msg, txtcelcius);

    Lcd_Out(2,1,txt_msg);

    if (celcius>=30)

    LAMP = 1;else

    LAMP = 0;

    }void animate(unsigned int no)

    {

    unsigned int i;

    if (no == 1){

    Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    strcp_c(txt_msg, animate1);Lcd_Out(1,1,txt_msg);

    for(i=1;i

  • 8/6/2019 Report Micro1

    23/32

    LED5 = ~LED5;

    LED6 = ~LED6;

    LED7 = ~LED7;Lengahan(2);

    }

    Lcd_Cmd(Lcd_CLEAR);}

    else if (no == 2)

    {Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    strcp_c(txt_msg, animate2);

    Lcd_Out(1,1,txt_msg);

    for(i=1;i

  • 8/6/2019 Report Micro1

    24/32

    Lengahan(2);

    LED7=0; LED1=0;LED6=1;LED2=1;

    Lengahan(2);LED6=0; LED2=0;LED5=1;LED3=1;

    Lengahan(2);

    LED5=0; LED3=0;LED4=1;Lengahan(2);

    LED4 =0;

    }Lcd_Cmd(Lcd_CLEAR);

    }

    else if (no == 4)

    {Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    strcp_c(txt_msg, animate4);

    Lcd_Out(1,1,txt_msg);

    for(i=1;i

  • 8/6/2019 Report Micro1

    25/32

    Lengahan(2);

    LED1 = 0;

    LED2 = 0;LED3 = 0;

    LED4 = 0;

    LED5 = 0;LED6 = 0;

    LED7 = 0;

    }

    Lcd_Cmd(Lcd_CLEAR);

    }

    else if (no == 6){

    Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    strcp_c(txt_msg, animate6);

    Lcd_Out(1,1,txt_msg);for(i=1;i

  • 8/6/2019 Report Micro1

    26/32

    LED2 = ~LED2;

    LED3 = ~LED3;

    LED4 = LED4;LED5 = ~LED5;

    LED6 = ~LED6;

    LED7 = LED7;Lengahan(2);

    LED1 = ~LED1;

    LED2 = ~LED2;LED3 = LED3;

    LED4 = ~LED4;

    LED5 = ~LED5;

    LED6 = LED6;LED7 = ~LED7;

    Lengahan(2);

    }Lcd_Cmd(Lcd_CLEAR);

    }else if (no == 8)

    {

    Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    strcp_c(txt_msg, animate8);Lcd_Out(1,1,txt_msg);

    for(i=1;i

  • 8/6/2019 Report Micro1

    27/32

    LED4 = 1;

    Lengahan(2);

    LED5 = 0;Lengahan(2);

    LED6 = 1;

    Lengahan(2);LED7 = 0;

    Lengahan(2);

    LED1 = 0;LED2 = 0;

    LED3 = 0;

    LED4 = 0;

    LED5 = 0;LED6 = 0;

    LED7 = 0;

    }Lcd_Cmd(Lcd_CLEAR);

    }else if (no == 9)

    {

    Lcd_Cmd(Lcd_CLEAR); //Clear LCD display

    Lcd_Out(1, 1, "Animate 9");for(i=1;i

  • 8/6/2019 Report Micro1

    28/32

    }

    void scan_keypad(void)

    {//=============================================================

    COLUMN1 = 1; COLUMN2 = 0; COLUMN3 = 0;

    //PORTC = COLUMN1; //Activate column 1 (button 1, 4, 7)if (ROW1 == 1)

    {

    while(ROW1 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 1 is pressed

    animate(1);

    }//=============================================================

    COLUMN1 = 0; COLUMN2 = 1; COLUMN3 = 0;

    //PORTC = COLUMN2; //Activate column 2 (button 2, 5, 8)

    if (ROW1 == 1){

    while(ROW1 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 2 is pressed

    animate(2);

    }//=============================================================

    COLUMN1 = 0; COLUMN2 = 0; COLUMN3 = 1;

    //PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)if (ROW1 == 1)

    {

    while(ROW1 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 3 is pressed

    animate(3);}

    //=============================================================

    COLUMN1 = 1; COLUMN2 = 0; COLUMN3 = 0;

    //PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)if (ROW2 == 1)

    {

    while(ROW2 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 3 is pressed

    animate(4);}

    //=============================================================

    COLUMN1 =0; COLUMN2 = 1; COLUMN3 = 0;

    //PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)

  • 8/6/2019 Report Micro1

    29/32

    if (ROW2 == 1)

    {

    while(ROW2 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 3 is pressed

    animate(5);}

    //=============================================================

    COLUMN1 = 0; COLUMN2 = 0; COLUMN3 =1;//PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)

    if (ROW2 == 1)

    {

    while(ROW2 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 3 is pressed

    animate(6);

    }//=============================================================

    COLUMN1 = 1; COLUMN2 = 0; COLUMN3 = 0;//PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)

    if (ROW3 == 1)

    {

    while(ROW3 == 1)continue; //wait until button is releaseDelay_ms(20);

    //Button no 3 is pressed

    animate(7);}

    //=============================================================

    COLUMN1 = 0; COLUMN2 = 1; COLUMN3 = 0;//PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)

    if (ROW3 == 1)

    {while(ROW3 == 1)continue; //wait until button is release

    Delay_ms(20);

    //Button no 3 is pressed

    animate(8);}

    //=============================================================

    COLUMN1 = 0; COLUMN2 = 0; COLUMN3 = 1;//PORTC = COLUMN3; //Activate column 3 (button 3, 6, 9)

    if (ROW3 == 1)

    {while(ROW3 == 1)continue; //wait until button is release

    Delay_ms(20);

    //Button no 3 is pressed

    animate(9);

  • 8/6/2019 Report Micro1

    30/32

    }

    }

    void Lengahan(unsigned int lengah)

    {

    switch (lengah){

    case 1:

    Delay_ms(100);break;

    case 2:

    Delay_ms(200);

    break;case 3:

    Delay_ms(300);

    break;

    case 4:Delay_ms(400);

    break;case 5:

    Delay_ms(500);

    break;

    default:Delay_ms(1000);

    }

    }//=====Copies constant string (in ROM) to 'normal' string (in RAM)

    void strcp_c(char *str1, const char *cstr2)

    {unsigned short x = 0;

    do {

    str1[x] = cstr2[x];} while (str1[x++]);

    }

    8.0 Discussion

  • 8/6/2019 Report Micro1

    31/32

    We are facing some problems to complete our project. The problem for us to complete the

    project are: -

    1. Lack of parts and difficult to obtain.

    - The lack of such components 220ohm resistors, bulbs, cables and others. We need to wait

    for two (2) weeks to get it out of the electronic office, although some proposals we have put

    forward and we buy their own solution components.

    2. Faulty components

    - During the process of completing the project, several components of damage such asbroken legs, broken and LED bord burning occurs. It was beyond our expectations and the

    worst of all IC we burn when we use the direct connection of voltage AC / DC ADAPTER

    12V REGULATOR capacity for 3v 9V and can not accommodate our circuit. We have no

    choice because if we use the 9V and 3V circuits we were not able to function fully. Next stepwe have to spend more to buy back the IC is programmed again and even though we know

    that time is running out.

    3. Combining all the circuits

    - We believe that the problems of our group with other groups. When we examine thiscircuit, at first there are some circuit work properly but when we try to combine circuit as

    "running light" and "interrupt" the circuit does not work. To accomplish that we isolate the

    circuit. In addition, we use alternative routes such as the cutting path circuit so the circuitdoes not collide with each other. In addition, we use connector to the cable to make sure the

    cable cannot damage so easily and also the component.

  • 8/6/2019 Report Micro1

    32/32

    9.0 Conclusion

    After struggling to finish this project, we finally managed to solve it. Many problems we face

    them such as to combine all the circuits, defective components and inadequate, including the

    problem of completing the program MICRO C. Although the

    project was completed, before we send them there may

    be some changes as we pulleach circuit and each connection, as we modify the

    recommendation of Mr.Mohamad Bin Md Som, our lecturer for this

    subject. All that we learn as TMR0, the disorder"interrupt", "running light", the

    power circuit (power) and others in the class time orduring the lab we are trying our best

    efforts to apply in this project. We also want to thank you goes

    to our lecturer for sincerity in helping us to complete this project.