Pic Ccs
Pic Ccs
MikroC and CCS C are the best compilers for beginners as they includes a
lot of built in libraries which enable us to program a PIC Microcontroller
without the deep knowledge of its internal architecture. I think CCS C is
the best High Level Language Compiler for PIC Microcontroller as it is
almost hardware independent.
For more information and for downloading CCS Compiler please visit their
website.
VDD and VSS are the pins for providing power. For PIC 16F877A, VDD = 5V
and VSS = GND (0V). Pin 13 & 14, OSC1 and OSC2 are for connecting
oscillator which will provide the necessary clock for the operation of
microcontroller. The 1st pin MCLR is the reset pin of PIC Microcontroller, it is
an active low input. It should be connected to HIGH (VDD) for normal
operations. IO (Input Output) pins in a PIC Microcontroller is divided in to
different ports, eg : PORTA, PORTB, PORTC, PORTD etc. Each PORT is
associated with two registers, TRIS and PORT which are named as TRISA,
PORTA, TRISB, PORTB etc.
PORT and TRIS are the registers which handle discrete IO operations in
PIC Microcontroller. TRIS stands for Tri-state. TRIS register determines
the function of an IO pin. Logic 1 at TRIS register makes the
corresponding pin Input while Logic 0 at TRIS register makes the
corresponding pin Output. PORT register can be used to read input pins or
to write status of output pins. For an Output Pin, Logic 1 at PORT register
makes the corresponding pin HIGH state (VDD) while Logic 0 at PORT
register makes the corresponding pin LOW state (VSS). Reading PORT
register reads the actual voltage levels on IO pins. If the actual voltage
level is near to HIGH Level (VDD), corresponding PORT bit will be 1 and if
the voltage level is near to LOW Level (VSS), corresponding PORT bit will
be 0. Hope that you can understand its working from the above image.
Prerequisite Knowledge
0 0b00000000 00 0x00
1 0b00000001 01 0x01
get_tris_x()
This function is used to read TRIS register. Examples are given below.
set_tris_x()
This function is used to write TRIS register. Examples are given below.
This function is used to read data from an IO port, ie it returns the value of
a PORT register. This function sets direction of all pins of the specified port
as INPUT (TRIS bits 1) before reading the input. Examples are given
below.
output_x()
This function is used to write data to a PORT. This function sets direction of
all pins of specified port as OUTPUT (TRIS bits 0) before writing the output.
Examples are given below.
input()
This function returns the state of the specified pin. This function sets the
direction of the specified pin as INPUT (TRIS bit 1) before reading the
input. Examples are given below.
output_bit()
This function writes the specified value (1 or 0) to the specified IO pin. This
function sets the direction of the IO pin to OUTPUT before writing the
value.
input_state()
This function reads the state of a pin without changing the direction of that
pin as input() does.
input_change_x()
This function reads the value of the specified port and it compares with
the result of last time input_change_x() function was called. It returns an 8
bit or a 16 bit number representing the changes on the port. A 1
corresponds if the value has changed and 0 corresponds if the value has
unchanged.
portc_check = input_change_c();
output_float()
This function sets the specified pin to input mode (TRIS bit 1), which is in
high impedance state.
output_drive()
This function sets the specified pin to output mode (TRIS bit 0).
output_high()
output_low()
output_toggle()
Hope you download CCS C compiler from CCS Website and installed it.
#include <main.h>
#use delay (clock=8000000)
void main()
{
while(TRUE)
{
output_high(PIN_B0); //LED ON
delay_ms(1000); //1 Second Delay
output_low(PIN_B0); //LED OFF
delay_ms(1000); //1 Second Delay
}
}