Summary of Led Blinking by Basic Language Using PIC16f877A
The article details the PIC16F877A microcontroller's pin configuration and a project to blink eight LEDs alternately on PORTD. It explains TRIS register logic for setting input/output modes, internal pull-up usage, and provides a Basic language code snippet using PIC Simulator IDE to toggle lights via shift operations every 500 microseconds.
Parts used in the LED Blinking Project:
- PIC16F877A Microcontroller
- 8 Light Emitting Diodes (LEDs)
- PIC Simulator IDE Software
- BASIC Language Compiler
PIC16F877A Pin out & Descriptions
There are 5 ports that provide parallel I/O Interfaces to outside world PORTA, PORTB, PORTC, PORTD, PORTE
Each port provides 8 bidirectional digital I/O lines which are connected to PIC16F877A pins provided that alternate functions are not selected on that Port.
Eventhough Bidirectional at nay time the I/O line can either be INPUT or OUTPUT.
By clearing some bit of the TRIS register (bit=0), the corresponding port pin is configured as output. Similarly, by setting some bit of the TRIS register (bit=1), the corresponding port pin is configured as input. This rule is easy to remember 0 = Output, 1 = Input.
Step 1: Connection of LEDs With a Port
Let us assume that 8 LEDs are connected to 8-pins of PORTD of an PIC16F877A chip.
We want to glow eight LEDs alternately. [If ‘1’ is sent, the corresponding LED glows]
And they will toggle at every 1 sec and it will be repeated continuously.
Write a C code or Basic code for the above mentioned output operations
Light Emitting Diode (LED) is a special diode that emits light when electric voltage is applied to it. It is a common electronic equipment used in many devices for indication purpose.
Step 2: Project Video
Attachments
Step 3: Summary Action During Output
Step1: If we want to read (in) data through a pin of a port, the corresponding bit of TRISx Register has to be set to ‘0’.
Step 2: Whatever data is in that pin of the port the data will appear in the corresponding bit of TRISx register.
Step 3: Each pin has a provision of connecting a pull up resistor internally. If we want to connect that resistor, we have to write ‘1’ to the corresponding bit of PORTx register.
Note: At START UP or UPON RESET, TRISx register contains 0x00. That is the port remains at Input state. But if it is used as OUTPUT at one stage of program, afterwards, we can not read data from a pin if we do not complete step 1.
Step 4: PIC SIMULATOR IDE
PIC Simulator IDE is powerful application that supplies Microchip microcontroller users with user-friendly graphical development environment for Windows with integrated simulator (emulator), pic basic compiler, assembler, disassembler and debugger. PIC Simulator IDE supports the extensive number of microcontrollers (MCUs) from the Microchip 8-bit PIC Mid-Range architecture product line (selected PIC16F, PIC12F, PIC10F models).
Step 5: Code
Define CONF_WORD = 0x3f72
Define CLOCK_FREQUENCY = 12 ‘clock frequency
AllDigital ‘all ports goes to digital
TRISD = 0x00 ‘PORTD output
PORTD = %00000001 ‘RD0 is on and other pin off or zero
goleft: ‘for left shift loop
WaitUs 500 ‘delay 500us
PORTD = ShiftLeft(PORTD, 1) ‘portd shiftleft from rd0
If PORTD.7 Then Goto goright ‘when RD7=1 then goto loop right shift
Goto goleft ‘repet loop
goright: ‘right shift loop
WaitUs 500 PORTD = ShiftRight(PORTD, 1) ‘shift right
If PORTD.0 Then Goto goleft ‘when RD0=1 then goto left shift loop
Goto goright
Source: Led Blinking by Basic Language Using PIC16f877A
- How many ports does the PIC16F877A provide?
There are 5 ports that provide parallel I/O interfaces: PORTA, PORTB, PORTC, PORTD, and PORTE. - How do you configure a port pin as an output?
You must clear the corresponding bit of the TRIS register by setting the bit to 0. - What is the default state of the TRISx register upon reset?
At startup or upon reset, the TRISx register contains 0x00, meaning all ports remain in the Input state. - How can you enable the internal pull-up resistor for a pin?
You need to write a 1 to the corresponding bit of the PORTx register to connect the internal pull-up resistor. - What clock frequency is defined in the provided BASIC code?
The code defines the clock frequency as 12 MHz. - What happens when the value sent to the LED port is 1?
If a 1 is sent to the port, the corresponding LED glows. - Which software tool is described as having an integrated simulator and compiler?
PIC Simulator IDE is the application that supplies a graphical development environment with an integrated simulator and pic basic compiler. - What condition triggers the switch from left shift to right shift in the code?
The loop switches to the right shift if the RD7 pin becomes 1.