100 likes | 205 Views
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.
E N D
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.
Program structure • Definition: • Initialization: • Master program • Subroutines • Tables • Definition of Special function registers • Definition of user registers and variables • Setup of peripheral devices • Setup of initial values of the ports • Setup of data downstream through the ports • Setup of initial values of user registers and variables • Main program loop • Subroutines used in the main program loop • Tables of data constants, conversion tables, texts
Program structure An example of definitions: porta equ 0x05 portb equ 0x06 trisa equ 0x85 trisb equ 0x86 status equ 0x03 #define RP0 status,5 #define RP1 status,6 #define TL1 PORTA,0 #define TL2 PORTA,1 #INCLUDE <P16F883.INC>
Program structure An example of initialization: INIT NOP BANKSEL ANSEL ;Bank selection CLRF ANSEL ;PORTA = DIGITAL I/O BANKSEL TRISA MOVLW b'11101111‚ ;Setup of data downstream of the A port MOVWF TRISA MOVLW b'11111111‚ ;Setup of data downstream of the B port MOVWF TRISB MOVLW .0 ;Reset of the C port MOVWF TRISC BANKSEL PORTA RETURN
Program structure An example of a master program: START CALL INIT ;initialization of the microcontroller bsf VYSTUP ;H level on the OUTPUT bit call zpozd ;timeout bcf VYSTUP ;L level on the OUTPUT bit call zpozd ;timeout goto START ;and again from the beginning …
Program structure An example of a subroutine: ;delay: delay loop delay movlw '255' movwf counter 1 decfsz counter 1 goto $-1 return
Program structure An example of a table: TAB RETLW b'11000000' ;character 0 RETLW b'11111001' ;character 1 RETLW b'10100100' ;character 2 RETLW b'10110000' ;character 3 RETLW b'10011001' ;character 4 RETLW b'10010010' ;character 5 RETLW b'10000010' ;character 6 RETLW b'11111000' ;character 7 RETLW b'10000000' ;character 8 RETLW b'10010000' ;character 9 RETLW b'10000110' ;character E
Summary of the subject matter - exercises • What is the difference between a definition and a declaration? • What is a peripheral device in a microcontroller? • Why is it good to set up the initial vaules of the ports before we set up the data downstream in them? • Why do we have to work with so-called banks? Which part of the memory of a microcontroller do they concern?
Summary of the subject matter - exercises • What are the advantages and pitfalls of the use of the #define directive? • What is the main principle of creating a master program? • What is the purpose and sense of a subroutine, how is it called and how is it used? • Give an example of the use of a delay loop. • Give an example of the use of a table of constants.
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