EMBEDDED SYSTEMS 5

850 views
768 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
850
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

EMBEDDED SYSTEMS 5

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

×