Sei sulla pagina 1di 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 debugging your 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

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

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.

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 code will 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 for procedure 3

void main() { int time = 1000 ; PORTB = 0; TRISB = 0; // Initialize PORTB // Configure PORTB as output

while(1) { PORTB = 0x01; Vdelay_ms(time); PORTB = 0x02; Vdelay_ms(time); PORTB = 0x04; Vdelay_ms(time); PORTB = 0x08; Vdelay_ms(time); PORTB = 0x10; Vdelay_ms(time); // Light Up 1st LED // one second delay // Light Up 2nd LED // one second delay // Light Up 3rd LED // one second delay // Light Up 4th LED // one second delay // Light Up 5th LED // one second delay

PORTB = 0x20; Vdelay_ms(time); PORTB = 0x40; Vdelay_ms(time); PORTB = 0x80; Vdelay_ms(time); } }

// Light Up 6th LED // one second delay // Light Up 7th LED // one second delay // Light Up 8th LED // one second delay

LST file

; ADDRESS

OPCODE

ASM

; ---------------------------------------------$0000 $EF87 F000 _Mul_32x32_U: MOVLB MOVLW MOVWF CLRF CLRF CLRF CLRF _NEXT: DECF STACK_12, F, 0 0 34 STACK_12, 0 GOTO _main

$019E $ $019E $0100 $01A0 $0E22 $01A2 $6E0C $01A4 $6A08 $01A6 $6A09 $01A8 $6A0A $01AA $6A0B $01AC $ $01AC $060C $01AE $B4D8

STACK_8, 0 STACK_9, 0 STACK_10, 0 STACK_11, 0

BTFSC STATUS, Z, 0 GOTO _EXIT2 BCF _LOOP: STATUS, C, 0

$01B0 $EFFC F000 $01B4 $90D8 $01B6 $

$01B6 $320B $01B8 $320A $01BA $3209 $01BC $3208 $01BE $3203 $01C0 $3202 $01C2 $3201 $01C4 $3200 $01C6 $A0D8 $01C8 $EFD6 F000 $01CC $060C $01CE $B4D8 $01D0 $EFF4 F000 $01D4 $5004 $01D6 $2608 $01D8 $5005 $01DA $2209 $01DC $5006 $01DE $220A $01E0 $5007 $01E2 $220B $01E4 $EFDB F000 $01E8 $ $01E8 $5004 $01EA $2608 $01EC $5005 $01EE $2209 $01F0 $01F2 $01F4 $5006 $220A $5007 _EXIT1:

RRCF RRCF RRCF RRCF RRCF RRCF RRCF RRCF

STACK_11, F, 0 STACK_10, F, 0 STACK_9, F, 0 STACK_8, F, 0 STACK_3, F, 0 STACK_2, F, 0 STACK_1, F, 0 STACK_0, F, 0

BTFSS STATUS, C, 0 GOTO _NEXT DECF STACK_12, F, 0

BTFSC STATUS, Z, 0 GOTO _EXIT1 MOVF STACK_4, W, 0 ADDWF STACK_8, F, 0

MOVF STACK_5, W, 0 ADDWFC STACK_9, F, 0

MOVF STACK_6, W, 0 ADDWFC STACK_10, F, 0

MOVF STACK_7, W, 0 ADDWFC GOTO _LOOP STACK_11, F, 0

MOVF STACK_4, W, 0 ADDWF STACK_8, F, 0

MOVF STACK_5, W, 0 ADDWFC STACK_9, F, 0

MOVF STACK_6, W, 0 ADDWFC STACK_10, F, 0

MOVF STACK_7, W, 0

$01F6 $01F8 $01F8 $0008

$220B $ $0012 $ _VDelay_ms: _EXIT2:

ADDWFC

STACK_11, F, 0

RETURN

;Delays.c,115 :: ;Delays.c,118 :: $0008 $0E88

void VDelay_ms(unsigned Time_ms){ NumberOfCyc = Clock_KHz()>>2; MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVWF 136 VDelay_ms_NumberOfCyc_L0, 0 19 VDelay_ms_NumberOfCyc_L0+1, 0 0 VDelay_ms_NumberOfCyc_L0+2, 0 VDelay_ms_NumberOfCyc_L0+3, 0

$000A $6E19 $000C $0E13 $000E $6E1A $0010 $0012 $0014 $0E00 $6E1B $6E1C

;Delays.c,119 :: $0016 $C017 F000

NumberOfCyc *= Time_ms; MOVFF FARG_VDelay_ms+0, STACK_0 MOVFF FARG_VDelay_ms+1, STACK_0+1 MOVLW MOVWF MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF 0 STACK_0+2, 0 STACK_0+3, 0 136 STACK_4, 0 19 STACK_4+1, 0 0 STACK_4+2, 0 0 STACK_4+3, 0

$001A $C018 F001 $001E $0E00 $0020 $0022 $0024 $0026 $0028 $6E02 $6E03 $0E88 $6E04 $0E13

$002A $6E05 $002C $0E00 $002E $6E06 $0030 $0032 $0034 $0038 $0E00 $6E07 $ECCF F000 $C000 F019

CALL _mul_32x32_u MOVFF STACK_0, VDelay_ms_NumberOfCyc_L0 MOVFF STACK_0+1, VDelay_ms_NumberOfCyc_L0+1

$003C $C001 F01A

$0040 $0044

$C002 F01B $C003 F01C

MOVFF STACK_0+2, VDelay_ms_NumberOfCyc_L0+2 MOVFF STACK_0+3, VDelay_ms_NumberOfCyc_L0+3 if (NumberOfCyc < 660) MOVLW 0

;Delays.c,120 :: $0048 $0E00

$004A $5C03 $004C $E108 $004E $0E00 $0050 $0052 $0054 $0056 $0058 $5C02 $E105 $0E02 $5C01 $E102

SUBWF STACK_0+3, 0, 0 BNZ L_VDelay_ms_5 0

MOVLW

SUBWF STACK_0+2, 0, 0 BNZ L_VDelay_ms_5 2

MOVLW

SUBWF STACK_0+1, 0, 0 BNZ L_VDelay_ms_5 148

$005A $0E94 $005C $5C00 $005E $ $005E $0100 $0060 $A0D8 return; L_VDelay_ms_5:

MOVLW

SUBWF STACK_0, 0, 0

MOVLB

BTFSS STATUS, C, 0

;Delays.c,121 :: $0062 $0064 $0012 $ L_VDelay_ms_2:

RETURN

;Delays.c,122 :: $0064 $0066 $0068 $0100 $0E94 $6E00

NumberOfCyc -= 660; MOVLB MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVWF 0 148 STACK_0, 0 2 STACK_0+1, 0 0 STACK_0+2, 0 STACK_0+3, 0

$006A $0E02 $006C $6E01 $006E $0E00 $0070 $0072 $0074 $6E02 $6E03 $C019 F004

MOVFF VDelay_ms_NumberOfCyc_L0, STACK_4

$0078

$C01A F005

MOVFF VDelay_ms_NumberOfCyc_L0+1, STACK_4+1 MOVFF VDelay_ms_NumberOfCyc_L0+2, STACK_4+2 MOVFF VDelay_ms_NumberOfCyc_L0+3, STACK_4+3 MOVF STACK_0, 0, 0 SUBWF STACK_4, 1, 0 MOVF STACK_0+1, 0, 0 SUBWFB STACK_4+1, 1, 0

$007C $C01B F006 $0080 $0084 $0086 $0088 $C01C F007 $5000 $5E04 $5001

$008A $5A05 $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

: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

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; TRISB = 0; TRISA = 0x10; // Initialize PORTB // Configure PORTB as output

while(1) { //read the switch condition if(PORTA.F4==0) { // check if the push button is pressed PORTB = 0x01; Vdelay_ms(time); PORTB = 0x02; Vdelay_ms(time); PORTB = 0x04; // Light Up 1st LED // one second delay // Light Up 2nd LED // one second delay // Light Up 3rd LED

Vdelay_ms(time); PORTB = 0x08; Vdelay_ms(time); PORTB = 0x10; Vdelay_ms(time); PORTB = 0x20; Vdelay_ms(time); PORTB = 0x40; Vdelay_ms(time); PORTB = 0x80; Vdelay_ms(time); } else if(PORTA.F4==1)

// one second delay // Light Up 4th LED // one second delay // Light Up 5th LED // one second delay // Light Up 6th LED // one second delay // Light Up 7th LED // one second delay // Light Up 8th LED // one second delay

PORTB = 0; } }

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; TRISB = 0; TRISA = 0x10; //Light Up all LED // Configure PORTB as output //Configure PORTA pin 4 as input

while(1) { // read the switch condition if(PORTA.F4==0) { PORTB = 0x01; // check if push button is pressed // Light Up first LED Vdelay_ms(time); PORTB = 0x02; Vdelay_ms(time); PORTB = 0x04; Vdelay_ms(time); PORTB = 0x08; Vdelay_ms(time); PORTB = 0x10; Vdelay_ms(time); PORTB = 0x20; Vdelay_ms(time); // 0.5 second delay // Light Up first LED // 0.5 second delay // Light Up first LED // 0.5 second delay // Light Up first LED // 0.5 second delay // Light Up first LED // 0.5 second delay // Light Up first LED // 0.5 second delay

PORTB = 0x40; Vdelay_ms(time); PORTB = 0x80; Vdelay_ms(time);

// Light Up first LED // 0.5 second delay // Light Up first LED // 0.5 second delay

} else if (PORTA.F4 == 1) { PORTB = 0x01; // check if push button is released // Light Up first LED Vdelay_ms(time2); PORTB = 0x02; Vdelay_ms(time2); PORTB = 0x04; Vdelay_ms(time2); PORTB = 0x08; Vdelay_ms(time2); PORTB = 0x10; Vdelay_ms(time2); PORTB = 0x20; Vdelay_ms(time2); PORTB = 0x40; Vdelay_ms(time2); PORTB = 0x80; Vdelay_ms(time2); } } } // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay // Light Up first LED // 2 second delay

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

:1001C0000001220E0C6E086A096A0A6A0B6A0C06A4 :1001D000D8B40DEF01F0D8900B320A320932083250 :1001E0000332023201320032D8A0E7EF00F00C06F1 :1001F000D8B405EF01F00450082605500922065036 :100200000A2207500B22ECEF00F00450082605509C :10021000092206500A2207500B221200FFFFFFFF9F :020000040030CA :0E000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF00 :00000001FF

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.

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

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.

Potrebbero piacerti anche