ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Curso De Curso_assembler_pic_892.doc


Enviado por   •  16 de Mayo de 2014  •  46.903 Palabras (188 Páginas)  •  196 Visitas

Página 1 de 188

My First PIC Projects

An introduction to the PIC processor.

© Bubble Software 2000

mICro’s First Projects

Introduction Flash That LED Define The Problem Writing The Software Mnemonics The Assembler Labels Using a text assembler The Flowchart MicroPlan Assembler The Simulator The Real World 7 segment LED display The Counter Using Switches

Introduction

Welcome to MICRO’s. I know you are itching to get started with your new software and begin programming PICs as soon as possible, so this introduction will get you familiar with the MICRO’s suite of software and during the process you will also start writing some small programs and hopefully get them working in the real world.

If you have the MICRO’s Experimenters Kit, then going through the projects will be quite easy. If you do not have the Experimenters Kit, then you may like to get a PIC programmer so that you can program the software into a 16F84 chip to complete the projects.

Before we get going, you have to understand that a PIC, or any other microcontroller chip for that matter, is just a piece of silicon wrapped in plastic with pins sticking out to connect it to the outside world. It does not have any brains, nor can it think for itself, so anything the chip does is the direct result of our intelligence and imagination. Sometimes you may get the feeling that these things are alive and are put here to torment your every waking minute, but this is usually due to bugs in your software, not a personality inside the chip. So please remember:

The PIC will always do what you tell it to, not necessarily what you want it to.

One other thing that can cause problems is in the way you handle the chip itself. Your body is more than likely charged with Static Electricity and is usually the zap you feel when you touch a metal object after walking on nylon carpet or similar. The PIC’s most definitely do not like this high voltage discharging into them. It can destroy the functionality of the chip either totally or partially, so always try to avoid touching the pins with your fingers.

The PIC 16F84 data sheet is available in PDF format on the CD ROM in the Acrobat directory.

Flash That LED

This would have to be the universal number one project for new PIC programmers. If you have had anything to do with writing software for PC’s, then it would be the equivalent of writing “hello world” on the monitor for the first time.

You might be thinking at this stage...“What a boring project. I want to create a robot that does amazing things, not mess around with silly ‘hello world’ or LED flash programs.”

Patience my friend. Things like that will come in due course, and as the old saying goes, “You have to crawl before you can walk”.

OK then, so how do we get started?

You might be tempted to jump straight in and write volumes of code right from the start, but I can only say, that in all probability, your software will not work. Now this might sound a bit tedious, but “planning” is the best way to begin any piece of new software. Believe me, in the long run, your code will stand a much better chance of working and it will save you valuable time. Other benefits are that your code will be structured and documented much better, which means you can read through and understand it more easily in the future if the need arises.

So just how do we get this piece of silicon to do our bidding? In this case - flash a LED.

Fundamentally, the PIC needs three things to make it work.

1) 5 volt power source.

2) Clock source

3) Software

The 5 volt supply is there to power the chip. The clock source gives the chip the ability to process instructions. The software is a list of instructions that we create. The PIC will follow these to the letter with no exceptions, so we must make sure that they are written correctly or our program will not work as intended.

Define the problem

To begin planning we must first define the LED flash problem that is going to be solved by using a PIC. This is the physical needs of the project. You can’t write reams of software without knowing what the PIC is going to control. You may find that you need to alter hardware and software as you progress, but don’t be discouraged. This is normal for a lot of projects and is called ‘Prototyping’.

We can start this discussion by saying that we must have a voltage source connected to the LED to make it light. Usually we put a resistor in series with the LED to limit the current through it to a safe level and in most LED’s the maximum current is about 20mA.

Quite obviously, if the PIC is going to turn the LED on and off for us, then the LED must be connected to one of it’s pins. These pins can be set as inputs or as outputs and when they are set as outputs we can make each individual pin have 5 volts connected or 0 volts connected by writing either a Logic 1 or a Logic 0 to them. We can now define this by saying we set a pin as an output high or as an output low.

When a pin is an output high it will have 5 volts connected to it and is able to source 20mA of current. When a pin is an output low it will have 0 volts connected to it and can sink 25mA of current.

A red LED will consume about 2 volts across it when it is being used. We know that an output pin will have 5 volts connected to it, so that means the series resistor needs to consume the remaining 3 volts. 5V - 2V = 3V. By using Ohms law we can calculate the value of the resistor which must drop 3 volts with 3mA of current flowing through it and the LED.

V = I R or R = V / I R = 3 / 0.003

Therefore R = 1000 ohms, or 1K.

Our circuit so far is a 1K ohm resistor in series with a red LED.

Which pin are we going to use to drive this LED? On the 16F84 there are 13 pins available for us to use and these are divided into 2 Ports.

PortA has 5 pins which are numbered RA0 - RA4. PortB has 8 pins which are numbered RB0 - RB7.

At this stage you might think that we can use any one of these, and you would be right - except for one thing. Pin RA4 is an open collector, which means that

...

Descargar como (para miembros actualizados)  txt (250.2 Kb)  
Leer 187 páginas más »
Disponible sólo en Clubensayos.com