EMBEDDED SYSTEMS 5
description
Transcript of EMBEDDED SYSTEMS 5
I/O ProgrammingI/O Programming4 ports for I/o Programming
◦Port 0 0x80◦Port 1 0x90◦Port 2 0xA0◦Port 3 0xB0
Secret of Port 0Secret of Port 0Port 0 has no pull up resistors Reason?
◦Due to the purpose of Port 0 as data and address holder , it cannot have a resistor in the output pins.
◦By directly giving the supply of 5 v to the port 0 will damage the internal transistor eventually.
Solution :◦By connecting external pull up resistor in
a range of 1K to 10K ohms , the damage to the internal transistor can be avoided.
Try to Avoid Port 3Try to Avoid Port 3Port 3 is also called as multifunctional
port.It is used for serial communication,
timer, external interrupt, chip read and write.
Therefore by using port 3 in a situation under which a serial communication or connecting an external memory which will cause loss of data or misbehavior in the output.
Also the timer and interrupts are very sensitive to the crystal frequency.
Remaining for I/O Remaining for I/O programmingprogrammingThe remaining for I/O programming
are Port 1 and Port 2 only.
Port 1 is a simple bidirectional Port
Port 2 is also a bidirectional with MSB of 16 bit address
Remember that port 2 is in reverse order while looking aerially
C programming of I/OsC programming of I/OsKey word for accessing I/Os
sbit a single bit ---------| sfr eight bit ____
|----- for accessing I/O directly bit a single bit-----|----| sfr 16 16
bit-----------|-----------for acessing I/O indirectly
Giving to Ports Giving to Ports & &Getting from the PortsGetting from the Ports
You can set a particular port with the help of the keyword
“sbit” Eg.,
sbit my_key =P1^1;Explanation: my_key is the user defined variable which can be used to get or send data to 2nd PIN of Port 1.^ symbol is used to mention a particular PIN any port
Use of Use of bitbit“bit” is another single bit keyword
which is used to change the value for the variable which is assigned by the sbit keyword.
Rather we can simply use it for “Boolean operation”.
Eg., bit garbage;
garbage =1; while(1) { garbage = ~garbage; my_key = garbage }Explanation: garbage is a user defined variable
which can only be used as either ‘0’ or ‘1’
Sfr made for??Sfr made for??“sfr” is an eight bit keyword, which allows
user to set a 8-bit value.Most of the registers in uC are 8-bit registers.Therefore it is easy to use all 8-bit register
using the “sfr” keyword.◦ Eg., sfr myport=0x80;
Explanation: Here myport is a user defined variable which is assigned to get or send value through PORT 0 (since port 0 is located in 0x80 address).
This is not only for ports, but also all register(TCON, SBUF, PCON, etc.,) can be assessed like this.
What about 16-bit What about 16-bit registers???registers???Still there are some registers
which have 16-bit .Therefore to access those 16-bit
registers, sfr16 has to be used.The only 16-bit register which
can be often used is DataPoinTeR (DPTR)
sfr16 can be used to assign that DPTR register.
Delay is the main Delay is the main concept..concept..After the infinite loop concept, Delay is another
important thing in the embedded system.There are different type of delays available in
microcontroller
By using the I/O concept delay can be produced.
Basic of delay is no operation for a particular period.
Here we providing that concept via programming
Therefore we can call this kind of delays as “software delays”
Simple delay programSimple delay program
int i,j;for(i=0;i<250;i++){
for(j=0;j<1275;j++){
;}
}This will generate approximately 1 sec delay. Software delays are only approximate figures.
A simple I/O programmingA simple I/O programming#include<reg51.h>sbit book = P1^2; //port 1 – 3rd pinsfr select =P0; //port 0void main(){book=1; // as an inputbit name =1; // single bit declarationwhile(1){if(book==1) // condition check in port 1 – 3rd pin{book=~name; //changing the value for book Select=0x55; //sending the output to port 0 }}}