Pics

Páginas: 6 (1272 palabras) Publicado: 19 de septiembre de 2012
1
World of Microcontrollers s Introduction

14

PIC microcontrollers - programming in Basic

A/D CONVERTER
External signals are usually fundamentally different from those the microcontroller recognizes (0V and 5V only) and therefore have to be converted into recognizable values. An analog to digital converter is an electronic circuit which converts continuous signals to discrete digitalnumbers. In other words, this circuit converts an analogue value into a binary number and forwards it to the CPU for further processing. This module is thus used for input pin voltage (analogue value) measurement.

1
World of Microcontrollers s Must Know Details

The result of measurement is a number (digital value) used and processed later in the program.

40

PIC microcontrollers -programming in Basic

The process of writing program in Basic. By selecting the appropriate option, the program will be compiled into an assembly then a hex code to be loaded into the microcontroller.

Similar to assembly language, a specialized program installed on the PC is in charge of compiling program into machine code. Unlike assembler, compilers for high-level programming languages createan executable code which is not always the shortest possible.
1. - Use the compiler installed on your PC to write a program in one of the high-level programming languages and select the appropriate option to compile it into a hex code. 2. - Load the hex code into the programmer (also installed on your PC) and select the appropriate option to load the program into the microcontroller. 3. - Buildthe programmed microcontroller into the target device. From now on, it will be run by this program.

1

2

3

Figure above gives a rough illustration of what is going on during the process of compiling a program written in Basic into a hex code.

PIC

MICROCONTROLLERS

-

PROGRAMMING IN

BASIC

53

Programming Microcontrollers s Programming Languages

On the other hand,programs are always executed at high speeds and in most cases it is not necessary to know in detail what is going on within the microcontroller. Despite all good attributes of the assembly language, programmers have always needed a programming language similar to the language they use in everyday speech. Finally, high-level programming languages, including Basic, have been created. The main advantageof these languages is a simplicity of program writing. Several assembly instructions are now replaced by one statement in Basic. The programmer is not required to be familiar with the instruction set of the microcontroller in use any more. It is no longer possible to know how each statement is executed, but it doesn’t matter anyway. In case it does, the problem is solved by adding a sequencewritten in assembly language to the program.

2

ADVANTAGES OF HIGH-LEVEL PROGRAMMING LANGUAGES
If you have any experience in writing programs for PIC microcontrollers in assembly language, then you are probably familiar with the other side of the medal of RISC architecture - the lack of instructions. For example, there is no appropriate instruction for multiplying two numbers. Of course, thereis a way to solve this issue owing to mathematics which enables you to perform complex operations by breaking them into a number of simple ones. Accordingly, multiplication can be easily substituted by successive addition (a x b = a + a + a + ... + a). And here we are, just at the beginning of a very long story... Still there is no reason to be worried about as far as you use one of the high-levelprogramming languages, such as Basic, as the compiler will automatically find a solution to these and similar issues. Simply write a*b.
BSF BCF CLRF L__main2: BCF CLRF ' Configure pins as outputs MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main6: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main7: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP GOTO 11...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • PICS
  • pics
  • Pics
  • Pics
  • Pics
  • Pics
  • Pics
  • Pics

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS