Summary of Basic input-output For CSS Compiler
Summary: This PIC16F877 microcontroller program configures PORTA as inputs and PORTB as outputs, disables ADC and watchdog timer, and runs at 4 MHz. In a loop it reads RA0 and RA1; if RA0 is low it sets PORTB high, and if RA1 is low it clears PORTB, each with a 100 ms delay.Parts used in the PIC16F877 PORTB Control Project:
- Microcontroller PIC16F877
- Power supply (suitable for 5V MCU operation)
- Clock crystal or resonator for 4 MHz
- Pull-up or pull-down resistors for RA0 and RA1 inputs
- LEDs or loads connected to PORTB (with current-limiting resistors)
- Decoupling capacitor(s)
- Programmer compatible with PIC16F877
- Breadboard or PCB and connecting wires
#include <16F877.h>
#device adc=8
#FUSES NOWDT ,XT
#use delay(clock=4000000)
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
output_b(0x00);
while(true){
if(!input(pin_a0)){
output_b(0xff);
delay_ms(100);}
if(!input(pin_a1)){
output_b(0x00);
delay_ms(100);}
}
}
Quick Solutions to Questions related to the PIC16F877 PORTB Control Project:
- What does this program configure PORTA and PORTB as?
PORTA is configured as inputs and PORTB as outputs. - Does the code enable the ADC module?
No, the code disables the ADC module with setup_adc(ADC_OFF) and setup_adc_ports(NO_ANALOGS). - How does the program respond when RA0 is low?
When RA0 is low the program sets all bits of PORTB high (output_b(0xff)) and delays 100 ms. - How does the program respond when RA1 is low?
When RA1 is low the program clears all bits of PORTB (output_b(0x00)) and delays 100 ms. - What clock frequency is the microcontroller configured to use?
The microcontroller is configured to use a 4 MHz clock via #use delay(clock=4000000). - Is the watchdog timer enabled in this code?
No, the watchdog timer is disabled using the NOWDT fuse. - What header file is included for device definitions?
The code includes the 16F877.h device header file. - Are any input pins configured as analog in this project?
No, setup_adc_ports(NO_ANALOGS) makes all pins digital inputs/outputs.
Related projects
PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation
Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....
Peripheral TutorialsHands-On Digital I/O Lab with PIC18F46K22 Microcontroller
PIC18F46K22 Microcontroller Digital I/O specifically explores the design of simple combinational circuits using the digital I/O capabilities of the PIC18F46K22 microcontroller. Moving...
Peripheral TutorialsDesign for manufacturing and assembly: DFA&DFM
Product developers understand the challenges involved in creating a market-ready product. Even experienced designers often go through multiple prototype iterations before reaching...
Peripheral Tutorials · PIC16F877AKeypad 4×5 for microcontrollers v. 1.1 using PIC16F877
What's this? The circuit here described is a simple 4x5 keypad that can be used in particular with the PIC 16F877 microcontroller,...
Peripheral TutorialsMatrix scankey 3×4 for Lcd 2 line For CSS Compiler
Peripheral Tutorials · PIC16F877APIC16F877 timer1 code and Proteus simulation
This PIC16F877 microcontroller tutorial answers the question, " How to use timer1 of PIC16F877 and how to handle its interrupts? " Using...