Cs3691-Embedded & Iot Notes All Units
Cs3691-Embedded & Iot Notes All Units
3 0 2 4
COURSE OBJECTIVES:
To learn the internal architecture and programming of an embedded processor.
To introduce interfacing I/O devices to the processor.
To introduce the evolution of the Internet of Things (IoT).
To build a small low-cost embedded and IoT system using Arduino/Raspberry Pi/ open platform.
To apply the concept of Internet of Things in real world scenario.
TEXTBOOKS :
1. Muhammed Ali Mazidi, Janice Gillispie Mazidi, Rolin D. McKinlay, “The 8051 Microcontroller
and Embedded Systems”, Pearson Education, Second Edition, 2014
2. Robert Barton, Patrick Grossetete, David Hanes, Jerome Henry, Gonzalo Salgueiro, “IoT
Fundamentals: Networking Technologies, Protocols, and Use Cases for the Internet of Things”,
CISCO Press, 2017.
REFERENCES :
Features:
4K bytes internal ROM
128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Two 16-bit timers/counters
One serial interface
only 1 On chip oscillator (external crystal)
6 interrupt sources (2 external , 3 internal, Reset)
64K external code (program) memory(only read)PSEN
64K external data memory(can be read and write) by RD,WR
Code memory is selectable by EA (internal or external)
External memory can be interfaced when data and code storage capacity
exceed size of the internal memory.
ALU - Arithmetic Logical Unit: This unit is used for the arithmetic calculations.
A-Accumulator: This register is used for arithmetic operations. This is also bit addressable and8
bit register.
B-Register: This register is used in only two instructions MUL AB and DIV AB. This is also
bitaddressable and 8 bit register.
PC-Program Counter:
Points to the address of next instruction to be executed from ROM
It is 16 bit register means the 8051 can access program address from 0000H to FFFFH. A
total of 64KB of code.
Initially PC has 0000H
PC is incremented after each instruction.
Flag Bits and PSW Register:
→ Used to indicate the Arithmetic condition of Accumulator (ACC).
→ Flag register in 8051 is called as program status word (PSW). This special function register
PSW is also bit addressable and 8 bit wide means each bit can be set or reset independently.
PIN Details
• The 8051 has an on-chip oscillator but requires an external clock to run it
A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18)
• RESET pin is an input and is active high (normally low)
• Upon applying a high pulse to this pin, the microcontroller will reset and terminate
allactivities
• EA‟,“external access’’, is an input pin and must be connected to Vcc or GND
• Normally EA pin is connected to Vcc
• EA pin must be connected toGNDto indicate that the code or data isstored externally.
• PSEN,“program store enable’’, is an output pin
• This pin is connected to theOEpin of the external memory.
• For External Code Memory, PSEN‟ = 0
• For External Data Memory, PSEN‟ = 1
• ALE pin is used for demultiplexing the address and data.
• The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins.
• Port 0 is also designated as AD0-AD7.
• When connecting an 8051 to an external memory, port 0 provides both address and data.
• The 8051 multiplexes address and data through port 0 to save pins.
• ALE indicates if P0 has address or data.
• When ALE=0, it provides data D0-D7
• When ALE=1, it has address A0-A7
• Port 2 must be used along with P0 to provide the 16-bit address for the external memory.
• P0 provides the lower 8 bits via A0 – A7.
• P2 is used for the upper 8 bits of the 16-bit address, designated as A8 – A15, and it cannot
be used for I/O.
PORT 0
Port 0 pins may serve as inputs, outputs, or, when used together, as a bi-directional low
order address and data bus for external memory.
When a pin is to be used as an input, a „1‟ must be written to the corresponding port 0 latch
by the program, thus turning both of the output transistors off,
When port 0 is used as an address bus to external memory, internal control signals
switch the address lines to the gates of the Field Effect Transistors (FETs).
PORT 1
Port 1 pins have no dual functions.
When a pin is to be used as an input, a „1‟ must be written to the corresponding port 1 latch
by the program, thus turning both of the output transistors off.
To aid in speeding up switching times when the pin is used as an output. the internal FET
pull up has another FET in parallel with it.
PORT 2
Port 2 may be used as an input/output port similar in operation to port 1.
The alternate use of port 2 is to supply a high-order address byte in conjunction with
the port 0 low-order byte to address external memory.
Port 2 pins are momentarily changed by the address control signals when supplying the
high byte of a 16- bit address.
PORT 3
Port 3 is an input/output port similar to port 1
The input and output functions can be programmed under the control of the P3 latches or
under the control of various other special function registers.
The port 3 alternate uses are shown in the following table
ADDRESSING MODES OF 8051
An "addressing mode" refers to the way of specifying operand in the instruction. In
summary, the addressing modes are as follows, with an example of each:
This instruction uses Immediate Addressing because the Accumulator will be loaded with the
value that immediately follows; in this case 20 (hexadecimal). Immediate addressing is very fast
since the value to be loaded is included in the instruction. However, since the value to be loaded
is fixed at compile-time it is not very flexible.
Direct Addressing: Direct addressing is so-named because the value to be stored in memory
is obtained by directly retrieving it from another memory location. For example: MOV A,30h
This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the
Accumulator. Direct addressing is generally fast since, although the value to be loaded is not
included in the instruction, it is quickly accessible since it is stored in the 8051s Internal RAM. It
is also much more flexible than Immediate Addressing since the value to be loaded is whatever is
found at the given address--which may be variable. Also, it is important to note that when using
direct addressing any instruction which refers to an address between 00h and 7Fh is referring to
Internal Memory. Any instruction which refers to an address between 80h and FFh is referring to
the SFR control registers that control the 8051 microcontroller itself.
Indirect Addressing: Indirect addressing is a very powerful addressing mode which in many
cases provides an exceptional level of flexibility. Indirect addressing is also the only way to access
the extra 128 bytes of Internal RAM found on an 8052. Indirect addressing appears as follows:
MOV A,@R0
This instruction causes the 8051 to analyze the value of the R0 register. The 8051 will then load
the accumulator with the value from Internal RAM which is found at the address indicated by R0.
For example, lets say R0 holds the value 40h and Internal RAM address 40h holds the value 67h.
External Indirect
External memory can also be accessed using a form of indirect addressing.
MOVX A,@DPTR and MOVX @DPTR,A
Both commands utilize DPTR. In these instructions, DPTR must first be loaded with the address
of external memory. Once DPTR holds the correct external memory address, the first command
will move the contents of that external memory address into the Accumulator. The second
command will do the opposite: it will allow to write the value of the Accumulator to the external
memory address pointed to by DPTR.
INSTRUCTION SET OF 8051 MICROCONTROLLER
MOVC Moves the code byte relative to the DPTR to the accumulator
A,@A+DPTR (address=A+DPTR) 1 3
Moves the code byte relative to the PC to the accumulator
MOVC A,@A+PC (address=A+PC) 1 3
MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator 1 3-10
MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator 1 3-10
MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address) 1 4-11
MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address) 1 4-11
PUSH direct Pushes the direct byte onto the stack 2 4
POP direct Pops the direct byte from the stack 2 3
XCH A,Rn Exchanges the register with the accumulator 1 2
XCH A,direct Exchanges the direct byte with the accumulator 2 3
XCH A,@Ri Exchanges the indirect RAM with the accumulator 1 3
XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the accumulator 1 3
ARITHMETIC INSTRUCTIONS
Arithmetic instructions perform several basic operations such as addition, subtraction,
division, multiplication etc. After execution, the result is stored in the first operand. For
example:
ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.
Mnemonic Description
ADD A,Rn Adds the register to the accumulator
ADD A,direct Adds the direct byte to the accumulator
ADD A,@Ri Adds the indirect RAM to the accumulator
ADD A,#data Adds the immediate data to the accumulator
ADDC A,Rn Adds the register to the accumulator with a carry flag
ADDC A,direct Adds the direct byte to the accumulator with a carry flag
ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag
ADDC A,#data Adds the immediate data to the accumulator with a carry flag
SUBB A,Rn Subtracts the register from the accumulator with a borrow
SUBB A,direct Subtracts the direct byte from the accumulator with a borrow
SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow
SUBB A,#data Subtracts the immediate data from the accumulator with a borrow
INC A Increments the accumulator by 1
INC Rn Increments the register by 1
INC direct Increments the direct byte by 1
INC @Ri Increments the indirect RAM by 1
DEC A Decrements the accumulator by 1
DEC Rn Decrements the register by 1
DEC direct Decrements the direct byte by 1
DEC @Ri Decrements the indirect RAM by 1
INC DPTR Increments the Data Pointer by 1
MUL AB Multiplies A and B
DIV AB Divides A by B
DA A Decimal adjustment of the accumulator according to BCD code
LOGIC INSTRUCTIONS:
Logic instructions perform logic operations upon corresponding bits of two registers.
After execution, the result is stored in the first operand.
Mnemonic Description
ANL A,Rn AND register to accumulator
ANL A,direct AND direct byte to accumulator
ANL A,@Ri AND indirect RAM to accumulator
ANL A,#data AND immediate data to accumulator
ANL direct,A AND accumulator to direct byte
ANL direct,#data AND immediae data to direct register
ORL A,Rn OR register to accumulator
ORL A,direct OR direct byte to accumulator
ORL A,@Ri OR indirect RAM to accumulator
ORL direct,A OR accumulator to direct byte
ORL direct,#data OR immediate data to direct byte
XRL A,Rn Exclusive OR register to accumulator
XRL A,direct Exclusive OR direct byte to accumulator
XRL A,@Ri Exclusive OR indirect RAM to accumulator
XRL A,#data Exclusive OR immediate data to accumulator
XRL direct,A Exclusive OR accumulator to direct byte
XRL direct,#data Exclusive OR immediate data to direct byte
CLR A Clears the accumulator
CPL A Complements the accumulator (1=0, 0=1)
SWAP A Swaps nibbles within the accumulator
RL A Rotates bits in the accumulator left
RLC A Rotates bits in the accumulator left through carry
RR A Rotates bits in the accumulator right
RRC A Rotates bits in the accumulator right through carry
EXAMPLE:
Before execution: A= C2h (11000010 Bin.)
After execution: A=85h (10000101 Bin.)
RLC A - Rotates the accumulator one bit left through the carry flag
Description: All eight bits in the accumulator and carry flag are rotated one bit left. After
this operation, the bit 7 is rotated into the carry flag position and the carry flag is rotated into the bit
0 position.
Syntax: RLC A;
Byte: 1 (instruction code); STATUS register flags: C; EXAMPLE:
Before execution: A= C2h (11000010 Bin.) C=0
After execution: A= 85h (10000100 Bin.) C=1
Syntax: RRC A;
Byte: 1 (instruction code); STATUS register flags: C; EXAMPLE:
Before execution: A= C2h (11000010 Bin.) C=0
After execution: A= 61h (01100001 Bin.) C=0
The ACALL instruction is logically similar to the LCALL but has a limited address range
similar to the AJMP instruction. CALL is a generic call instruction supported by many 8051
assemblers. The assembler will decide which type of call instruction, LCALL or ACALL, to
use so as to choose the most efficient instruction.
Mnemonic Description
ACALL addr11 Absolute subroutine call
LCALL addr16 Long subroutine call
RET Returns from subroutine
RETI Returns from interrupt subroutine
AJMP addr11 Absolute jump
LJMP addr16 Long jump
Short jump (from –128 to +127 locations relative to the following instruction)
SJMP rel
JC rel Jump if carry flag is set. Short jump.
JNC rel Jump if carry flag is not set. Short jump.
JB bit,rel Jump if direct bit is set. Short jump.
JBC bit,rel Jump if direct bit is set and clears bit. Short jump.
JMP @A+DPTR Jump indirect relative to the DPTR
JZ rel Jump if the accumulator is zero. Short jump.
JNZ rel Jump if the accumulator is not zero. Short jump.
Compares direct byte to the accumulator and jumps if not equal. Short jump.
CJNE A,direct,rel
Compares immediate data to the accumulator and jumps if not equal. Short jump.
CJNE A,#data,rel
CJNE Rn,#data,rel Compares immediate data to the register and jumps if not equal. Short jump.
CJNE Compares immediate data to indirect register and jumps if not equal. Short jump.
@Ri,#data,rel
DJNZ Rn,rel Decrements register and jumps if not 0. Short jump.
DJNZ Rx,rel Decrements direct byte and jump if not 0. Short jump.
NOP No operation
PROGRAMS
8 Bit Addition (Immediate Addressing)
LABEL MNEMONIC OPERAND COMMENTS
CLR C Clear CY Flag
MOV A, data1 Get the data1 in Accumulator
ADDC A, # data 2 Add the data1 with data2
MOV DPTR, #4500H Initialize the memory location
MOVX @ DPTR, A Store the result in memory location
L1 SJMP L1 Stop the program
8 Bit Multiplication
LABEL MNEMONIC OPERAND COMMENTS
MOV A ,#data1 Store data1 in accumulator
MOV B, #data2 Store data2 in B reg
MUL A,B Multiply both
MOV DPTR, # Initialize memory location
4500H
MOVX @ DPTR, A Store lower order result
INC DPTR Go to next memory location
MOV A,B Store higher order result
MOV @ DPTR, A
STOP SJMP STOP Stop
8 Bit Division
LABEL MNEMONIC OPERAND COMMENTS
MOV A, # data1 Store data1 in accumulator
MOV B, # data2 Store data2 in B reg
DIV A,B Divide
MOV DPTR, # 4500H Initialize memory location
MOVX @ DPTR, A Store remainder
INC DPTR Go to next memory location
MOV A,B Store quotient
MOV @ DPTR, A
STOP SJMP STOP Stop
Timer Classification
The 8051 has two timers/counters. They can be used either
as timers to generate a time delay or as counters to count
events happening outside the microcontroller. The 8051 has
two timers:
• Timer 0,
• Timer 1.
GATE
• Gating control when set. Timer/counter is enable only while the INTx pin is high and
the TRx control pin is set. When cleared, the timer is enabled whenever the TRx
control bit is set.
Timers of 8051 do starting and stopping by either software or hardware control.
In using software to start and stop the timer where GATE=0
The start and stop of the timer are controlled by way of software by the
TR(timer start) bits TR0 and TR1
To start Timer, TR0 or TR1 must be high. or To stop Timer, TR0 or TR1 must be low.
These instructions start and stop the timers as long as GATE=0 in the TMOD register
The hardware way of starting and stopping the timer by an external source is
achieved by making GATE=1 in the TMOD register
TMOD Register
C/T
Timer or counter selected Cleared for timer operation (input from internal
system clock). Set for counter operation (input from Tx input pin).
If C/T = 0, it is used as a timer for time delay generation. The clock source for
the time delay is the crystal frequency of the 8051.
If C/T = 1, it is used as a counter for event counters to count events
happening outside the microcontroller
TMOD Register
TCON Register
Timers – Mode of Operations
Timer 0
Timer 0 – Mode 0
Timer 0 – Mode 1
Timer 0 – Mode 2
Timer 0 – Mode 3
Timer 1
Timer 1 – Mode 0
Timer 1 – Mode 1
Timer 1 – Mode 2
Interrupts
Interrupts
Interrupts
6 Interrupts in 8051
6 Interrupts in 8051
IE Register
Interrupt Priority
Interrupt Priority Register
Serial Interface
The serial port of 8051 is full duplex, i.e., it can transmit
and receive simultaneously.
The register SBUF is used to hold the data. The special
function register SBUF is physically two registers. One is,
write-only and is used to hold data to be transmitted out
of the 8051 via TXD.
The other is, read-only and holds the received data from
external sources via RXD. Both mutually exclusive
registers have the same address 099H.
Serial Interface
8051 Serial Port
SBUF Register
SCON Register
8051 Serial Port – Mode 0
8051 Serial Port – Mode 1
8051 Serial Port – Mode 2
8051 Serial Port – Mode 3
UNIT - 2 EMBEDDED C PROGRAMMING
Interfacing a Microcontroller to Keyboard
When you press a key on your computer, you are activating a switch. There are
many different ways of making these switches. An overview of the construction and
operation of some of the most common types.
Mechanical key switches: In mechanical-switch keys, two pieces of metal are
pushed together when you press the key. The actual switch elements are often made of a
phosphor-bronze alloy with gold platting on the contact areas. The key switch usually
contains a spring to return the key to the nonpressed position and perhaps a small piece of
foam to help damp out bouncing.
Some mechanical key switches now consist of a molded silicon dome with a small
piece of conductive rubber foam short two trace on the printed-circuit board to produce the
key pressed signal.
Mechanical switches are relatively inexpensive but they have several disadvantages.
First, they suffer from contact bounce. A pressed key may make and break contact several
times before it makes solid contact.
Second, the contacts may become oxidized or dirty with age so they no longer make
a dependable connection.
Higher- quality mechanical switches typically have a rated life time of about 1
million keystrokes. The silicone dome type typically last 25 million keystrokes.
Membrane key switches: These switches are really a special type of mechanical
switches. They consist of a three-layer plastic or rubber sandwich.
The top layer has a conductive line of silver ink running under each key position.
The bottom layer has a conductive line of silver ink running under each column of keys.
Example 6.3
Rate-monotonic scheduling
Here is a simple set of processes and their characteristics.
P1 1 4
P2 2 6
P3 3 12
Applying the principles of RMA, we give P1 the highest priority, P2 the middle priority,
and P3 the lowest priority. To understand all the interactions between the periods, we need to
construct a time line equal in length to hyperperiod, which is 12 in this case.
P3
P2
P1
0 2 4 6 8 10 12
Time
All three periods start at time zero. P1’s data arrive first. Since P1 is the highest-priority
process, it can start to execute immediately. After one time unit, P1 finishes and goes out
of the ready state until the start of its next period. At time 1, P2 starts executing as the
highest-priority ready process. At time 3, P2 finishes and P3 starts executing. P1’s next iteration
starts at time 4, at which point it interrupts P3. P3 gets one more time unit of execution between
the second iterations of P1 and P2, but P3 does not get to finish until after the third iteration
of P1.
Consider the following different set of execution times for these processes, keeping the
same deadlines.
P1 2 4
P2 3 6
P3 3 12
In this case, we can show that there is no feasible assignment of priorities that guarantees
scheduling. Even though each process alone has an execution time significantly less than its
period, combinations of processes can require more than 100% of the available CPU cycles.
For example, during one 12 time-unit interval, we must execute P1 three times, requiring
6 units of CPU time; P2 twice, costing 6 units of CPU time; and P3 one time, requiring 3 units
of CPU time. The total of 6 + 6 + 3 = 15 units of CPU time is more than the 12 time units
available, clearly exceeding the available CPU capacity.
Liu and Layland [Liu73] proved that the RMA priority assignment is optimal
using critical-instant analysis. We define the response time of a process as the
time at which the process finishes. The critical instant for a process is defined
as the instant during execution at which the task has the largest response time. It
is easy to prove that the critical instant for any process P, under the RMA model,
occurs when it is ready and all higher-priority processes are also ready—if we
change any higher-priority process to waiting, then P’s response time can only go
down.
We can use critical-instant analysis to determine whether there is any feasible
schedule for the system. In the case of the second set of execution times in
Example 6.3,there was no feasible schedule. Critical-instant analysis also implies that
priorities should be assigned in order of periods. Let the periods and computation
times of two processes P1 and P2 be 1 , 2 and T1 , T2 , with 1 < 2 . We can
generalize the result of Example 6.3 to show the total CPU requirements for the
two processes in two cases. In the first case, let P1 have the higher priority. In the
worst case we then execute P2 once during its period and as many iterations of P1
as fit in the same interval. Since there are 2 /1 iterations of P1 during a single
period of P2 , the required constraint on CPU time, ignoring context switching
overhead, is
2
T1 T2 2 . (6.4)
1
If, on the other hand, we give higher priority to P2 , then critical-instant analysis
tells us that we must execute all of P2 and all of P1 in one of P1 ’s periods in the
worst case:
T1 T2 1 . (6.5)
There are cases where the first relationship can be satisfied and the second
cannot, but there are no cases where the second relationship can be satisfied and
the first cannot. We can inductively show that the process with the shorter period
should always be given higher priority for process sets of arbitrary size. It is also
possible to prove that RMS always provides a feasible schedule if such a schedule
exists.
The bad news is that,although RMS is the optimal static-priority schedule,it does
not always allow the system to use 100% of the available CPU cycles. In the RMS
framework, the total CPU utilization for a set of n tasks is
n
Ti
U . (6.6)
i
i1
The fraction Ti /i is the fraction of time that the CPU spends executing task i.
It is possible to show that for a set of two tasks under RMS scheduling, the CPU
utilization U will be no greater than 2(21/2 1) ∼ 0.83. In other words, the CPU
will be idle at least 17% of the time. This idle time is due to the fact that priorities
are assigned statically; we see in the next section that more aggressive scheduling
policies can improve CPU utilization. When there are m tasks with fixed priorities,
the maximum processor utilization is
U m(21/m 1). (6.7)
FIGURE 6.12
C code for rate-monotonic scheduling.
Example 6.4
Earliest-deadline-first scheduling
Consider the following processes:
P1 1 3
P2 1 4
P3 2 5
The hyperperiod is 60. In order to be able to see the entire period, we write it as a table:
Time Running process Deadlines
0 P1
1 P2
2 P3 P1
3 P3 P2
4 P1 P3
5 P2 P1
6 P1
7 P3 P2
8 P3 P1
9 P1 P3
10 P2
11 P3 P1, P2
12 P1
13 P3
14 P2 P1, P3
15 P1 P2
16 P2
17 P3 P1
18 P1
19 P3 P2, P3
20 P2 P1
21 P1
22 P3
23 P3 P1, P2
24 P1 P3
25 P2
26 P3 P1
27 P1 P2
28 P3
29 P2 P1, P3
30 idle
31 P1 P2
32 P3 P1
33 P3
34 P1 P3
35 P2 P1, P2
36 P1
37 P2
38 P3 P1
39 P3 P2, P3
40 P1
(Continued )
Time Running process Deadlines
41 P2 P1
42 P1
43 P3 P2
44 P3 P1, P3
45 P1
46 P2
47 P3 P1, P2
48 P3
49 P1 P3
50 P2 P1
51 P1 P2
52 P3
53 P3 P1
54 P2 P3
55 P1 P2
56 P2 P1
57 P1
58 P3
59 P3 P1, P2, P3
There is one time slot left at t 30, giving a CPU utilization of 59/60.
Liu and Layland showed that EDF can achieve 100% utilization. A feasible sched-
ule exists if the CPU utilization (calculated in the same way as for RMA) is 1. They
also showed that when an EDF system is overloaded and misses a deadline, it will
run at 100% capacity for a time before the deadline is missed.
The implementation of EDF is more complex than the RMS code. Figure 6.13
outlines one way to implement EDF. The major problem is keeping the processes
sorted by time to deadline—since the times to deadlines for the processes change
during execution, we cannot presort the processes into an array, as we could for
RMS. To avoid resorting the entire set of records at every change, we can build a
binary tree to keep the sorted records and incrementally update the sort. At the end
of each period,we can move the record to its new place in the sorted list by deleting
it from the tree and then adding it back to the tree using standard tree manipulation
techniques. We must update process priorities by traversing them in sorted order,
so the incremental sorting routines must also update the linked list pointers that let
us traverse the records in deadline order. (The linked list lets us avoid traversing the
tree to go from one node to another,which would require more time.) After putting
in the effort to building the sorted list of records, selecting the next executing
process is done in a manner similar to that of RMS. However, the dynamic sorting
adds complexity to the entire scheduling process. Each update of the sorted list
Deadline_tree
... ...
Activation_record Activation_record
Data structure
/* linked list, sorted by deadline */
Activation_record *processes;
/* data structure for sorting processes */
Deadline_tree *deadlines;
FIGURE 6.13
C code for earliest-deadline-first scheduling.
requires O(log n) steps. The EDF code is also significantly more complex than the
RMS code.
Examples:
Priority-based scheduling
Preemptive Scheduling:
Preemptive scheduling is used when a process switches from the running
state to the ready state or from the waiting state to the ready state. The
resources (mainly CPU cycles) are allocated to the process for a limited
amount of time and then taken away, and the process is again placed back in
the ready queue if that process still has CPU burst time remaining. That
process stays in the ready queue till it gets its next chance to execute.
Pot-Fading Led:
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(10, OUTPUT);
pinMode(A0, INPUT);
[Link](9600);
}
void loop()
{
int sensorValue = analogRead(A0);
[Link](sensorValue);
int brightness = map(sensorValue, 0, 1023, 0, 255);
analogWrite(10, brightness);
delay(50);
}
To Control Servo Motor:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0;
void setup() {
[Link](9);
}
void loop() {
/* goes from 0 degrees to 180 degrees in steps of 1 degree tell servo to go to position in
variable 'pos' waits 15ms for the servo to reach the position */
for (pos = 0; pos <= 180; pos += 1) {
[Link](pos);
delay(15);
}
/* goes from 180 degrees to 0 degrees tell servo to go to position in variable 'pos' waits
15ms for the servo to reach the position */
for (pos = 180; pos >= 0; pos -= 1)
{
[Link](pos);
delay(15);
}
}
UNIT 4
IOT COMMUNICATION
AND
OPEN PLATFORMS
IoT Communication Protocols
Explain in detail about BLUETOOTH.
Nov/Dec 2011/April/May 2011/ April/May 2013 /May/June 2014/Nov/Dec 2017
It is a wireless LAN technology designed to connect devices of different functions such as
telephones, computers, mobiles or cell phones, cameras and printers so [Link] LAN is an adhoc
network, which means that the network is formed spontaneously find each other and make a network
called piconet.
Piconet
Scattered Net
i) Piconet
It is a small net. It has up to 8 stations, one of which is called the primary and rest is [Link]
communication between these two is one to one or one to more. The 8 stations is parked state and
synchronized with primary.
Scattered Net
Bluetooth devices:
It has a built in short range radio transmitter. The current data rate is 1mbps with 2.4 GHz
bandwidth.
Bluetooth layers
Radio layer: It is roughly equivalent to physical layer. Bluetooth are low power have a range of 10
meters.
Band: Bluetooth uses a 2.4 GHz band divided into 79 channels of 1 MHz each. Bluetooth uses FHSS
(Frequency Flopping Spread Spectrum Technique) and to transmit bits to a signal a Bluetooth uses the
FSK is called Gaussian FSK (GFSK).
Base Band Layer:It is roughly equivalent to the MAC sub layer in LAN. The access method is
TDMA. The communication each other that is primary & secondary is using time slots.
Single Secondary Communication: If the piconet has only one secondary, the TDMA operation is
very simple. The time is divided into slots of 625 µsec. The primary & secondary communication is
half duplex mode.
Multiple – Secondary Communication:The process is little more, if there is more than one secondary
in the piconet.
Physical link:
There are 2 types of links can be carried between primary & secondary.
It is used when avoiding latency (delay in data delivery) and is more important than
integrity (error free delivery).
Access code: It is an identifier of the primary to distinguish the frames of one piconet from another.
Header: Address: It consist of source & destination information (address 3 bit field)