Professional Documents
Culture Documents
I. INTRODUCTION
A microcontroller is a self-supporting single chip
processor with all constituent subsystems of an ordinary
desktop computer. A microcontroller is basically a
computer, which is in much smaller size. Microcontroller
is a specific purpose computer which run specific
program and commands, unlike the general purpose
computer that we use daily. Microcontroller is an
integrated device with features of central processing unit
(CPU), ROM (read-only-memory), RAM (random access
memory), registers, input output ports (such as UARTs),
peripherals (such as timers and event counters), analog-todigital converter/ digital-to-analog converter, clock and
others serial communications interfaces (I2C, Controller
Area Network). Microcontroller is usually embedded
inside a device which require moderate amount of local
intelligence within given application. Microcontroller is
employed to control the functions, actions and features of
the device. Microcontroller is programmed to run specific
program and is dedicated to specific task. This specific
program is saved and stored in the ROM of the
microcontroller. [2]
II. OBJECTIVE
A. Able to understand the specification of
Microcontroller, Peripheral Interface Controller
(PIC), circuit and wiring of the PIC.
B. Able to understand the basic concept of integrating
between the PICBasicPro, Proteus and PICKit2 with
SK40C and UIC00B.
Fig. 6. LED and Switches Logic (ii) when SW1 and SW2 are ON.
Fig. 3. LED and Switches Logic (ii) when SW1 and SW2 are OFF.
Fig. 4. LED and Switches Logic (ii) when only SW1 is ON.
ENDIF
PAUSE 1000
GOTO MAINLOOP
Explanation:
Fig. 5. LED and Switches Logic (ii) when only SW2 is ON.
Fig. 7. LED and Switches Logic (iii) when SW1 and SW2 are OFF.
ELSE
PORTB.6 = 0
PORTB.7 = 0
ENDIF
PAUSE 1000
GOTO MAINLOOP
Explanation:
Fig. 8. LED and Switches Logic (iii) when SW1 is ON and SW2 is OFF.
Fig. 9. LED and Switches Logic (iii) when SW1 is OFF and SW2 is ON.
Fig. 10. LED and Switches Logic (iv) when SW1 is OFF.
Fig. 11. LED and Switches Logic (iv) when SW1 is ON.
DEFINE OSC 20
TRISB = %00000011
PORTB = $00
MAINLOOP
IF PORTB.0 = 0 THEN
PORTB.6 = 1
PORTB.7 = 0
ELSEIF PORTB.1 = 0 THEN
PORTB.6 = 0
PORTB.7 = 1
ELSE
PORTB.6 = 0
PORTB.7 = 0
Fig. 13. LED and Switches Logic (v) when SW1 is ON and SW2 is
OFF.
ENDIF
PAUSE 5
GOTO MAINLOOP
Explanation:
The oscillator is set to frequency of 20 mHz and
PORTB is configure as the input and output for this
program. PORTB.0 and PORTB.1 are set as input while
PORTB.2 to PORTB.7 are set as outputs. In mainloop, if
PORTB.0 is low (active low), then PORTB.6 will be high
while PORTB.7 will remain low, else if PORTB.1 is low
(active low), then PORTB.6 will be low and PORTB.7
will be high. In this case, PORTB.0 is SW1 and PORTB.1
is SW2 while PORTB.6 is LED1 and PORTB.7 is LED2.
As SW1 is pressed (ON), PORTB.0 is low (active low),
LED1 will lights up, else if SW2 is pressed (ON),
Fig. 14. LED and Switches Logic (v) when SW1 is OFF and SW2 is
ON.
2) LED Sequential
PAUSE 5000
WHILE PORTB.6 = 1
PORTB.6 = 0
PORTB.7 = 1
WEND
ENDIF
GOTO MAINLOOP
Explanation:
The oscillator is set to frequency of 20 mHz and
PORTB is configure as the input and output for this
program. PORTB.0 and PORTB.1 are set as input while
PORTB.2 to PORTB.7 are set as outputs. In mainloop, if
PORTB.0 is low (active low), PORTB.6 will be high for
5000 milliseconds (5 seconds) and then PORTB.7 will be
high. In this case, PORTB.0 is SW1 while PORTB.6 is
LED1 and PORTB.7 is LED2. As SW1 is pressed (ON),
PORTB.0 is low (active low), LED1 will lights up for
5000 milliseconds and then LED2 will lights up. Then the
statements in mainloop will start all over again after the
execution.
Switch HIGH
Statement
Perform
YES
LED1 HIGH
After 5 seconds
LED1 HIGH
LED2 LOW
END
ii.
Code:
DEFINE OSC 20
INCLUDE "modedefs.bas"
TRISB = %00000011
PORTB = $00
MAINLOOP:
IF PORTB.0 = 0 THEN
PORTB.6 = 1
PORTB.7 = 1
PAUSE 5000
WHILE PORTB.7 = 1
PORTB.6 = 0
WEND
ENDIF
GOTO MAINLOOP
Explanation:
The oscillator is set to frequency of 20 mHz and
PORTB is configure as the input and output for this
program. PORTB.0 and PORTB.1 are set as input while
PORTB.2 to PORTB.7 are set as outputs. In mainloop, if
PORTB.0 is low (active low), PORTB.6 and PORTB.7
will be high for 5000 milliseconds (5 seconds) and then
PORTB.7 will continue to be high while PORTB.6 will be
low. In this case, PORTB.0 is SW1 while PORTB.6 is
LED1 and PORTB.7 is LED2. As SW1 is pressed (ON),
PORTB.0 is low (active low), both LED1 and LED2 will
light up for 5000 milliseconds and then LED1 will turn
off while LED2 will continue to lights up. Then the
statements in mainloop will start all over again after the
execution.
Switch HIGH
NO
Statement
Perform
YES
LED1 HIGH
LED2 HIGH
After 5 seconds
LED1 HIGH
LED2 LOW
ENDIF
IF PORTB.1 = 0 THEN
PORTD = %10000000
PAUSE 100
PORTD = %10000000 >> 1
PAUSE 100
PORTD = %01000000 >> 1
PAUSE 100
PORTD = %00100000 >> 1
PAUSE 100
PORTD = %00010000 >> 1
PAUSE 100
PORTD = %00001000 >> 1
PAUSE 100
PORTD = %00000100 >> 1
PAUSE 100
PORTD = %00000010 >> 1
PAUSE 100
PORTD = %00000001 >> 1
PAUSE 100
ENDIF
END
PAUSE 100
3) LED Running Light
The LED running light is designed using to 8
LEDs.
Code:
DEFINE OSC 20
TRISB = %00000011
TRISD = %00000000
PORTD = $00
PORTB = $00
MAINLOOP
IF PORTB.0 = 0 THEN
PORTD = %00000001
PAUSE 100
PORTD = %00000001 << 1
PAUSE 100
PORTD = %00000010 << 1
PAUSE 100
PORTD = %00000100 << 1
PAUSE 100
PORTD = %00001000 << 1
PAUSE 100
PORTD = %00010000 << 1
PAUSE 100
PORTD = %00100000 << 1
PAUSE 100
PORTD = %01000000 << 1
PAUSE 100
PORTD = %10000000 << 1
PAUSE 100
GOTO MAINLOOP
Explanation:
The oscillator is set to frequency of 20 mHz, and
PORTB and PORTD are configured as the input and
output for this program. PORTB.0 and PORTB.1 are set
as input while PORTD are set as outputs. In the mainloop,
if PORTB.0 is low (active low), PORTDs output will be
00000001 which means that the PORTD.0 will be high
while others are low for 100 milliseconds. Then PORTDs
output will change to 00000010 which means PORTD.1
will be high while others are low. The 1 will shift from
PORTD.0 to PORTD.7 one by one from LED1 to LED8
and the << means that the1 will shift to the left by 1
bit. Else if PORTB.1 is low (active low), PORTDs output
will be 1000000 which means that the PORTD.7 will be
high while others are low for 100 milliseconds. Then
PORTDs output will change to 01000000 which means
PORTD.1 will be high while others are low. The 1 will
shift from PORTD.7 to PORTD.0 one by one from LED8
to LED1 and the >> means that the 1 will shift to the
right by 1 bit. In this case, the LED will light up one after
the other one for 100 milliseconds. After execution, the
program will reset itself and wait for input for the next
execution.
Simulation using Proteus:
Fig. 21. LED Running Light when SW1 and SW2 are OFF.
Fig. 24. LED Running Light when SW1 is OFF and SW2 is ON.
Fig. 22. LED Running Light when SW1 is ON and SW2 is OFF.
Fig. 25. LED Running Light when SW1 is ON, SW2 is OFF. The LED
is light up one after another from LED8 to LED1.
Switch1 HIGH
Switch2 HIGH
LED1 HIGH
LED8 HIGH
LED2 HIGH
LED7 HIGH
LED3 HIGH
LED6 HIGH
LED4 HIGH
LED5 HIGH
LED5 HIGH
LED4 HIGH
LED6 HIGH
LED3 HIGH
LED7 HIGH
LED2 HIGH
Fig. 23. LED Running Light when SW1 is ON, SW2 is OFF. The LED
is light up one after another from LED1 ro LED8.
LED1 HIGH
LED8 HIGH
END
IN VAR BYTE
TRISA = %11111111
TRISB = %00000000
ADCON1 = 0
PORTB = $00
mainloop
ADCIN 0,IN
IF IN = 0 then
PORTB = 0
ELSEIF IN > 0 and IN < 32 then
PORTB = 1
ELSEIF IN >= 32 and IN < 64 then
PORTB = 3
ELSEIF IN >= 64 and IN < 96 then
PORTB = 7
ELSEIF IN >= 96 and IN < 128 then
PORTB = 15
ELSEIF IN >= 128 and IN < 160 then
PORTB = 31
>224
>85.96
255
1111 1111
193 - 223
127
0111 1111
Code:
DEFINE OSC 20
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
72.99
161 - 192
63
0011 1111
59.23
129 -160
31
0001 1111
50.49
97 - 128
15
0000 1111
39.15
65 - 96
7
0000 0111
26.01
33 - 64
3
LED (binary)
0000 0011
15.12
1 32
1
5.04
LED (decimal)
0000 0001
Maximum
potentiometer
reading (%)
IN(byte)
TABLE I.
Explanation:
0000 0000
B. Analog Input
1) Read analog input using potentiometer and show
the result of ADC conversion using 8 LEDs.
PORTB = 127
'hot
ENDIF
GOTO MAINLOOP
Explanation:
2) Case Study
A client asked you to develop a temperature monitoring
system using PIC microcontroller to monitor the
temperature inside a room. The system must indicate
when reaches high temperature, red LED must be on. And
when the temperature is below low level, yellow light is
turn on. Green LED will light at ideal room temperature.
Code:
DEFINE ADC_SAMPLEUS 50
T VAR BYTE
AnVal VAR BYTE
TRISA = %11111111
TRISB = %00000000
ADCON1 = 0
PORTB = $00
Fig. 28. At ideal room temperature.
MAINLOOP
ADCIN 0,AnVal
T = AnVal*500/255
IF T < 10 then
PORTB = 1
'cold
'cold
'cold
'normal
REFERENCES
ELSEIF T >= 30 and T < 40 then
PORTB = 31
'normal
'hot
'hot
[1]
[2]
[3]
[4]