Tema: Programarea pinilor porturilor unui microcontroler ca intrări I. Scopul lucrării 1.1 Familiarizarea cu tehnicile de programare a pinilor porturilor ca intrări şi simularea necesară pentru realizarea acestui lucru. II. Conținutul raportului 2.1 Programul 2 ;********************************************************************** list p=16f877A ; list directive to define processor include <p16f877A.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS w_temp EQU 0x7D ; variable used for context saving status_temp EQU 0x7E ; variable used for context saving pclath_temp EQU 0x7F ; variable used for context saving ;********************************************************************** cblock 0x20 ;start of general purpose registers d1 ;reg. utilizat in rutina de intarziere d2 ;reg. utilizat in rutina de intarziere endc org 0x0000 ;org seteaza originea, de aici porneste programul bsf STATUS, RP0 ;selecteaza bank 1 movlw b'00001111' ;se incarca registrul W cu b'00001111' movwf TRISB ;set PortB cu 4 inputs si 4 outputs bcf STATUS, RP0 ;selecteaza bank 0 clrf PORTB ;setare toate iesirile LOW Loop btfss PORTB, 0 ;Testare bit 0 al PORTB. Skip following instruction if SET. call Sw1 ;call subrutine Sw1 btfss PORTB, 1 ;Testare bit 1 of PORTB Skip following instruction if SET. call Sw2 ;call subrutine Sw2 goto Loop ;se reia bucla Sw1 call Delay ;acorda timp ca SW1 sa se linisteasca btfsc PORTB, 0 ;verifica daca este apasat Sw1 retlw 0x00 ;returneaza valoarea 0x00 daca nu btfss PORTB, 4 ;verifica daca LED1 este aprins goto LED1_on ;salt la eticheta LED1_on goto LED1_off ;salt la eticheta LED1_off LED1_on bsf PORTB, 4 ;setare bit 4 al PORTB (aprinde LED1) call Delay ;call delay subrutine btfsc PORTB, 0 ;asteapta Sw1 sa fie eliberat retlw 0x00 ;return daca nu e apasat goto LED1_on ;salt la eticheta LED1_on LED1_off bcf PORTB, 4 ;stinge LED1 call Delay ;Call delay subrutine btfsc PORTB, 0 ;asteapta Sw1 sa fie eliberat retlw 0x00 ;return daca nu e apasat goto LED1_off ;salt la eticheta LED1_off Sw2 call Delay ;acorda timp SW2 sa se linisteasca btfsc PORTB, 1 ;verifica daca este apasat SW1 retlw 0x00 ;returneaza valoarea 0x00 daca nu btfss PORTB, 5 ;verifica daca LED1 este aprins goto LED2_on ;salt la eticheta LED1_on goto LED2_off ;salt la eticheta LED1_off LED2_on bsf PORTB,5 ;aprinde LED2 call Delay ;Call delay subrutine btfsc PORTB, 1 ;asteapta Sw2 sa fie eliberat retlw 0x00 ;return daca nu e apasat goto LED2_on ;salt la eticheta LED2_on LED2_off bcf PORTB,5 ;stinge LED2 call Delay ;Call delay subrutine btfsc PORTB, 1 ;asteapta SW2 sa fie eliberat retlw 0x00 ;return daca nu e apasat goto LED2_off ;salt la eticheta LED2_off Delay movlw 0x20 ;incarcam registrul W cu valoarea 0x20 movwf d1 ;se transfera valoarea 0x20 in registrul d1 movlw 0x10 ;incarcam registrul W cu valoarea 0x10 movwf d2 ;se transfera valoarea 0x10 in registrul d2 Delay_0 decfsz d1,f ;decrementam registrul d1 cu 1. goto $+2 ;salt peste 2 instructiuni decfsz d2,f ;decrementam registrul d2 cu 1. goto Delay_0 ;salt la eticheta Delay_0 ;aceasta consuma in plus 2 cycle goto $+1 ;salt la instructiunea urmatoare return ;return la instructiunea care a trimis aici. (call delay) END ; directiva 'end of program’ care nu trebuie sa lipseasca. 2.2 Schema electrica principiala din figura 1
2.3 Rezultatele obținute la execuția programului.
Concluzie. Lucrarea a oferit o înțelegere detaliată a tehnicilor de programare a pinilor porturilor unui microcontroler ca intrări.