Professional Documents
Culture Documents
To view the following file names with underline, press mouses left click. But your
windows must have corresponding software.
1. .jpg files need photo viewer software to view this images.
2. .avi files and .mp4 files - need video viewer software to view this video.
3. .rpp files need Real PIC Simulator software to open this project files.
When you place mouse pointer over these names for 2 seconds, detail file
location will be appeared.
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x3
x5
x2
x2
YWT-2
YWT-3
(3) You can supply PIC circuit by 5V USB phone power bank(battery). Use
modified USB power cable.
Image =>img_0375.jpg
(OR)
(4) You can get 5V from 9V battery by using 7805 IC.
Image => img_0200.jpg
(OR)
(5) You can get 5V from DC 12V adaptor by using 7805 IC.
Image => img_0384.jpg
YWT-4
7805
Vin
+
9V(or)12V _
Vout
+
Gnd
5V
_
YWT-5
(2) You can supply PIC board by 5V USB phone charger .Use modified USB power
cable.
Image => img_0373.jpg
img_0374.jpg
(OR)
(3) You can supply PIC Board directly from 5V USB phone power bank.
Image => img_0364.jpg
(OR)
(4) You can supply PIC board by 5V USB phone power bank. Use modified USB
power cable.
Image => img_0371.jpg
img_0372.jpg
(OR)
(5) You can supply PIC board directly from 5V power supply.
Image => img_0196.jpg
(OR)
(6) You can get 5V from 9V battery by using 7805 IC.
Image => img_0287.jpg
(OR)
(7) You can get 5V from DC 12V adaptor by using 7805 IC.
Image => img_0385.jpg
img_0387.jpg
Warning Do not use Computers USB port to get 5V for this board. It can
damage the computer due to error of short circuit by board error or user error.
YWT-6
Step 2 -Connect MCLR pin to +5V using 4.7k(or 10k) resistor. In pic16f84, MCLR
pin is 4.
Step 3 -Some modern PIC can run without external clock because they have builtin (internal) clock(oscillator).But pic16F84 need external clock circuit (in this
example, use one 4MHz crystal and two of 22pf capacitor to operate as 4Mhz
external clock circuit.).
Connect OSC1 and OSP2 pins with the clock circuit. In pic16f84, OSC1 pin
is 16 and OSC2 pin is 15.
Now,pic16F84 is in running mode and any input/output pins can be used.
Image => img_0023.jpg
img_0195.jpg
22pF
22pF
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
PIC 16F84A
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K
(or)
10K
+5V
YWT-7
+5V in/out
330
+5V
Gnd
RGB
LED
22pF
150
Pink
LED
100
Violet
LED
100
Blue
LED
150
Green
LED
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
+5V
USB
connector
For
5V power
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
connector
150 Yellow
LED
RA1
RA2
RA3
RA4
150 Orange
LED
Ground
Jumper
4.7K
+5V
connector
connector
150
Red
LED
+5V
The value of R may be vary depend upon the color, size and type of LED.
By Ohm Law(V=IR) => R = V/I =>So, Resistance for LED=(Supply Voltage LED
Voltage)/LED current
If ( red, orange, yellow, pink, green ) transparent LED use 2V & 20mA,
R=(5V-2V)/20mA = 150,so 150 resistor can be used.
YWT-8
YWT-9
Chapter (1)
OUTPUT with LED
In PIC 16F84 or PIC 16F627A, any I/O pin from PortA(RA0,RA1,RA2,RA3,RA4) and
any I/O pin from PortB (RB0 ,RB1 ,RB2 ,RB3, RB4, RB5, RB6,RB7) can be use
separately as input or output as you like. But you must declare them as input or
output before use them. To assign input or output pins for portA, we use TRISA
(Tri-state A) register, and TRISB (Tri-state B) register for portB. If we assign pins
for neither input nor output, the program assume these pins as output.
RA4
TRISA
0x85
RA4
PORTA
0x05
RA3 RA2
RA0 (LSB)
5V
5V
0V
5V
Fig 1-4
For example ,in Fig 1-4, assign RA0,RA1,RA4 as input(mark by "1") and
RA2,RA3 as output(mark by "0"),so enter binary (0b00010011) or hexa (0x13) or
decimal(19) to TRISA.
After assigning as output pins, if you enter that these pins to "logic 1",they
will become 5V.And if you enter these pins to "logic 0",they will become 0V.Input
pins can be neglect when enter values to output pins. In Fig 1-4, enter PORTA to
8(or 0b00001000 or 0x08) to become RA2 to 0V and RA3 to 5V.
RB7
TRISB
0x86
PORTB
0x06
RB6 RB5
RB0(LSB)
RB7
RB6
5V
5V
0V
0V
5V
5V
RB5 RB4
YWT-10
Example 1-0 => After burning Exp1_0.hex to PIC, PortBs RB0 pin will be assign
as output pin and produce 5V( logic 1 ).So, the red LED will be ON.
main()
{
RB0
330 Ohm
TRISB=0;
Red LED
PORTB=1;
}
Fig 1-6
Exp1_0.c
According to TRISB=0; , all of 8 bits in TRISB register will be fill with 0
and it means that it declare that all of 8 pins in PORTB(RB0 to RB7) will be used
as output pins.
In, PORTB=1 , convert 1 to binary is 0000 0001.So last bit(bit 0=RB0)
of PORTB will be 1 and it mean that RB0 pin will produce 5V.
When logic 1, RB0 pin produce 5V which exceed Red LEDs normal
working voltage(1.5V with 10mA) and the LED may be burn.
Therefore, a resistor is needed to reduce 5V to 1.5V.The require resistance
is (Total Volt-LED Volt)/(LED current) = (5-1.5)/10m=350 ,So 330 Ohm resistor can
be used.
22pF
22pF
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K
(or)
10K
+5V
330
Ohm
Red
LED
Fig 1-7 . Complete circuit diagram for example 1-0 and 1-1
YWT-11
Step 4 (i)- If your PIC programmer is GTP-USB Board- write that hex file to a PIC(pic16F84A) by using a PIC programmer device
and software. Notice Jumper position.
YWT-12
Note In this video , we use GTP-USB Board and PicKit3 as PIC programmer
device and WinPIC800 and PicKit3 programmer application as PIC programmer
software. If you use another type of PIC programmer and programmer software,
step 3 and 4 may be different. You can buy pickit3 programmer from Circuit
World Electronics shop, Mandalay. Phone-09-6800396 .
Step 5 Then, insert the PIC and required electronics components to project
board as shown in Fig1-7. The LED will be ON.
Image => BeforeProgramBurn.jpg
AfterProgramBurn.jpg
Making my GTP-USB PIC Programmer
If you want to burn GTP_USB.hex file to new PIC18F2550(24 pin) for your
new GTP-USB PIC programmer PCB board, change jumper position and burn.
Image => NewPICandBoard.jpg
BurnPic18F2550.jpg
BurnPic18F2550_JumperConnection.jpg
BurnPic18F2550_ZIF_JumperConnection.jpg
YWT-13
RB0
330 Ohm
Red LED
Fig 1-6
Exp1_1.c
main()
{
TRISB = 0xFE ;
while(1)
{
PORTB = 0x01;
Delay_ms(500);
PORTB = 0x00;
Delay_ms(500);
}
}
YWT-14
Explanation
TRISB=0xFE; => put the hexa-decimal value of FE to TRISB register.
Hexa FE(0xFE) = Binary 1111 1110(0b11111110) = Decimal 254(254).
So you can replace TRISB=0xFE; with TRISB=0b11111110; (or) TRISB=254;
You can use windows 7 built-in calculator with programmer mode to change
hexa
=> binary,octa,decimal video => HexToOthersWithWin7Calc.mp4
Binary => hexa,octa,decimal
video => BinToOthersWithWin7Calc.mp4
Decimal => binary, hexa, octa
video => DecToOthersWithWin7Calc.mp4
According to this statement, last bit(bit 0) of TRISB register which is assigned to
RB0 is 0 and other bits(bit 1 to 7 which is assigned to RB1 to RB7) are 1.That
mean that this program declare RB0 pin as output and declare RB1 to RB7 pins
as input.
While(1) { Process 1; Process 2; Process 3;etc.. } => means that the program
lines between { and } will do repeat and repeat forever.
Eg. Will do =>Process 1; Process 2; Process 3;etc.. Process 1; Process 2;
Process 3; etc..Process 1; Process 2; Process 3;etc.. Process 1; Process 2;
Process 3;etc until program stop.
Delay_ms(500); => the program will be in waiting state for 500 mili-seconds.
1000 mili-seconds = 1 seconds
YWT-15
In Brief,
At the first of program, declare RB0 as output.
Step 1 to 4 are in while(1) loop. So, step 1 to 4 will do in sequence and repeatedly
forever.
Step 1 RB0 become logic 1 and produce 5V.So LED will ON.
Step 2- wait for 500 mili-second (or) 0.5 second. During this time, the
program do nothing. So, LED will still ON.
Step 3 - RB0 become logic 0 and produce 0V.So LED will OFF.
Step 4- wait for 500 mili-second (or) 0.5 second. During this time, the
program do nothing. So, LED will still OFF.
So, while running this program, LED at RB0 will blink in every second.
You can run Example 1-1 on Project board with 9V battery and 7805 IC.
7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
YWT-16
This section shows Example 1-1 circuit with various color of LED.
Image => IMG_0216.jpg (Red Transparent LED with 150 Ohm, OFF)
IMG_0215.jpg (Red Transparent LED with 150 Ohm, ON)
Video => MVI_0218.avi (Red Transparent LED with 150 Ohm)
Image => IMG_0216.jpg (Orange Transparent LED with 150 Ohm, OFF)
IMG_0220.jpg (Orange Transparent LED with 150 Ohm, ON)
Video => MVI_0219.avi (Orange Transparent LED with 150 Ohm)
Image => IMG_0216.jpg (Yellow Transparent LED with 150 Ohm, OFF)
IMG_0221.jpg (Yellow Transparent LED with 150 Ohm, ON)
Video => MVI_0222.avi (Yellow Transparent LED with 150 Ohm)
YWT-17
Image => IMG_0216.jpg (Green Transparent LED with 150 Ohm, OFF)
IMG_0223.jpg (Green Transparent LED with 150 Ohm, ON)
Video => MVI_0224.avi (Green Transparent LED with 150 Ohm)
Image => IMG_0229.jpg (Blue Transparent LED with 100 Ohm, OFF)
IMG_0226.jpg (Blue Transparent LED with 100 Ohm, ON)
Video => MVI_0225.avi (Blue Transparent LED with 100 Ohm)
Image => IMG_0229.jpg (Violet Transparent LED with 100 Ohm, OFF)
IMG_0230.jpg (Violet Transparent LED with 100 Ohm, ON)
Video => MVI_0231.avi (Violet Transparent LED with 100 Ohm)
Image => IMG_0216.jpg (Pink Transparent LED with 150 Ohm, OFF)
IMG_0233.jpg (Pink Transparent LED with 150 Ohm, ON)
Video => MVI_0232.avi (Pink Transparent LED with 150 Ohm)
Image => IMG_0229.jpg (White Transparent LED with 100 Ohm, OFF)
IMG_0234.jpg (White Transparent LED with 100 Ohm, ON)
Video => MVI_0235.avi (White Transparent LED with 100 Ohm)
Image => IMG_0214.jpg (White Short Transparent LED with 220 Ohm, OFF)
IMG_0213.jpg (White Short Transparent LED with 220 Ohm, ON)
Video => MVI_0212.avi (White Short Transparent LED with 220 Ohm)
Image => IMG_0201.jpg (RGB color Transparent LED with 330 Ohm, OFF)
YWT-18
You can run Example 1-1 on Project board with 5V power supply.
This section shows Example 1-1 circuit with various color of LED.
Image => IMG_0025.jpg (Red LED with 330 Ohm, OFF)
IMG_0181.jpg (Red LED with 330 Ohm, ON)
Video => MVI_0031.avi (Red LED with 330 Ohm)
Image => IMG_0033.jpg (Red Transparent LED with 150 Ohm, OFF)
Video => MVI_0034.avi (Red Transparent LED with 150 Ohm)
Image => IMG_0036.jpg (White Transparent LED with 100 Ohm, ON)
Video => MVI_0037.avi (White Transparent LED with 100 Ohm)
Image => IMG_0182.jpg (RGB color Transparent LED with 330 Ohm)
You can run Example 1-1 on PIC16F84 PCB board.
Video => MVI_0291.avi
YWT-19
Example 1-2 => Exp1_2.c will blink two LED alternatively with 500 mili-seconds
delay. Exp1_2_2.c will "on" two LED(LED1&LED2=01,10,11,00) with 1000 miliseconds(1 second) delay.
main()
{
TRISB=252;
while(1)
{
PORTB=1;
Delay_ms(1000);
PORTB=2;
Delay_ms(1000);
PORTB=3;
Delay_ms(1000);
PORTB=0;
Delay_ms(1000);
}
}
RB0
330 Ohm
Red LED 1
330 Ohm
Red LED 2
main()
{
TRISB = 0xFC;
while(1)
{
PORTB = 0x01;
Delay_ms(500);
PORTB = 0x02;
Delay_ms(500);
}
}
RB1
Fig 1-8
Exp1_2.c
22pF
Exp1_2_2.c
22pF
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K
330
Ohm Red LED 2
(or)
10K
+5V
330
Red LED 1
Ohm
Fig 1-9 . Complete circuit diagram for example 1-2 and 1-2-2
YWT-20
You can run Example 1-2 on Project board with 9V battery and 7805 IC.
7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
This section shows Example 1-2 circuit with various color of LED.
Image => IMG_0240.jpg ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
Video => MVI_0241.avi ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
You can run Example 1-2 on Project board with 5V power supply.
This section shows Example 1-2 circuit with various color of LED.
Image => IMG_0052.jpg ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
IMG_0053.jpg ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
Video => MVI_0054.avi ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
YWT-21
Image => IMG_0043.jpg (Red(use 330 Ohm) and Yellow(use 330 Ohm) LED )
IMG_0048.jpg (Red(use 330 Ohm) and Yellow(use 330 Ohm) LED )
Video => MVI_0050.avi ( Red(use 330 Ohm) and Yellow(use 330 Ohm) LED )
Image => IMG_0039.jpg (Red(150 Ohm) and Yellow(150 Ohm) Transparent LED )
IMG_0040.jpg (Red(150 Ohm) and Yellow(150 Ohm) Transparent LED )
IMG_0041.jpg (Red(150 Ohm) and Yellow(150 Ohm) Transparent LED )
Video => MVI_0042.avi ( Red(150 Ohm) and Yellow(150 Ohm) Transparent LED )
You can run Example 1-2-2 on Project board with 5V power supply.
Video => MVI_0055.avi ( Red(use 330 Ohm) and Green(use 220 Ohm) LED )
YWT-22
RB0
RB4
330 Ohm
Red LED 1
RB1
330 Ohm
Red LED 5
RB5
330 Ohm
Red LED 2
330 Ohm
Red LED 3
RB2
330 Ohm
Red LED 6
330 Ohm
Red LED 7
RB6
RB3
RB7
330 Ohm
Red LED 4
330 Ohm
Red LED 8
Fig 1-10
Explanation
main()
{
char i,j;
TRISB = 0x00;
while(1)
{
j=1;
for(i=1;i<=8;i++)
{
PORTB = j;
j = j<<1;
Delay_ms(50);
}
}
}
Exp1_3.c
At first of while loop, j=1; => j is 0000 0001, so only last bit (bit 0) will be 1.
In for loop, i start with 1 and increase by 1 then end at 8.So this loop will do 8
times.
In for loop, put value of j to portB, so only RB0 will be ON because j is 00000001.
j=j<<1; => left shift j by 1 and override the new result to j. So, left shift 0000 0001
by 1 get 0000 0010. Then put this value to j. So, js current value is 0000 0010.
j=j<<1;(in binary) is same with j=jx2;(in decimal).
Delay_ms(50); => wait for 50 mili-seconds.
Then, repeat the first line of for loop with j value of 0000 0010. So, only RB1 will
be ON.then,left shift by 1, so j=00000100 ,50mili second delay,
Then repeat and this time, only RB2 will on.. till only RB7 will On and finish for
loop. Then repeat the first line of while loop and while loop will do forever.
YWT-23
main()
{
char i,j;
TRISB = 0x00;
while(1)
{
j=1;
for(i=1;i<=8;i++)
{
PORTB = j;
j = j<<2;
Delay_ms(50);
}
}
}
Exp1_3_2.c
Exp1_3_3.c
Explanation
Exp1-3-2
j=1; => 0000 0001 in binary
Exp1-3-3
j=128; => 1000 0000 in binary ..
YWT-24
22pF
22pF
330
Ohm
Red LED 8
330
Ohm
Red LED 7
330
Ohm
Red LED 6
330
Ohm
Red LED 5
330
Ohm
Red LED 4
330
Ohm
Red LED 3
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K
(or)
10k
+5V
330
Ohm
Red LED 2
330
Red LED 1
Ohm
Fig 1-10 . Complete circuit diagram for example 1-3 and 1-3-2 and 1-3-3
YWT-25
=> PicSimulatorIDE_Install.mp4
You can run Example 1-3 on Project board with 9V battery and 7805 IC.
7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 1-3 on Project board with 5V power supply.
Image => IMG_0056.jpg ( Red LED with 330 Ohm-before connecting wires)
IMG_0059.jpg ( Red LED with 330 Ohm-before connecting wires)
IMG_0060.jpg ( Red LED with 330 Ohm)
YWT-26
You can run Example 1-3-2 on Project board with 9V battery and 7805 IC.
7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 1-3-2 on Project board with 5V power supply.
Video => MVI_0066.avi ( Red LED with 330 Ohm)
MVI_0129.avi ( color LED )
YWT-27
You can run Example 1-3-3 on Project board with 9V battery and 7805 IC.
7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 1-3-3 on Project board with 5V power supply.
Video => MVI_0067.avi ( Red LED with 330 Ohm)
MVI_0128.avi ( color LED )
YWT-28
CHAPTER (2)
INTPUT with Push Button
Example 2-1 and Example 2-2 with Fig 2-1.
+5V
s1
main()
{
TRISA = 1 ;
TRISB = 0 ;
while(1)
{
PORTB.F0=PORTA.F0;
}
}
Exp2_1.c
RA0
RB0
330 Ohm
Red
LED
10K
Ohm
main()
{
TRISA = 1 ;
TRISB = 0 ;
while(1)
{
PORTB.F0=~PORTA.F0;
}
}
Exp2_2.c
YWT-29
In Example 2-1 (when use with Fig 2-1), declare RA0 pin as input (by TRISA=1; )
and declare all Port B pins (RB0 to RB7) as output (by TRISB=0;).
Then set the PORTB.F0(bit 0 of Port B or RB0) to the value of PORTA.F0(bit 0 of
Port A or RA0) within continuously while loop. That mean that, when RA0 is 1,
RB0 will 1 and LED will ON. Otherwise , LED will be OFF. By using this program
with Fig 2-1, LED will only ON while push button S1 is pressed.
In Example 2-2 (when use with Fig 2-1), declare RA0 pin as input (by TRISA=1; )
and declare all Port B pins (RB0 to RB7) as output (by TRISB=0;).
Then set the PORTB.F0(bit 0 of Port B or RB0) to the opposite value of PORTA.F0
(bit 0 of Port A or RA0) within continuously while loop. That mean that, when RA0
is 0, RB0 will 1 and LED will ON. Otherwise , LED will be OFF. ( ~ means apply
by Not Gate ). By using this program with Fig 2-1, LED will only OFF while push
button S1 is pressed.
+5V
22pF
22pF
S1
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
10K
Ohm
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K
(or)
10K
+5V
330
Ohm
Red
LED
Fig 2-2 .Complete circuit diagram for Example 2-1 and Example 2-2 with Fig 2-1.
YWT-30
You can run Example 2-1 with Fig 2-1 in Real PIC Simulator.
Video => Exp2_1 with Fig2_1.mp4
Project file to open with Real PIC Simulator => Exp2_1 with Fig2_1.rpp
You can run Example 2-1 with Figure 2-1 on Project board with 9V battery and
7805 IC. 7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-1 with Figure 2-1 on Project board with 5V power supply.
You can run Example 2-1 with Figure 2-1 on PIC16F84 PCB board.
YWT-31
You can run Example 2-2 with Fig 2-1 in Real PIC Simulator.
Video => Exp2_2 with Fig2_1.mp4
Project file to open with Real PIC Simulator => Exp2_2 with Fig2_1.rpp
You can run Example 2-2 with Figure 2-1 on Project board with 9V battery and
7805 IC. 7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-2 with Figure 2-1 on Project board with 5V power supply.
You can run Example 2-2 with Figure 2-1 on PIC16F84 PCB board.
YWT-32
10K
Ohm
main()
{
TRISA = 1 ;
TRISB = 0 ;
while(1)
{
PORTB.F0=PORTA.F0;
}
}
Exp2_1.c
RA0
RB0
330 Ohm
Red
LED
s1
main()
{
TRISA = 1 ;
TRISB = 0 ;
while(1)
{
PORTB.F0=~PORTA.F0;
}
}
Ex2_2.c
Fig 2-3 . s1 is normal =1, pressed =0 type switch
In Example 2-1 (when use with Fig 2-3, declare RA0 pin as input (by TRISA=1; )
and declare all Port B pins (RB0 to RB7) as output (by TRISB=0;).
Then set the PORTB.F0 (bit 0 of Port B or RB0) to the value of PORTA.F0 (bit 0 of
Port A or RA0) within continuously while loop. That means that, when RA0 is 1,
YWT-33
RB0 will 1 and LED will ON. Otherwise, LED will be OFF. By using this program
with Fig 2-3, LED will only OFF while push button S1 is pressed.
In Example 2-2 (when use with Fig 2-3), declare RA0 pin as input (by TRISA=1; )
and declare all Port B pins (RB0 to RB7) as output (by TRISB=0;).
Then set the PORTB.F0 (bit 0 of Port B or RB0) to the opposite value of PORTA.F0
(bit 0 of Port A or RA0) within continuously while loop. That means that, when
RA0 is 0, RB0 will 1 and LED will ON. Otherwise, LED will be OFF. ( ~ means
apply by Not Gate ). By using this program with Fig 2-3, LED will only ON while
push button S1 is pressed.
+5V
22pF
22pF
10K
Ohm
+5V
4MHz
Crystal
S1
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10K Ohm
+5V
330
Ohm
Red
LED
Fig 2-4 . Complete circuit diagram for Example 2-1 and Example 2-2 with Fig 2-3.
YWT-34
You can run Example 2-1 with Fig 2-3 in Real PIC Simulator.
Video => Exp2_1 with Fig2_3.mp4
Project file to open with Real PIC Simulator => Exp2_1 with Fig2_3.rpp
You can run Example 2-1 with Figure 2-3 on Project board with 9V battery and
7805 IC. 7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-1 with Figure 2-3 on Project board with 5V power supply.
You can run Example 2-1 with Figure 2-1 on PIC16F84 PCB board.
YWT-35
You can run Example 2-2 with Fig 2-3 in Real PIC Simulator.
You can run Example 2-2 with Figure 2-3 on Project board with 9V battery and
7805 IC. 7805 IC is used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-2 with Figure 2-3 on Project board with 5V power supply.
You can run Example 2-2 with Figure 2-3 on PIC16F84 PCB board.
YWT-36
main()
{
TRISA = 1;
TRISB = 0;
PORTB=0;
while(1)
{
while(PORTA.F0==0)
{
while(PORTA.F0==0)
{
10K
Ohm
RA0
Delay_ms(100);
RB0
330 Ohm
Red
LED
PORTB.F0=~PORTB.F0;
s1
}
}
}
Fig 2-4 .
Exp2_3.c
In Fig 2-4, Red LED will ON when RB0 pin is 1(5V).
Before S1 press, RA0 is only connected to 5V through 10K Ohm resistor, so RA0
pin will be 5V(logic 1).
When S1 press, RA0 will connect to ground(0V) directly(virtually consider as
through 0 Ohm resistor) and connect to 5V through 10K Ohm resistor .According
to voltage divider law , RA0 pin will be 0V(logic 0).
YWT-37
YWT-38
+5V
22pF
22pF
10K
Ohm
+5V
4MHz
Crystal
S1
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10K Ohm
+5V
330
Ohm
Red
LED
YWT-39
You can run Example 2-3 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-3 on Project board with 5V power supply.
YWT-40
+5V
+5V
10K
Ohm
10K
Ohm
RA0
RA1
RB0
330 Ohm
S1
S2
Red
LED
Fig 2-6.
main()
{
TRISA = 0b00000011;
TRISB = 0b11111110;
PORTB=0;
while(1)
{
while(PORTA.F0==0)
{
PORTB.F0=1;
while(PORTA.F0==0)
{
Delay_ms(100);
}
}
while(PORTA.F1==0)
{
PORTB.F0=0;
while(PORTA.F1==0)
{
Delay_ms(100);
}
}
}
}
Exp2_4.c
YWT-41
Declare the last bit of PORTB(RA0) as output and others in PORTB as input by
writing TRISB register to 254(as binary-0b11111110) using the commandTRISB=0b11111110;
Set PORTBs initial value to 0 to be 0V at all PORTBs pins by PORTB=0;
Then, while(1) { } loop will repeat continuously until the program stop.
In while(1) loop, there are two while loops. while(POTRA.F0==0) loop and
while(POTRA.F1==0) loop.
while(POTRA.F0==0) loop will do while RA0 is 0(while S1 is pressed).In this
loop, set RB0 to 1(to ON LED) and use other 0.1 second waiting while loop until
RA0 is 1(when S1 is released).
while(POTRA.F1==0) loop will do while RA1 is 0(while S1 is pressed).In this
loop, set RB0 to 0(to OFF LED) and use other 0.1 second waiting while loop
until RA1 is 1(when S1 is released).
+5V
22pF
22pF
10K
Ohm
+5V
4MHz
Crystal
+5V
S1
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
10K
Ohm
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
S2
4.7K Ohm
(or)
10K Ohm
+5V
330
Ohm
Red
LED
YWT-42
You can run Example 2-4 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 2-4 on Project board with 5V power supply.
YWT-43
CHAPTER (3)
PRODUCING SOUND
2ndcycle
Time(second)
0.5
T1
T2
0.5 second 0.5 second
Fig 3-1 .
PIC can generate square wave frequency with 5V amplitude as shown in Fig3-2.
The total time(T) for each cycle equal the sum of "on time" and "off time" of that
cycle. T=T1+T2=Ton+Toff=3ms+1ms =4ms. For frequency, f = 1/T = 1/4ms = 250
Hz.
Amplitude
(Voltage)
1stcycle
5V
3ms
1ms Toff
Ton
2ndcycle
0V
0 1 2 3 4 5 6 7 8 9 10
T1
T2
4 mili-sec
4 mili-sec
Fig 3-2.
Time
(mili-second)
YWT-44
So,we can hear that frequency by connecting with a speaker circuit as shown in
Fig3-3.
10F
capacitor
PIC
8 Ohm
0.2 Watt
speaker
Fig 3-3.
If we want to produce 1kHz frequency(f) (with 50% duty cycle) for 2 second by PIC
, we need to calculate the time(T) for one cycle and also need to know how many
cycles(number of cycles-NC) are required for 2 seconds.
To calculate T, T = 1/f = 1/1k = 1ms.
Duty cycle = (Ton/T) *100% , if duty cycle is 50%, Ton =Toff = T/2 = 1ms/2 = 0.5ms
= 500 s(micro-second).
For number of cycles (NC) for 2 seconds, NC = 2 second / T = 2sec/1msec = 2000
cycles.
To write a program, use 500 micro-second delay for Ton and Toff for one cycle
and need to produce 2000 cycles by looping as shown in Fig 3-4,Fig3-5 and
exp3_0.c.
Amplitude
(Voltage)
1st
cycle
2000 th
cycle
2nd
cycle
.5ms
.5ms
Ton Toff
Time-ms
(mili-second)
1ms
2ms
Fig 3-4
2000ms
(2 seconds)
YWT-45
10F
capacitor
PIC
RA3
8 Ohm
0.2 Watt
speaker
Fig 3-5 .
main()
{
int i;
TRISA.F3 = 0;
for (i=0;i<2000;i++)
{
PORTA.F3 = 1;
Delay_us(500);
PORTA.F3 = 0;
Delay_us(500);
}
}
Exp3_0.c
YWT-46
There are 2000 for loop, 1 mili-second x 2000 = 2000 mili-second = 2 seconds.
To calculate the frequency (f), (f=1/T ), f = 1/1 mili-second = 1000= 1 Kilo Hertz =
1KHz .So, this program produce 1KHz frequency for 2 seconds.
22pF
22pF
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10K Ohm
8 Ohm
0.2 Watt
speaker
10F
capacitor
+5V
Fig 3-6 . Complete circuit diagram for Example 3-0, 3-1, 3-4 and 3-5
YWT-47
You can run Example 3_0 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_0 on Project board with 5V power supply.
YWT-48
10F
capacitor
PIC
RA3
8 Ohm
0.2 Watt
speaker
main()
{
TRISA.F3 = 0;
While(1)
{
PORTA.F3 = 1;
Delay_us(1000);
PORTA.F3 = 0;
Delay_us(1000);
}
}
Fig 3-5 .
Exp3_1.c
Complete circuit for this example is shown previously in Fig 3-6 .
Explanation
This example is similar to example 3-0.
Example 3-0 use 500 micro-second delay to get frequency of 1 KHz. But this
example use 1000 microsecond to get 500 Hz.
Example 3-0 use for loop for limited times. But this example use while(1) loop for
unlimited times or the whole time until the program stop.
YWT-49
You can run Example 3_1 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_1 on Project board with 5V power supply.
YWT-50
Example 3-2 . 1 KHz sound will be produced by speaker during the time while
press "s1" push button.
+5V
10kO
10F
capacitor
RA3
RA0
8 Ohm
0.2 Watt
speaker
Fig 3-7 .
s1
main()
{
TRISA.F3 = 0;
TRISA.F0 = 1;
while(1)
{
while(PORTA.F0==0)
{
PORTA.F3 = 1;
Delay_us(500);
PORTA.F3 = 0;
Delay_us(500);
}
}
}
Exp3_2.c
Explanation
Declare RA3 pin as output by TRISA.F3=0; command and declare RA0 pin as
input by TRISA.F0=1; command.
Then, while(1) loop will do continuously until the program stop.
While you press s1 push button, RA0 will change to logic 0 and internal while
loop ( while(PORTA.F0) loop ) will do to produce 1 KHz sound from RA3 pin.
YWT-51
+5V
22pF
22pF
10K
Ohm
+5V
4MHz
Crystal
S1
18
17
RA1
RA0
16
15
14
13
OSC1
OSC2
VDD
RB7
12
RB6
11
10
RB5
RB4
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10K Ohm
8 Ohm
0.2 Watt
speaker
10F
capacitor
+5V
( with Oscilloscope)
YWT-52
You can run Example 3_2 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_2 on Project board with 5V power supply.
YWT-53
+5V
+5V
10kO
+5V
10kO
RA0
10kO
RA1
S1
RA2
S2
10F
capacitor
RA3
8 Ohm
0.2 Watt
speaker
Fig 3-9.
S3
main()
{
TRISA = 7;
while(1)
{
while(PORTA.F0==0)
{
PORTA.F3=1;
Delay_us(477);
PORTA.F3=0;
Delay_us(477);
}
while(PORTA.F1==0)
{
PORTA.F3=1;
Delay_us(425);
PORTA.F3=0;
Delay_us(425);
}
while(PORTA.F2==0)
{
PORTA.F3=1;
Delay_us(380);
PORTA.F3=0;
Delay_us(380);
}
}
}
Exp3_3.c
Explanation
Declare last 3 bits of PORTA register (RA0, RA1 and RA2) as input and other
PORTA pins as output by TRISA=7; command( 7in binary is 00000111).
Example 3-3 is similar to example 3-2.
YWT-54
Example 3-2 has one button in circuit and one while loop in while(1) loop to
produce one frequency while pressing that button.
But example 3-3 has three buttons in circuit and three while loop in while(1) loop
to produce three different frequencies while pressing each of three button.
+5V
10K
Ohm
22pF
22pF
+5V
4MHz
Crystal
+5V
S1
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
10K
Ohm
10K
Ohm
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10K Ohm
+5V
S3
8 Ohm
0.2 Watt
speaker
10F
capacitor
YWT-55
You can run Example 3_3 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_3 on Project board with 5V power supply.
YWT-56
10F
capacitor
PIC
RA3
8 Ohm
0.2 Watt
speaker
Fig 3-5.
Note
Sound
Frequency(Hz)
N_C()
Do
1047
N_D()
Ray
1175
N_E()
Mi
1319
N_F()
Fa
1397
N_G()
So
1568
N_A()
La
1760
N_B()
Ti
1976
N_C1()
Do(high)
2093
N_S()
no sound
Exp3_4.c
void N_C(void);
void N_D(void);
void N_E(void);
void N_F(void);
void N_G(void);
void N_A(void);
void N_B(void);
void N_C1(void);
void N_S(void);
void main()
{
TRISA.F3=0;
N_C();N_C();N_C();
N_D();N_D();N_D();
N_E();N_E();N_E();
N_F();N_F();N_F();
N_G();N_G();N_G();
N_A();N_A();N_A();
N_B();N_B();N_B();
N_C1();N_C1();N_C1();
}
void N_C(void)
{ int i;
for (i=0;i<150;i++)
{ PORTA.F3=1;
Delay_us(477);
PORTA.F3=0;
Delay_us(477);
}
}
void N_D(void)
{ int i;
for (i=0;i<168;i++)
{ PORTA.F3=1;
Delay_us(425);
PORTA.F3=0;
Delay_us(425);
}
}
void N_E(void)
{ int i;
for (i=0;i<189;i++)
{ PORTA.F3=1;
Delay_us(379);
PORTA.F3=0;
Delay_us(379);
}
}
void N_F(void)
{ int i;
for (i=0;i<200;i++)
{ PORTA.F3=1;
Delay_us(358);
PORTA.F3=0;
Delay_us(358);
}
}
void N_G(void)
{ int i;
for (i=0;i<225;i++)
{ PORTA.F3=1;
Delay_us(318);
PORTA.F3=0;
Delay_us(318);
}
}
void N_A(void)
{ int i;
for (i=0;i<252;i++)
{ PORTA.F3=1;
Delay_us(284);
PORTA.F3=0;
Delay_us(284);
}
}
void N_B(void)
{ int i;
for (i=0;i<282;i++)
{ PORTA.F3=1;
Delay_us(253);
PORTA.F3=0;
Delay_us(253);
}
}
void N_C1(void)
{ int i;
for (i=0;i<300;i++)
{ PORTA.F3=1;
Delay_us(239);
PORTA.F3=0;
Delay_us(239);
}
}
void N_S(void)
{ int i;
for (i=0;i<567;i++)
{ PORTA.F3=0;
Delay_us(126);
}
}
YWT-57
Explanation
This program uses 9 functions. These functions must be declare before main
program.
Void N_C(void) function produce the sound with 1047 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Do sound(Note C) of piano.
Void N_D(void) function produce the sound with 1175 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Ray (Note D)of piano.
Void N_E(void) function produce the sound with 1319 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Mi (Note E)of piano.
Void N_F(void) function produce the sound with 1397 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Fa (Note F)of piano.
Void N_G(void) function produce the sound with 1568 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with So (Note G)of piano.
Void N_A(void) function produce the sound with 1760 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with La (Note A)of piano.
Void N_B(void) function produce the sound with 1976 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Ti (Note B)of piano.
Void N_C1(void) function produce the sound with 2093 Hz frequency for 0.25
seconds at RA3 pin which is equivalent with Do(High) (Note C#)of piano.
Void N_S(void) function produce no sound( 0 Hz) for a very short period at RA3
pin. This function can be used as a break between two consecutive sound(notes).
The first void found in these functions means this function has no return value.
The last void found in these functions means that there is no need to use input
parameters to run that function.
When call these functions from main program, you can omit both of first void
word and last void word. For example, N_C(); , N_D(); , N_E(); , N_F(); , N_G(); ,
N_A(); , N_B(); , N_C1(); , N_S();
If long note of C take for 0.75 second, you can call N_C(); function 3 times
because it takes 0.25 second for N_C(); function 1 time. Eg - N_C(); N_C(); N_C();
If short note of C take for 0.5 second, you can call N_C(); function 2 times
because it takes 0.25 second for N_C(); function 1 time. Eg - N_C(); N_C();
YWT-58
You can run Example 3_4 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_4 on Project board with 5V power supply.
YWT-59
Example 3-5 - Producing Mya Nandar song using piano key notes.
10F
capacitor
PIC
RA3
8 Ohm
0.2 Watt
speaker
void N_C(void);
void N_D(void);
void N_E(void);
void N_F(void);
void N_G(void);
void N_A(void);
void N_B(void);
void N_C1(void);
void N_S(void);
void main()
{
TRISA.F3=0;
N_F();N_F();N_F(); N_D();N_D();N_D();
N_A();N_A();N_A(); N_F();N_F();
N_E();N_E(); N_D();N_D();
N_D();N_D(); N_C();N_C();
N_B();N_B(); N_A();N_A();
N_S();N_S();N_S(); N_C();N_C();
N_D();N_D(); N_A();N_A();
N_C();N_C(); N_A();N_A();
N_G();N_G(); N_F();N_F();N_F();
N_G();N_G();N_G(); N_A();N_A();N_A();
N_C();N_C();N_C(); N_S();N_S();N_S();
N_E();N_E(); N_D();N_D();
N_C();N_C(); N_A();N_A();
N_G();N_G(); N_F();N_F();
N_F();N_F(); N_A();N_A();
N_E();N_E(); N_E();N_E();
N_E();N_E(); N_G();N_G();
N_G();N_G(); N_C();N_C();
N_F();N_F();N_F();
}
void N_C(void)
{ int i;
for (i=0;i<150;i++)
{ PORTA.F3=1;
Delay_us(477);
PORTA.F3=0;
Delay_us(477);
}
}
void N_D(void)
{ int i;
for (i=0;i<168;i++)
{ PORTA.F3=1;
Delay_us(425);
PORTA.F3=0;
Delay_us(425);
}
}
void N_E(void)
{ int i;
for (i=0;i<189;i++)
{ PORTA.F3=1;
Delay_us(379);
PORTA.F3=0;
Delay_us(379);
}
}
void N_F(void)
{ int i;
for (i=0;i<200;i++)
{ PORTA.F3=1;
Delay_us(358);
PORTA.F3=0;
Delay_us(358);
}
}
void N_G(void)
{ int i;
for (i=0;i<225;i++)
{ PORTA.F3=1;
Delay_us(318);
PORTA.F3=0;
Delay_us(318);
}
}
void N_A(void)
{ int i;
for (i=0;i<252;i++)
{ PORTA.F3=1;
Delay_us(284);
PORTA.F3=0;
Delay_us(284);
}
}
void N_B(void)
{ int i;
for (i=0;i<282;i++)
{ PORTA.F3=1;
Delay_us(253);
PORTA.F3=0;
Delay_us(253);
}
}
void N_C1(void)
{ int i;
for (i=0;i<300;i++)
{ PORTA.F3=1;
Delay_us(239);
PORTA.F3=0;
Delay_us(239);
}
}
void N_S(void)
{ int i;
for (i=0;i<567;i++)
{ PORTA.F3=0;
Delay_us(126);
}
}
YWT-60
Explanation
Example 3-5 is similar to example 3-4. All functions and function declarations are
exactly the same. The difference is only in main program section. Both example
use RA3 pin as output(by TRISA.F0=3) and to connect to speaker via capacitor.
The main program section in Example 3-4 call functions to produce Do Ray
Mi Fa So La Ti Do(high) sound.
The main program section in Example 3-5 call functions to produce Mya Nandar
song.
You can run Example 3_5 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
You can run Example 3_5 on Project board with 5V power supply.
YWT-61
PIC
RA3
8 Ohm
0.2 Watt
speaker
RB0
RB4
330 Ohm
Red LED 1
RB1
330 Ohm
Red LED 5
RB5
330 Ohm
Red LED 2
330 Ohm
Red LED 3
RB2
330 Ohm
Red LED 6
330 Ohm
Red LED 7
RB6
RB3
RB7
330 Ohm
Red LED 4
Fig 3-11 .
330 Ohm
Red LED 8
YWT-62
}
void N_C(void)
// produce "Do" sound
{ int i;
PORTB.F0=1; // ON LED at RB0 pin
for (i=0;i<150;i++)
{ PORTA.F3=1;
Delay_us(477); //delay for 477 micro seconds
PORTA.F3=0;
Delay_us(477); }
PORTB.F0=0; // OFF LED at RB0 pin
}
void N_D(void)
// produce "Ray" sound
{ int i;
PORTB.F1=1; // ON LED at RB1 pin
for (i=0;i<168;i++)
{ PORTA.F3=1;
Delay_us(425);
PORTA.F3=0;
Delay_us(425); }
PORTB.F1=0; // OFF LED at RB1 pin
}
void N_E(void)
// produce "Mi" sound
{ int i;
PORTB.F2=1; // ON LED at RB2 pin
for (i=0;i<189;i++)
{ PORTA.F3=1;
Delay_us(379);
PORTA.F3=0;
Delay_us(379); }
PORTB.F2=0; // OFF LED at RB2 pin
}
void N_F(void)
// produce "Fa" sound
{ int i;
PORTB.F3=1; // ON LED at RB3 pin
for (i=0;i<200;i++)
{ PORTA.F3=1;
Delay_us(358);
PORTA.F3=0;
Delay_us(358); }
PORTB.F3=0; // FF LED at RB3 pin
}
void N_G(void)
// produce "So" sound
{ int i;
PORTB.F4=1; // ON LED at RB4 pin
for (i=0;i<225;i++)
{ PORTA.F3=1;
Delay_us(318);
PORTA.F3=0;
Delay_us(318); }
PORTB.F4=0; // OFF LED at RB4 pin
}
void N_A(void)
// produce "La" sound
{ int i;
PORTB.F5=1; // ON LED at RB5 pin
for (i=0;i<252;i++)
{ PORTA.F3=1;
Delay_us(284);
PORTA.F3=0;
Delay_us(284); }
PORTB.F5=0; // OFF LED at RB5 pin
}
void N_B(void)
// produce "Ti" sound
{ int i;
PORTB.F6=1; // ON LED at RB6 pin
for (i=0;i<282;i++)
{ PORTA.F3=1;
Delay_us(253);
PORTA.F3=0;
Delay_us(253); }
PORTB.F6=0; // OFF LED at RB6 pin
}
void N_C1(void)
// produce "Do(high)" sound
{ int i;
PORTB.F7=1; // ON LED at RB7 pin
for (i=0;i<300;i++)
{ PORTA.F3=1;
Delay_us(239);
PORTA.F3=0;
Delay_us(239); }
PORTB.F7=0; // OFF LED at RB7 pin
}
void N_S(void)
// make a break (or) no sound
{ int i;
for (i=0;i<567;i++)
{ PORTA.F3=0;
Delay_us(126); }
}
YWT-63
Explanation
This example combine example 3-4 and example 3-5 . And add some Delays and
modified N_C(), N_D(), N_E(), N_F(), N_G(), N_A(), N_B(), N_C1() functions to ON
corresponding LED at the beginning of the function and to OFF that LED at the
end of the function.
You can see comments to know the concept of lines in program. Comments are
used by programmers( start with // ) to note about something. You can write
comment by start with // and then follow any words as you like and these
comments will not take effect to the programs working sequences.
The purpose of comments written in Exp3_6.c are only to understand the
program and you can omit that comments when you write again Exp3_6.c in
mikroC to compile.
(Note - Real PIC Simulator version 1.1 has some sound error. Therefore, to run
sound simulations, Real PIC Simulator version 1.3 should be used.)
Video => RealPicSimulator_Exp3_6.mp4
RealPicSimulator1.3_RunExp3_6.mp4
Project file to open with Real PIC Simulator => Exp3_6.rpp
You can run Example 3_6 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
Image => IMG_0081.jpg (Red LED-330 Ohm resistor)
IMG_0111.jpg (color LED)
MG_0113.jpg (color LED)
IMG_0115.jpg (color LED)
Video => MVI_0088.avi (Red LED-330 Ohm resistor)
MVI_0119.avi (color LED)
YWT-64
YWT-65
Example 3-7 is the binary up / down counter .When you press S1 push button,
current binary value will increase by 1 and Do sound will be produced from
speaker connected with RA3 via 10uF capacitor. The resulted binary value will be
shown with 8 LED connected to RB0 to RB7.When you press S2 push button,
current binary value will increase by 1 and Mi sound will be produced from
speaker connected with RA3 via 10uF capacitor. The resulted binary value will be
shown with 8 LED connected to RB0 to RB7.
void N_C(void);
void N_E(void);
+5V
+5V
S1
(Up)
S2
(Down)
RA1
RA0
10k
10k
10F capacitor
RA3
8 Ohm
0.2 Watt
speaker
RB0
RB4
330 Ohm
Red LED 1
RB1
330 Ohm
Red LED 5
RB5
330 Ohm
Red LED 2
330 Ohm
Red LED 3
RB2
330 Ohm
Red LED 6
330 Ohm
Red LED 7
RB6
RB3
RB7
330 Ohm
Red LED 4
Fig 3-12 .
330 Ohm
Red LED 8
void main()
{ int i=0;
TRISA = 3;
TRISB = 0;
PORTA.F0=0;
PORTA.F1=0;
PORTB=0;
while(1)
{ PORTB=i ;
if (PORTA.F0==1)
{ i++;
if (i>255) i=255;
N_C();
}
if (PORTA.F1==1)
{ i--;
if (i<0) i=0;
N_E();
}
Delay_ms(100);
}
}
void N_C(void)
{ int i;
for (i=0;i<150;i++)
{ PORTA.F3=1;
Delay_us(477);
PORTA.F3=0;
Delay_us(477);
}
}
void N_E(void)
{ int i;
for (i=0;i<189;i++)
{ PORTA.F3=1;
Delay_us(379);
PORTA.F3=0;
Delay_us(379);
}
}
YWT-66
+5V
S1
(Up)
22pF
22pF
330
Ohm
Red LED 8
330
Ohm
Red LED 7
330
Ohm
Red LED 6
330
Ohm
Red LED 5
330
Ohm
Red LED 4
330
Ohm
Red LED 3
+5V
4MHz
Crystal
+5V
10K
Ohm
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
S2
(Down)
10K
Ohm
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
4.7K Ohm
(or)
10k Ohm
8 Ohm
0.2 Watt
speaker
10F
capacitor
+5V
330
Ohm
Red LED 2
330
Ohm
Red LED 1
(Note - Real PIC Simulator version 1.1 has some sound error. Therefore, to run
sound simulations, Real PIC Simulator version 1.3 should be used.)
YWT-67
You can run Example 3_7 on Project board with 9V battery and 7805 IC. 7805 IC is
used to convert 9V from 9V battery to 5V to supply PIC circuit.
Image => IMG_0090.jpg (Red LED-330 Ohm resistor)
IMG_0092.jpg (Red LED-330 Ohm resistor)
IMG_0098.jpg (color LED)
IMG_0104.jpg (color LED)
Video => MVI_0094.avi (Red LED-330 Ohm resistor)
MVI_0107.avi (color LED)
YWT-68
+5V in/out
Screw
connector
330
+5V
Gnd
RGB
LED
22pF
150
Pink
LED
100
Violet
LED
100
Blue
LED
150
Green
LED
+5V
4MHz
Crystal
18
17
16
15
14
13
12
11
10
RA1
RA0
OSC1
OSC2
VDD
RB7
RB6
RB5
RB4
+5V
USB connector
for 5V power
RA2
RA3
RA4
MCLR
VSS
RB0
RB1
RB2
RB3
connector
150 Yellow
LED
10F
capacitor
RA1
RA2
RA3
RA4
10k
150 Orange
LED
10k
Ground
Jumper
4.7K
+5V
connector
connector
150
8
speaker
+5V
S2
S1
Down
Up
Red
LED