Professional Documents
Culture Documents
Microcontrollers
1
PIC16 MCU Configuration
• Clock oscillator types
• Watchdog, power-up, brown-out timers
• Low-voltage programming
• Code protection
Microcontrollers
2
Clock oscillator types
• The PIC16F87XA can be operated in four different
oscillator modes.
– LP Low-Power Crystal
– XT Crystal/Resonator
– HS High-Speed Crystal/Resonator
–
Microcontrollers
RC Resistor/Capacitor
4
Configuration Options
• Code Protection (CP): The chip can be configured during
programming to prevent the machine code being read back from the
chip to protect commercially valuable or secure code.
• In-Circuit Programming and Debugging: Most PIC chips now
support in-circuit programming and debugging (ICPD), which allows
the program code to be downloaded and tested in the target
Microcontrollers
included is equivalent to
#fuses RC,WDT,NOPUT,BROWNOUT,LVP,NOCPD,NOWRT
This corresponds to all the bits of configuration register
being default high.
6
Configuration in C
The options defined in the standard CCS C 16F877 header file are
• Clock Type Select LP, XT, HS, RC
• Watchdog Timer Enable WDT, NOWDT
• Power Up Timer Enable PUT, NOPUT
• Program Code Protect PROTECT, NOPROTECT
• In Circuit Debugging Enable DEBUG, NODEBUG
Microcontrollers
7
PIC16 MCU Peripherals
• Digital I/O
• Timers
• A/D converter
• Comparator
Microcontrollers
8
Digital I/O
The 16F877 has the following digital I/O ports available:
9
Microcontrollers
Digital I/O
10
PIC16 C Analog Input
(Page 127 [4])
13
CCS C Analogue Input Functions
ANALOGUE INPUTS
setup_adc_ports( )
Syntax: setup_adc_ports (value)
setup_adc_ports (ports, [reference])
#include "16F877A.h"
#device ADC=8 //8-bit conversion
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1) //LCD output
void main()
{
unsigned int16 vin0; // Input variable
setup_adc(ADC_CLOCK_INTERNAL); // ADC clock
Microcontrollers
for(;;)
{ delay_ms(500);
vin0 = read_adc(); //Get input byte
vin0 = (vin0*5/255) + 0x30; //Convert to ASCII
putc(254); putc(1); delay_ms(10); // Clear screen
printf("Input = "); putc(vin0); // Display input
}
}
Microcontrollers
16
Voltage Measurement
Microcontrollers
17
Input Voltage Measurement and Display
Microcontrollers Test Program for Voltage Measurement
18
Microcontrollers
19
Temperature controller
#include "16F877A.h"
#device ADC=8
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1)
void main(){
float refin, numin, temp; int1 flag;
setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(ALL_ANALOG);
for(;;) {
delay_ms(500); set_adc_channel(0); refin = read_adc();
set_adc_channel(1);numin = read_adc();
Microcontrollers
21