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);}
}
}
- 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.