Hello Readers:
I have started this blog to show you Embedded C programming for 8051 family microcontroller using KEIL compiler. The KISS philosophy is used to write this tutorial. What is KISS? Keep It Simple, Stupid!
2. Manipulating Port Pins
This section teaches you how to manipulate port pins bytewise and bitwise.
2.2 Bitwise [single bit]
Now we see how to control port pins bitwise.
This program shows how to send data to all three available ports and can used to test them by connecting LEDs. Here all three ports are toggling infinitely. This program is code optimized version of PGM_219.C as invert [~] sign is used to toggle the ports. Note the code and flow chart diagrams for code optimization effects that mean they are drastically reduced to less number of codes & steps.
Code explanation:
Line 12, 13 & 14: Sending inverted value of Ports 1, 2 & 3 to themselves only.
Line 15: 250 Millisecond Delay.
After typing the code, press F7 or click Project->Build Target for building the source code. If there are no typical errors file will build successively and shows zero errors and zero warnings.
Now enter into debug mode by pressing Ctrl+F5 or click Debug->Start/Stop Debug Session menu. Our program is sending 0x55 & 0xAA numbers in binary form to Port 1, 2 & 3 continuously. So we want to watch the Ports 1, 2 & 3 pins while running this program for toggling values. To get Port 1, 2 & 3 tabs click Peripherals->I/O Ports->Port 1, Peripherals->I/O Ports->Port 2 and Peripherals->I/O Ports->Port 3 menus.
Run the program by pressing F5 or clicking Debug->Run. You can see the toggling values between 0x55 and 0xAA on Ports 1, 2 & 3 tabs continuously in binary form. If you generate HEX file of this program, burn it into your target chip’s memory using suitable uploader and connecting 8 LEDs to all Ports you can watch LEDs toggling in binary form. To stop running the program press red ‘x’ mark icon or click Debug->Stop.
...till next post bye-bye & take care.
No comments:
Post a Comment