I - o Programming in 8051 C
I - o Programming in 8051 C
1 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
Subscribe
what-when-how
In Depth Tutorials and Information
Example 7-9
LEDs are connected to bits PI and P2. Write an 8051 C program that shows the count from 0 to FFH (0000 0000
to 1111 1111 in binary) on the LEDs.
Solution:
Example 7-10
Write an 8051 C program to get a byte of data from PI, wait 1/2 second, and then send it to P2.
Solution:
06-03-2015 18:09
2 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
Example 7-11
Write an 8051 C program to get a byte of data from PO. If it is less than 100, send it to
PI; otherwise, send it to P2.
Solution:
06-03-2015 18:09
3 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
Example 7-13
Write an 8051 C program to monitor bit PI.5. If it is high, send 55H to PO; otherwise, sendAAHtoP2.
Solution:
Example 7-14
A door sensor is connected to the P 1.1 pin, and a buzzer is connected to PI.7. Write an 8051 C program to
monitor the door sensor, and when it opens, sound the buzzer. You can sound the buzzer by sending a square
wave of a few hundred Hz.
Solution:
06-03-2015 18:09
4 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
Example 7-15
The data pins of an LCD are connected to PI. The information is latched into the LCD whenever its Enable pin
goes from high to low. Write an 8051 C program to send The Earth is but One Country to this LCD.
Solution:
Run the above program on your simulator to see how PI displays each character of the message. Meanwhile,
monitor bit P2.0 after each character is issued.
Accesssing SFR addresses 80 FFH
Another way to access the SFR RAM space 80 FFH is to use the sfr data type. This is shown in Example 7-16.
We can also access a single bit of any SFR if we specify the bit address as shown in Example 7-17. Both the bit
and byte addresses for the PO P3 ports are given in Table 7-2. Notice in Examples 7-16 and 7-17, that there is
no ^include <reg51.h> statement. This allows us to access any byte of the SFR RAM space 80 FFH. This is a
method widely used for the new generation of 8051 microcontrollers, and we will use it in future chapters.
Table 7-2: Single Bit Addresses of Ports
Example 7-16
Write an 8051 C program to toggle all the bits of PO, PI, and P2 continuously with a
06-03-2015 18:09
5 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
250 ms delay. Use the sfr keyword to declare the port addresses.
Example 7-17
Solution:
06-03-2015 18:09
6 of 6
http://what-when-how.com/8051-microcontroller/io-programming-in-...
Write an 8051 C program to get the status of bit Pl.O, save it, and send it to P2.7 continuously.
Solution:
Arduino Programming
AVR Programming
Related Links
8051 Microcontroller
8051 MICROCONTROLLERS
MICROCONTROLLERS AND EMBEDDED PROCESSORS
OVERVIEW OF THE 8051 FAMILY
8051 ASSEMBLY LANGUAGE PROGRAMMING
INSIDE THE 8051
:: Search WWH ::
Custom Search
06-03-2015 18:09