Mar 15

Chapter 9: Communications

  * Introduction
* 9.1 USART and Software UART
* 9.2 SPI and Software SPI
* 9.3 I2C and Software I2C
* 9.4 Manchester Code
* 9.5 RS485
* 9.6 OneWire
* 9.7 CAN & CANSPI

Introduction

When you start writing real-life programs for PIC, you may soon find yourself having a “lack of space” feeling, that you need just a few more pins and a couple of dozens of bytes to do the job. You might want to solve this problem by transferring to bigger PIC, and the problem will be solved… for a little while. Or, you just happened to have found a beautiful, brand-new humidity sensor that does “all the job by itself”, leaving you just to connect it to PIC and pick up the data… That is, if you know how to do that. If you’ve come up with these or similar problems, it really is time for you to teach your PIC and yourself some communication lessons.

There are many ways for two machines to communicate these days, and PICs are generally well equipped for the task. Depending on the job to be done, data exchange – what communication basically is – can be done in a fairly simple manner, such as the SPI communication, but can extend to an entire network of various devices – MCUs, PCs, cameras, “intelligent” sensors, etc. With increased demands, rules of device behaviour must encompass a wider set of possible scenarios and therefore protocols dramatically grow in complexity (CAN, for instance).

Consider your needs carefully before jumping to CAN-driven solutions. There are different communication methods, offering lot of possibilities at varying levels of complexity. The rule of “sacred simplicity” remains here as well: do not use more complex communication tools than you really need to!

In this chapter, you’ll get yourself acquainted with various means of communication that are being used by the PIC MCUs, and the ways to access and extend them from the BASIC programming language. You may have already noticed that some of the communication devices also have their software counterparts, meaning you can have the same communication functionality that is achieved through a set of software routines that can be used through the BASIC programming language. You should be using software communication when you have utilized all the real (hardware) communication resouces but still need an extra communication line. Read the rest of this entry »

Tags: , , , , , , , , , , , , , ,

Related posts

Mar 15

Chapter 8: Examples with Memory and Storage Media

    * Introduction
* 8.1 EEPROM Memory
* 8.2 Flash Memory
* 8.3 Compact Flash

Introduction

There is no program on this world that doesn’t interact with memory in some way. First, during its execution, it retains the operational data from, uses or alters it, and puts it back into the program memory. Second, it is often necessary to store and handle large amount of data that can be obtained from various sources, whether it is the car engine temperature acquisition data or some bitmap image to be displayed on the GLCD. In this chapter we will focus on the latter problem, i.e. we’ll go through the techniques of manipulating data on the so-called memory storage devices and systems. Read the rest of this entry »

Tags: , , , , , , , , , , , , ,

Related posts

Mar 15

Chapter 7: Examples with Displaying Data

    * Introduction
* 7.1 LED Diode
* 7.2 Seven-Segment Display
* 7.3 LCD Display, 4-bit and 8-bit Interface
* 7.4 Graphical LCD
* 7.5 Sound Signalization

Introduction

Microcontrollers deal very well with 0’s and 1’s, but humans do not. We need indicator lights, numbers, letters, charts, beepers… In order to comprehend the information presented quicker and better, we need that information to be displayed to us in many different ways. In practice, human - machine communication can require substantial (machine) resources, so it is sometimes better to dedicate an entire microcontroller to that task. This device is then called the Human - Machine Interface or simply HMI. The second microcontroller is then required to get the human wishes from HMI, “do the job” and put the results back to HMI, so that operator can see it.

Clearly, the most important form of communication between the microcontroller system and a man is the visual communication. In this chapter we will discuss various ways of displaying data, from the simplest to more elaborate ones. You’ll see how to use LED diodes, Seven-Segment Displays, character- and graphic LCDs. We will also consider using BASIC for sound signalization necessary in certain applications.

Just remember: the more profound communication you wish to be, the more MCU resources it’ll take. Read the rest of this entry »

Tags: , , , , , , , , , , , , , , , , , ,

Related posts

Mar 15

Chapter 6: Examples with PIC Integrated Peripherals

    * Introduction
* 6.1 Interrupt Mechanism
* 6.2 Internal AD Converter
* 6.3 TMR0 Timer
* 6.4 TMR1 Timer
* 6.5 PWM Module
* 6.6 Hardware UART module (RS-232 Communication)

Introduction

It is commonly said that microcontroller is an “entire computer on a single chip”, which implies that it has more to offer than a single CPU (microprocessor). This additional functionality is actually located in microcontroller’s subsystems, also called the “integrated peripherals”. These (sub)devices basically have two major roles: they expand the possibilities of the MCU making it more versatile, and they take off the burden for some repetitive and “dumber” tasks (mainly communication) from the CPU.

Every microcontroller is supplied with at least a couple of integrated peripherals – commonly, these include timers, interrupt mechanisms and AD converters. More powerful microcontrollers can command a larger number of more diverse peripherals. In this chapter, we will cover some common systems and the ways to utilize them from BASIC programming language. Read the rest of this entry »

Tags: , , , , , , , , , , , ,

Related posts

Mar 14

Chapter 5: Built-in and Library Routines

* Introduction

* 5.1 Built-in Routines

* 5.1.1 SetBit
* 5.1.2 ClearBit
* 5.1.3 TestBit
* 5.1.4 Lo
* 5.1.5 Hi
* 5.1.6 Higher
* 5.1.7 Highest
* 5.1.8 Delay_us
* 5.1.9 Delay_ms
* 5.1.10 Inc
* 5.1.11 Dec
* 5.1.12 StrLen
Read the rest of this entry »

Tags: , , , , , , , , , , , ,

Related posts

Mar 14

Chapter 4: Control Structures

    * Introduction

* 4.1 Conditional Statements
* 4.1.1 IF..THEN Statement
* 4.1.2 SELECT..CASE Statement
* 4.1.3 GOTO Statement

* 4.2 Loops
* 4.2.1 FOR Statement
* 4.2.2 DO..LOOP Statement
* 4.2.3 WHILE Statement

* 4.3 ASM Statement

Introduction

Statements define algorithmic actions within a program. Simple statements - like assignments and procedure calls - can be combined to form loops, conditional statements, and other structured statements.

Simple statement does not contain any other statements. Simple statements include assignments, and calls to procedures and functions.

Structured statements are constructed from other statements. Use a structured statement when you want to execute other statements sequentially, conditionally, or repeatedly. Read the rest of this entry »

Tags: , , , , , , ,

Related posts

Mar 14

Chapter 3: Operators

* Introduction
* 3.1 Arithmetic Operators
* 3.2 Boolean Operators
* 3.3 Logical (Bitwise) Operators
* 3.4 Relation Operators (Comparison Operators)

Introduction

In complex expressions, operators with higher precedence are evaluated before the operators with lower precedence; operators of equal precedence are evaluated according to their position in the expression starting from the left.
Operator Priority
not first (highest)
*, div, mod, and, <<, >> second
+, -, or, xor third
=, <>, <, >, <=, >= fourth (lowest) Read the rest of this entry »

Tags: , , , , , , , , , , , ,

Related posts

Mar 14

Chapter 2: Elements of BASIC Language

    * Introduction
* 2.1 Identifiers
* 2.2 Operators
* 2.3 Expressions
* 2.4 Instructions
* 2.5 Data Types
* 2.6 Constants
* 2.7 Variables
* 2.8 Symbols
* 2.9 Directives
* 2.10 Comments
* 2.11 Labels
* 2.12 Procedures and Functions
* 2.13 Modules

Introduction

This chapter deals with the elements of BASIC language and the ways to use them efficiently. Learning how to program is not complicated, but it requires skill and experience to write code that is efficient, legible, and easy to handle. First of all, program is supposed to be comprehensible, so that the programmer himself, or somebody else working on the application, could make necessary corrections and improvements. We have provided a code sample written in a clear and manifest way to give you an idea how programs could be written:
Read the rest of this entry »

Tags: , , , , , , , ,

Related posts

Mar 14

Chapter 1: The Basics* Introduction *

1.1 Why BASIC? *
1.2 Choosing the right PIC for the task *
1.3 A word about code writing *
1.4 Writing and compiling your program *
1.5 Loading program to microcontroller *
1.6 Running the program *
1.7 Troubleshooting

Introduction

Simplicity and ease which higher programming languages bring in, as well as broad application of microcontrollers today, were reasons to incite some companies to adjust and upgrade BASIC programming language to better suit needs of microcontroller programming. What did we thereby get? First of all, developing applications is faster and easier with all the predefined routines which BASIC brings in, whose programming in assembly would take the largest amount of time. This allows programmer to concentrate on solving the important tasks without wasting his time on, say, code for printing on LCD display. Read the rest of this entry »

Tags: , , , , , , , , ,

Related posts