PIC Tutorials PIC18FxxK Devices

PIC Device Family For the 18FxxK family

PIC18F25K22The PIC18FxxK family has a wide range of devices within the family. Although many of the features are the same, the device are differentiated by the Program Memory and Data Memory. The amount of available memory is important as it will determine if the device can be boot-loaded.

The Salvo [RADIX] has a preinstalled boot loader, which enables your code to be boot loaded onto the device.

Note: The PIC18F25K22 variant installed on the Salvo [RADIX] has an SMD SOIC variant pre – installed.

The table below lists the devices in the family, and we recommend downloading the devices datasheet from the Microchip Website.

PIC Devices

Tutorials

Task 1 – Make an LED Flash

Making an LED flash is a very well renowned “Hello World” project, where an LED is toggled on and off which simply indicates that the PIC has started and is running. This can be a very useful feature in a production project whether you simply set the output high or toggle the output.

#define Q PORTB.B3 

void main()

{

ANSELB = 0X0;// Switched the Analog inputs off

PORTB = ;     // Sets two inputs with one output 

while(1)

{

Q=Q^1;

Delay_MS(500);

}

}

Task 2 – Use a switch to manually make an LED flash

The task of switching the LED on requires that an input condition be met, before the LED illuminates.

#define Q PORTB.B3
#define SW PORTB.B0
#define LED PORTB.B1
 
void main()
{

ANSELB = 0X0;// Switched the Analog inputs off

PORTB = 0xFE;     // Sets two inputs with one output 

while(1)
{

if(!SW)
{
LED=LED^1;
Delay_MS(500);
}

}

}

Task 3 – Use a PIC with two switches as a Logic Gate

This type of task is one to which we don’t perhaps give a PIC or any embedded device sufficient direct credit. Two or three I/O Pins configured as digital inputs, can be used as a logic gate replacement from the CD4000 series of devices. All you need is a grasp of Boolean algebra and you can implement TTL conditional logic alongside the other functions and tasks that your device is completing.

Turing the PIC into a logic gate is very useful and practical since the device’s operation can be changed on the fly, whereas if a real logic gate device were installed pin outs and function may differ which could result in the pcb’s usefulness being negated – pun intended.

The basic premise of Boolean logic principle is based on two states, a high or ‘1’ and a low or ‘0’. This can at times be inverted depending on the application, but for convention’s sake we will stick with the afore-mentioned.

The basic operations for a Boolean calculation are the following:

A or B = Q, which is notated as A+B = Q

A and B = Q which is notated as A.B = Q

An OR operation is one where if either condition is true, the output goes high or the equation resolve.

An AND operation is one where both conditions have to be true, for the output to go high or the equation to resolve to true.

Applying this to a real world application, let’s assume that the two inputs are connected to switches and when the two switches are depressed the change in the conditions causes the equation to be re – evaluated.

 

#define A PORTB.1

#define B PORTB.2

#define Q PORTB.3

#define HI 1

#define LO 0 

void main()
{

ANSELB = 0X0;// Switched the Analog inputs off

PORTB = ;     // Sets two inputs with one output 

while(1)
{
if(A&&B) {Q = HI;}
else{Q=LO;}

}

}

[E]