Basic input-output For CSS Compiler

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.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter