1 / 12

Anglicky v odborných předmětech " Support of teaching technical subjects in English “

Anglicky v odborných předmětech " Support of teaching technical subjects in English “. Training program: Mechanic - electrotechnician Program name: Digital processing - microprocessors III. class Microcontrollers Elaborated by: Vlastimil Vlček.

carol-gill
Download Presentation

Anglicky v odborných předmětech " Support of teaching technical subjects in English “

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Anglicky v odborných předmětech"Support of teaching technical subjects in English“ Training program: Mechanic - electrotechnician Program name: Digital processing - microprocessors III. class Microcontrollers Elaborated by: Vlastimil Vlček Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/04.0002 je spolufinancován Evropským sociálním fondem a státním rozpočtem České republiky.

  2. Do we start programming? In what language to program microcontrollers? Assembler – the lowest level of programming. • Advantages - the most compact code, absolute control over both HW and SW. • Disadvantages – more laborious program generation, necessity of creating proprietary libraries of subroutines. Higher programming languages (C, C++ ...) • Advantages – more synoptic, compact and therefore also faster program writing, use of standard libraries of functions. • Disadvantages – more extensive final code, arduous control over HW, in most cases a necessary investment in a good-quality translator.

  3. Illustration of writing in an assembler Let´s try to add up (in a binary manner) two simple numbers: 20 + 10 = 30: 20 in a decimal manner = 10100 in a binary manner 10 in a decimal manner = 01010 in a binary manner 30 in a decimal manner = 11110 in a binary manner Writing of the program adding up these numbers in an assembler: MOVLW b'00010100' ;b = binary representation of the number ADDLW b'00001010' Or also: MOVLW .20 ;.20 decimal representation of the number ADDLW .10 An assembler describes each instruction by means of an abbreviation based on the English description of the meaning of individual instructions. See e.g. the above-stated instruction: MOVLW has its origin in the word Move (transfer) and transfers the L data constant to the W register ADDLW is derived from the word Add (count up) and really adds up the L constant to the contents of the W register The result is saved in the W register.

  4. Illustration of the same writing in a higher language A = 20 B = 30 C = A + B Print C Comparison of both ways of writing • Higher programming language: • We do not have to know the inner structure of the processor for which the program is destined. Easier, faster and clearer writing, but at the expense of a bigger result file taking up abigger memory space. • Assembler: • More complicated and slower way of writing, we have to know the inner structure of the processor and the data storage place exactly. • The result file is, however, smaller (when programmed correctly, the smallest possible). If we want, we can have an absolute control over the behaviour of the program.

  5. Principles of writing a source text in an assembler • It is a plain text file. • It must not contain any characters but for text characters and the tabulator character. • It is possible to use an arbitrary text editor if we keep the above-stated conditions. • It is necessary to keep the prescribed writing format (determined by the translator which is used). • It is recommended to use specialized text editors embedded in development systems (they can, to a high degree, “watch over” the correctness of the writing).

  6. Recommended writing format (Microchip - MPASM)

  7. Translation of a program source text MPASM is a translator from an assembler into the machine code for the Microchip microcontrollers. It is integrated to the MPLAB IDE development environment, but can also be used as an independent application.

  8. Program source text before translation • #include <p16f883.inc> • EQU 0x20 • COUNTER_1 EQU RAM+1 • COUNTER_2 EQU RAM+2 • GOTO START • INIT NOP • BANKSEL ANSEL • CLRF ANSEL • CLRF ANSELH • BANKSEL TRISA • MOVLW .0 • MOVWF TRISC • BANKSEL PORTC • MOVLW b'11111111' ; switching off of all LED diodes at the C port • MOVWF PORTC • RETURN • WAIT MOVLW D'100' • MOVWF COUNTER_1 ;outside loop • WAIT_A MOVLW D'255' • MOVWF COUNTER_2 ;inner loop • WAIT_B DECFSZ COUNTER_2,f ;readout of the inner loop counter, zero test • GOTO WAIT_B ;is not zero - back • DECFSZ COUNTER_1,f ;readout of the outside loop counter, zero test • GOTO WAIT_A ;is not zero - back • return ;both loops reset - return • START CALL INIT ;inicialization of the microcontroller • START1 BCF STATUS,C ;resetting of the carry bit • START3 RLF PORTC • CALL WAIT • GOTO START3 • END

  9. The same program after the translation into the machine code :020000040000FA :10000000182800008316031788018901831603133B :100010000030870083120313FF308700080064302C :10002000A100FF30A200A20B1328A10B1128080089 :0A00300001200310870D0F201A288D :00000001FF Only after the creating of this machine code, it is possible to save the program in the memory of the microcontroller, it is possible to start the program, or use debugging means (simulation, emulation, step-by-step operation etc.). It is not possible to work directly with the original source text file! When working with ICD2 and with the MPLAB IDE development environment, we have an option whether to use a software simulation or debugging at the chip of the circuit. Both ways have their advantages and disadvantages, it depends on the actual situation which of them we will use.

  10. Summary of the subject matter • What are the advantages of a higher programming language and when is it, by contrast, more suitable to use an assembler? • What do we need a translator for? • What format is the translated source text in?

  11. Summary of the subject matter • For what reasons is it recommended to use specialized text editors for writing a program source text? • What are the main principles of writing a program source text? • Why is it necessary to keep the recommended writing format of a program source text?

  12. References • DatasheetMicrochip PIC16F882/883/884/886/887 DS41291E (http://www.microchip.com) • Microchip.com: GettingStartedwithPICmicroMCUs • Microchip.com: MPLAB IDE User’s Guide • Microchip.com: QuickGuide to MicrochipDevelopmentTools

More Related