LAB Six Print Diz

Embed Size (px)

Citation preview

  • 8/6/2019 LAB Six Print Diz

    1/19

    OBJECTIVE

    Basically, in this experiment MikroC Compiler for PIC were introduced which is caters the

    compiling work in very simplified manner. Besides that, the assignments of I/O are understood

    and program the I/O were learnt. The pin assignment of synthesizing of the input output

    interfacing is familiarizing accordingly to achieve the functionality without any unwanted errors.

    The time delay is applied to the input output interfacing to observe the time response of the

    circuit which will be done in the experiment.

    INTRODUCTION

    mikroC PRO for PIC is a full-featured C compiler for PIC microcontrollers from Microchip. It is

    designed for developing, building and debugging PIC-based embedded applications. This

    development environment has a wide range of features such as easy-to-use IDE, very compact

    and efficient code, hardware and software libraries, comprehensive documentation, software

    simulator, hardware debugger support, COFF file generation and many more.

    CCS provides a complete integrated tool suite for developing and debugging embedded

    applications running on Microchip PIC. The heart of this development tools suite is the CCS

    intelligent code optimizing C compiler which frees developers to concentrate on design

    functionality instead of having to become an MCU architecture expert.

    Technology is now omnipresent, since microprocessors are found in PDAs, phones, toys,

    greeting cards, etc. Almost all of them have a microprocessor encapsulated within, together with

    RAM, ROM, and input/output ports, all in one single silicon chip known as a microcontroller.

    In some cases, these may well be PIC microcontrollers from Microchip Inc., and as with any

    CPU, we need tools to make them work - let us see what this one is capable of.

    mikroC PRO for PIC is a complete IDE for coding, simulating, programming, and debuggingyour PICs. Writing your code in C brings advantages over writing it in assembler - for example,

    you do not have to switch between register banks. But the most important advantage is that C is

    easier to use, maintain, understand, and share.

    Writing and simulating the code can be done with the IDE, but for programming and debugging

  • 8/6/2019 LAB Six Print Diz

    2/19

    the PIC , Mikro Elekronikas PICFlash is needed. If you want to use a different one, you just

    need to assemble one on your own, or use one of the many already available on the Internet.

    Unfortunately, PICFlash interface is not open, so most of the time programming and debugging

    will be unavailable.

    Usually, when programming a tool that requires some port interface (SPI, UART, USB, etc.),

    testing becomes crucial. This IDE offers you a series of interface windows for that purpose. For

    instance, if your prototype includes a UART interface, you can use the UART Terminal to

    configure the number of bits, the parity, the baud rate, and anything else you may need to verify

    how well your idea works. This helps a lot in finding common problems beforehand. It is also

    very helpful to have access to a number of built-in libraries.

    Figure 1 : Mikro C Desktop

  • 8/6/2019 LAB Six Print Diz

    3/19

    PROCEDURE

    Part A: Running light

    First of all, the following circuit is constructed as following below.

    Figure 2 : Running light circuit is constructed as picture above. This design is connected to the

    eight LED and protected by 330 ohm of resistors before the LED to prevent burn due to

    overcurrent. As well as the LED is connected in parallel and grounded to a common point.

    The LED of the circuit is constructed which is constructed on the protoboard. The source code

    which is provided in the lab manual is completed so that the LED will blink on to another

    sequentially from LED L1 until LED L7 and the sequence repeats continuously.

    The source code is written in microC compiler , built, and download the HEX file into the

    Microcontroller and run the program. The LST file was printed and the observation is discussed

    accordingly.

    The delay is change to 500 ms and the program downloaded and executed to see the differences.

    Later on, commented out all delay instruction were removed, then build and run the application

    to see the difference. The observation for both program is observed and written down.

  • 8/6/2019 LAB Six Print Diz

    4/19

    PART B: CONTROLLABLE RUNNING LIGHT

    A push button in a Pull Up connection is already connected to PORT A pin 4. This push button

    was used to this particular application as an input to control the running light. The source code

    were written and completed in micro C. So that when the push buttons is released, all LED will

    be turn on else if it is pressed the running light application work as in PART A. The source codewill be built and downloaded and the application is executed to the results of the code. The

    observation on the output based on the switch condition will write and the main source code was

    printed. Later the code was modified so that when a push button is pressed, the interval between

    each LED to light up is 0.5 seconds. While when the push button is release, the interval is 2

    seconds. The result is verified by the approved instructor in the lab.

    Source Code forprocedure 3

    void main()

    {

    int time = 1000 ;

    PORTB = 0; // Initialize PORTB

    TRISB = 0; // Configure PORTB as output

    while(1)

    {

    PORTB = 0x01; // Light Up 1st LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x02; // Light Up 2nd LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x04; // Light Up 3rd LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x08; // Light Up 4th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x10; // Light Up 5th LED

    Vdelay_ms(time); // one second delay

  • 8/6/2019 LAB Six Print Diz

    5/19

    PORTB = 0x20; // Light Up 6th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x40; // Light Up 7th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x80; // Light Up 8th LED

    Vdelay_ms(time); // one second delay

    }

    }

    LST file

    ; ADDRESS OPCODE ASM

    ; ----------------------------------------------

    $0000 $EF87 F000 GOTO _main

    $019E $ _Mul_32x32_U:

    $019E $0100 MOVLB 0

    $01A0 $0E22 MOVLW 34

    $01A2 $6E0C MOVWF STACK_12, 0

    $01A4 $6A08 CLRF STACK_8, 0

    $01A6 $6A09 CLRF STACK_9, 0

    $01A8 $6A0A CLRF STACK_10, 0

    $01AA $6A0B CLRF STACK_11, 0

    $01AC $ _NEXT:

    $01AC $060C DECF STACK_12, F, 0

    $01AE $B4D8 BTFSC STATUS, Z, 0

    $01B0 $EFFC F000 GOTO _EXIT2

    $01B4 $90D8 BCF STATUS, C, 0

    $01B6 $ _LOOP:

  • 8/6/2019 LAB Six Print Diz

    6/19

    $01B6 $320B RRCF STACK_11, F, 0

    $01B8 $320A RRCF STACK_10, F, 0

    $01BA $3209 RRCF STACK_9, F, 0

    $01BC $3208 RRCF STACK_8, F, 0

    $01BE $3203 RRCF STACK_3, F, 0

    $01C0 $3202 RRCF STACK_2, F, 0

    $01C2 $3201 RRCF STACK_1, F, 0

    $01C4 $3200 RRCF STACK_0, F, 0

    $01C6 $A0D8 BTFSS STATUS, C, 0

    $01C8 $EFD6 F000 GOTO _NEXT

    $01CC $060C DECF STACK_12, F, 0

    $01CE $B4D8 BTFSC STATUS, Z, 0

    $01D0 $EFF4 F000 GOTO _EXIT1

    $01D4 $5004 MOVF STACK_4, W, 0

    $01D6 $2608 ADDWF STACK_8, F, 0

    $01D8 $5005 MOVF STACK_5, W, 0

    $01DA $2209 ADDWFC STACK_9, F, 0

    $01DC $5006 MOVF STACK_6, W, 0

    $01DE $220A ADDWFC STACK_10, F, 0

    $01E0 $5007 MOVF STACK_7, W, 0

    $01E2 $220B ADDWFC STACK_11, F, 0

    $01E4 $EFDB F000 GOTO _LOOP

    $01E8 $ _EXIT1:

    $01E8 $5004 MOVF STACK_4, W, 0

    $01EA $2608 ADDWF STACK_8, F, 0

    $01EC $5005 MOVF STACK_5, W, 0

    $01EE $2209 ADDWFC STACK_9, F, 0

    $01F0 $5006 MOVF STACK_6, W, 0

    $01F2 $220A ADDWFC STACK_10, F, 0

    $01F4 $5007 MOVF STACK_7, W, 0

  • 8/6/2019 LAB Six Print Diz

    7/19

  • 8/6/2019 LAB Six Print Diz

    8/19

    $0040 $C002 F01B MOVFF STACK_0+2, VDelay_ms_NumberOfCyc_L0+2

    $0044 $C003 F01C MOVFF STACK_0+3, VDelay_ms_NumberOfCyc_L0+3

    ;Delays.c,120 :: if (NumberOfCyc < 660)

    $0048 $0E00 MOVLW 0

    $004A $5C03 SUBWF STACK_0+3, 0, 0

    $004C $E108 BNZ L_VDelay_ms_5

    $004E $0E00 MOVLW 0

    $0050 $5C02 SUBWF STACK_0+2, 0, 0

    $0052 $E105 BNZ L_VDelay_ms_5

    $0054 $0E02 MOVLW 2

    $0056 $5C01 SUBWF STACK_0+1, 0, 0

    $0058 $E102 BNZ L_VDelay_ms_5

    $005A $0E94 MOVLW 148

    $005C $5C00 SUBWF STACK_0, 0, 0

    $005E $ L_VDelay_ms_5:

    $005E $0100 MOVLB 0

    $0060 $A0D8 BTFSS STATUS, C, 0

    ;Delays.c,121 :: return;

    $0062 $0012 RETURN

    $0064 $ L_VDelay_ms_2:

    ;Delays.c,122 :: NumberOfCyc -= 660;

    $0064 $0100 MOVLB 0

    $0066 $0E94 MOVLW 148

    $0068 $6E00 MOVWF STACK_0, 0

    $006A $0E02 MOVLW 2

    $006C $6E01 MOVWF STACK_0+1, 0

    $006E $0E00 MOVLW 0

    $0070 $6E02 MOVWF STACK_0+2, 0

    $0072 $6E03 MOVWF STACK_0+3, 0

    $0074 $C019 F004 MOVFF VDelay_ms_NumberOfCyc_L0, STACK_4

  • 8/6/2019 LAB Six Print Diz

    9/19

    $0078 $C01A F005 MOVFF VDelay_ms_NumberOfCyc_L0+1, STACK_4+1

    $007C $C01B F006 MOVFF VDelay_ms_NumberOfCyc_L0+2, STACK_4+2

    $0080 $C01C F007 MOVFF VDelay_ms_NumberOfCyc_L0+3, STACK_4+3

    $0084 $5000 MOVF STACK_0, 0, 0

    $0086 $5E04 SUBWF STACK_4, 1, 0

    $0088 $5001 MOVF STACK_0+1, 0, 0

    $008A $5A05 SUBWFB STACK_4+1, 1, 0

    $008C $5002 MOVF STACK_0+2, 0, 0

    HEX File

    :1000000004EF00F0FFFFFFFFF40E156E010E166EF9

    :10001000D00E176E070E186E816A936A100E926EDC

    :10002000016A80B8012A0150000A41E1010E816E87

    :1000300015C019F016C01AF09FEC00F0020E816E88

    :1000400015C019F016C01AF09FEC00F0040E816E76

    :1000500015C019F016C01AF09FEC00F0080E816E62

    :1000600015C019F016C01AF09FEC00F0100E816E4A

    :1000700015C019F016C01AF09FEC00F0200E816E2A

    :1000800015C019F016C01AF09FEC00F0400E816EFA

    :1000900015C019F016C01AF09FEC00F0800E816EAA

    :1000A00015C019F016C01AF09FEC00F046D0016A96

    :1000B00080B8012A0150010A40E1010E816E17C08B

    :1000C00019F018C01AF09FEC00F0020E816E17C0F4

    :1000D00019F018C01AF09FEC00F0040E816E17C0E2

    :1000E00019F018C01AF09FEC00F0080E816E17C0CE

    :1000F00019F018C01AF09FEC00F0100E816E17C0B6

    :1001000019F018C01AF09FEC00F0200E816E17C095

    :1001100019F018C01AF09FEC00F0400E816E17C065

    :1001200019F018C01AF09FEC00F0800E816E17C015

  • 8/6/2019 LAB Six Print Diz

    10/19

    :1001300019F018C01AF09FEC00F072D7FFD7880EA4

    :100140001B6E130E1C6E000E1D6E1E6E19C000F08D

    :100150001AC001F0000E026E036E880E046E130EBC

    :10016000056E000E066E000E076E22EC01F000C058

    :100170001BF001C01CF002C01DF003C01EF0000EF9

    :10018000035C08E1000E025C05E1020E015C02E185

    :10019000940E005C0001D8A012000001940E006EC5

    :1001A000020E016E000E026E036E1BC004F01CC036

    :1001B00005F01DC006F01EC007F00050045E01509F

    :1001C000055A0250065A0350075A04C01BF005C0D6

    :1001D0001CF006C01DF007C01EF0050E006E04C026

    :1001E0001BF005C01CF006C01DF007C01EF000503B

    :1001F000000107E01E321D321C321B321E9EFF0F13

    :10020000F7D700011BC000F01CC001F01DC002F0B8

    :100210001EC003F0010E1B5E000E1C5A1D5A1E5A12

    :1002200000500110021003100CE00000000000005C

    :1002300000000000000000000000000000000000BE

    :10024000E0D712000001220E0C6E086A096A0A6AE1

    :100250000B6A0C06D8B44FEF01F0D8900B320A327B

    :10026000093208320332023201320032D8A029EFBB

    :1002700001F00C06D8B447EF01F0045008260550F1

    :10028000092206500A2207500B222EEF01F00450DB

    :1002900008260550092206500A2207500B22120098

    :020000040030CA

    :0E000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF00

    :00000001FF

  • 8/6/2019 LAB Six Print Diz

    11/19

    2. Observation for procedure 3

    The LED blinking one another 1 second in sequence.

    3. Observation for procedure 4

    The LED light up one another 500 ms in sequence, which is faster than procedure 3

    4. Source Code for procedure 7

    void main(){

    int time = 1000;

    PORTB = 0XFF; // Initialize PORTB

    TRISB = 0; // Configure PORTB as output

    TRISA = 0x10;

    while(1)

    {

    //read the switch condition

    if(PORTA.F4==0)

    { // check if the push button is pressed

    PORTB = 0x01; // Light Up 1st LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x02; // Light Up 2nd LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x04; // Light Up 3rd LED

  • 8/6/2019 LAB Six Print Diz

    12/19

    Vdelay_ms(time); // one second delay

    PORTB = 0x08; // Light Up 4th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x10; // Light Up 5th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x20; // Light Up 6th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x40; // Light Up 7th LED

    Vdelay_ms(time); // one second delay

    PORTB = 0x80; // Light Up 8th LED

    Vdelay_ms(time); // one second delay

    }

    else if(PORTA.F4==1)

    PORTB = 0;

    }

    }

  • 8/6/2019 LAB Six Print Diz

    13/19

    5. Verification for the result from procedure 8

    From the observation based on procedure 8 , we observed that, when we press the push button,

    the LED will ON and it will running faster. And if we not press the push button, the LED will

    running slower than before. These have showed that, we manage to control the running light

    application.

    Source Code:

    void main() {

    int time = 500 ;

    int time2 = 2000;

    PORTB = 0xFF; //Light Up all LED

    TRISB = 0; // Configure PORTB as output

    TRISA = 0x10; //Configure PORTA pin 4 as input

    while(1) {

    // read the switch condition

    if(PORTA.F4==0) { // check if push button is pressed

    PORTB = 0x01; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x02; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x04; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x08; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x10; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x20; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

  • 8/6/2019 LAB Six Print Diz

    14/19

    PORTB = 0x40; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    PORTB = 0x80; // Light Up first LED

    Vdelay_ms(time); // 0.5 second delay

    }

    else if (PORTA.F4 == 1) // check if push button is released

    { PORTB = 0x01; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x02; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x04; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x08; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x10; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x20; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x40; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    PORTB = 0x80; // Light Up first LED

    Vdelay_ms(time2); // 2 second delay

    }

    }

    }

  • 8/6/2019 LAB Six Print Diz

    15/19

    HEX File

    :1000000087EF00F0FFFFFFFFF40E196E010E1A6E6E

    :10001000000E1B6E1C6E17C000F018C001F0000E21

    :10002000026E036EF40E046E010E056E000E066E77

    :10003000000E076EE0EC00F000C019F001C01AF0ED

    :1000400002C01BF003C01CF0000E035C08E1000EB0

    :10005000025C05E1020E015C02E1940E005C00010D

    :10006000D8A012000001940E006E020E016E000E68

    :10007000026E036E19C004F01AC005F01BC006F032

    :100080001CC007F00050045E0150055A0250065A89

    :100090000350075A04C019F005C01AF006C01BF03F

    :1000A00007C01CF0050E006E04C019F005C01AF060

    :1000B00006C01BF007C01CF00050000107E01C3216

    :1000C0001B321A3219321C9EFF0FF7D7000119C0DC

    :1000D00000F01AC001F01BC002F01CC003F0010EBA

    :1000E000195E000E1A5A1B5A1C5A005001100210B9

    :1000F00003100CE000000000000000000000000001

    :1001000000000000000000000000E0D71200E80E30

    :10011000156E030E166EFF0E816E936A100E926EB0

    :10012000016A80B8012A0150000A41E1010E816E86

    :1001300015C017F016C018F004EC00F0020E816E26

    :1001400015C017F016C018F004EC00F0040E816E14

    :1001500015C017F016C018F004EC00F0080E816E00

    :1001600015C017F016C018F004EC00F0100E816EE8

    :1001700015C017F016C018F004EC00F0200E816EC8

    :1001800015C017F016C018F004EC00F0400E816E98

    :1001900015C017F016C018F004EC00F0800E816E48

    :1001A00015C017F016C018F004EC00F007D0016A73

    :1001B00080B8012A0150010AD8B4816AB1D7FFD7AB

  • 8/6/2019 LAB Six Print Diz

    16/19

    :1001C0000001220E0C6E086A096A0A6A0B6A0C06A4

    :1001D000D8B40DEF01F0D8900B320A320932083250

    :1001E0000332023201320032D8A0E7EF00F00C06F1

    :1001F000D8B405EF01F00450082605500922065036

    :100200000A2207500B22ECEF00F00450082605509C

    :10021000092206500A2207500B221200FFFFFFFF9F

    :020000040030CA

    :0E000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF00

    :00000001FF

  • 8/6/2019 LAB Six Print Diz

    17/19

    Question

    Q1: Based on the observation of procedure 3 and procedure 4, technically explain the

    effect of time delay to the running light application and its reason.

    The smaller time delay, the faster running light application. This is because when the time delay

    to 1 second, the LED light up one another in the interval time of 1 second. On the other hand,

    when set the time smaller which is 0.5 second, the LED light up one another in the interval time

    of 0.5 second. So that, the LED light up more faster.

    Q2: Draw the pull up circuit of the push button connected to PORTA pin 4 , the circuit will give

    logic 0 when the push button is pressed, and logic 1 when the push button is released. Show

    simple analysis to prove it.

  • 8/6/2019 LAB Six Print Diz

    18/19

    Q3: Draw the flowchart for both program given in the manual

  • 8/6/2019 LAB Six Print Diz

    19/19

    DISCUSSION

    In this experiment, mikroC have been used as compiler. MikroC is one of the most powerful

    compiler. By using this compiler, the programme manages to run the source code and make the

    light running according to the time delay as desired. MikroC allows to quickly develop and

    deploy complex applications. Besides that, it is proven when the time delay is smaller, the LED

    should lights up faster according to sequent. For part A, it is learnt on how to running the LED,

    for delay time of 2 seconds, 1 seconds and 0.5 seconds. For part B, by push the button in the

    breadboard, the running lights were managed to control. When the button were pushed, the

    LEDs will blink faster. Contrarily, when the button were released, the LEDs will blink slowly

    again.

    CONCLUSION

    From this experiment, the MikroC compiler for PIC is learnt and utilized for a programming

    purpose of the microcontroller. Besides that, it is also learnt understood how the process of I/O

    pin assignments and how to program the I/O input. From this experiment also, to familiarize with

    I/O interfacing is also acknowledged accordingly. The most important thing in this experiment is

    utilizing time delay in Input Output Interfacing were considered carefully. In this experiment

    also the programme on how to running light and control the running lights were learnt. In a

    nutshell, the main objectives of this experiment have been achieved successfully.