Presentation is loading. Please wait.

Presentation is loading. Please wait.

I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.

Similar presentations


Presentation on theme: "I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add."— Presentation transcript:

1 I/O PORTS

2 General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add flexibility and functionality to a device, some pins are multiplexed with an alternate function(s).

3 PORTA 6-bit wide, bidirectional port (RA0 – RA5)   RA0-RA3 pins are multiplexed with analog inputs and the analog VREF input for both the A/D converters and the comparators.   Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. On a Power-on Reset, these pins are configured as analog inputs and read as ‘0’. The comparators are in the off (digital) state.

4 BLOCK DIAGRAM OF RA3:RA0 PINS TRISA(0-3)=‘1’ PORTA pin an input ‘1’ ‘0’

5 BLOCK DIAGRAM OF RA3:RA0 PINS TRISA(0-3)=‘0’ PORTA pin an output

6 BLOCK DIAGRAM OF RA5 PIN BLOCK DIAGRAM OF RA4 PIN

7 SUMMARY OF REGISTERS ASSOCIATED WITH PORTA

8 ADCON1 (9Fh-Bank1) PCFG3PCFG2PCFG1PCFG0

9 ; BCF STATUS, RP0 ; ; Bank0 BCF STATUS, RP1 ; Bank0 ; Initialize PORTA by clearing output data latches CLRF PORTA ; Initialize PORTA by clearing output data latches ; Select Bank 1 BSF STATUS, RP0 ; Select Bank 1 ; Configure all pins MOVLW 0x06 ; Configure all pins ; as digital inputs MOVWF ADCON1 ; as digital inputs ; Value used to initialize data direction MOVLW 0xCF ; Value used to initialize data direction ; Set RA as inputs MOVWF TRISA ; Set RA as inputs ; RA as outputs ; RA as outputs ; TRISA are always ; TRISA are always ; read as '0'. ; read as '0'. INITIALIZING PORTA

10 PORTB 8-bit wide, bidirectional port (RB0 – RB7)  RB3,RB6,RB7 pins are multiplexed with the In-Circuit Debugger and Low-Voltage Programming function  RB0 is multiplexed with the external interrupt  Each of the PORTB pins has a weak internal pull-up.  RB7:RB4, have an interrupt on-change feature

11 BLOCK DIAGRAM OF RB3:RB0 PINS

12 SUMMARY OF REGISTERS ASSOCIATED WITH PORTB

13 LABORATORY 1 We will see how to active running lights (RA1-RA4) in two different directions upon the RB1 button press. Every button press will change the direction of running lights located on PORTA. We will see how to active running lights (RA1-RA4) in two different directions upon the RB1 button press. Every button press will change the direction of running lights located on PORTA.

14 Direction Settings ; choose bank 1 bsf STATUS,RP0 ; choose bank 1 movlw 0xff ; define port B as input port movwf TRISB ; define port B as input port movlw B'00000110' ; define porta as digital I/O movwf ADCON1 ; define porta as digital I/O ; define port A as output port clrf TRISA ; define port A as output port ADCON1

15 Initialization I/O PORTS bcf STATUS,RP0 ; choose bank 0 bcf ADCON0,ADON ; disable A/D converter movlw 0xFF movwf PORTA ; reset portA outputs bcf PORTA,1 ; set RA1

16 list p=16f877a ; list directive to define processor #include ; processor specific variable definitions ; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_ON ;***** VARIABLE DEFINITIONS w_temp EQU 0x70 ; variable used for context saving status_temp EQU 0x71 ; variable used for context saving num1 EQU 0x72 ; variable used for context saving num2 EQU 0x73 ; variable used for context saving #define button PORTB,1 ; use the definition button instead ;of PORTB,1

17 ORG 0x000 ; processor reset vector goto main ; go to beginning of program goto main ; go to beginning of program ORG 0x004 ; interrupt vector location ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movfSTATUS,w ; move status register into W register movwfstatus_temp ; save off contents of STATUS ;register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movf status_temp,w ; retrieve copy of STATUS register movwfSTATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt

18 main ;--------- Declaration in BANK 1 ----------------- ;--------- Declaration in BANK 1 ----------------- bsf STATUS,RP0 ; choose bank 1 bsf STATUS,RP0 ; choose bank 1 movlw 0xff movlw 0xff movwf TRISB ; define port B as input port movwf TRISB ; define port B as input port movlw B'00000110' movlw B'00000110' movwf ADCON1 ; define porta as digital I/O movwf ADCON1 ; define porta as digital I/O clrf TRISA ; define port A as output port clrf TRISA ; define port A as output port ;--------- Declaration in BANK 0 ------------------ ;--------- Declaration in BANK 0 ------------------ bcf STATUS,RP0 ; choose bank 0 bcf STATUS,RP0 ; choose bank 0 bcf ADCON0,ADON ; disable A/D converter bcf ADCON0,ADON ; disable A/D converter movlw 0xFF movlw 0xFF movwf PORTA ; reset portA outputs movwf PORTA ; reset portA outputs bcf PORTA,1 ; set RA1 bcf PORTA,1 ; set RA1

19 start1: call button_check ; call to subrutin button_check goto a1 ; jamp to address a2 cont1: btfss button ; if button pressed jump to start1 else skip the goto start2 ;goto instruction goto start2 ;goto instruction call delay ; call to subrutindelay call delay ; call to subrutin delay rlf PORTA ; rotate portb to the left bsf PORTA,1 Button_check delay

20 a1: btfsc PORTA,4 ; if LED RA4 turned on skip next instruction goto cont1 ;return to instruction in address cont goto cont1 ;return to instruction in address cont call delay call delay btfss button ; if RB1 pressed then jump to the address btfss button ; if RB1 pressed then jump to the address goto start2 ; start1 ( running lights to the right) goto start2 ; start1 ( running lights to the right) movlw 0xFF ; turn off all leds in PORTA movlw 0xFF ; turn off all leds in PORTA movwf PORTA movwf PORTA bcf PORTA,1 ; turn on led in RA1 bcf PORTA,1 ; turn on led in RA1 goto cont1 goto cont1

21 start2: call button_check ;call button_check subrutin goto a2 cont2: btfss button ; if RB1 pressed jump to the address start goto start1 goto start1 call delay call delay rrf PORTA ; rotate PORTA to the rigt rrf PORTA ; rotate PORTA to the rigt bsf PORTA,4 ; turn off led in RA4 bsf PORTA,4 ; turn off led in RA4

22 a2: btfsc PORTA,1 ; if LED RA4 turned on skip next instruction btfsc PORTA,1 ; if LED RA4 turned on skip next instruction goto cont2 ; return to instruction in address cont2 goto cont2 ; return to instruction in address cont2 call delay call delay btfss button ; if RB1 pressed jump to address btfss button ; if RB1 pressed jump to address goto start1 ; start1 (light running to the left) goto start1 ; start1 (light running to the left) movlw 0xff ; turn off all leds in PORTA movlw 0xff ; turn off all leds in PORTA movwf PORTA movwf PORTA bcf PORTA,4 ; turn on led in RA4 bcf PORTA,4 ; turn on led in RA4 goto cont2 goto cont2

23 delay movlw.200 movlw.200 movwf num1 movwf num1loop1: movlw.255 movlw.255 movwf num2 movwf num2loop2: decfsz num2 decfsz num2 goto loop2 goto loop2 decfsz num1 decfsz num1 goto loop1 goto loop1 return ; return from the subrutin to the next address after call return ; return from the subrutin to the next address after call ;instruction ;instruction

24 button_check call delay ;call delay subrutin call delay ;call delay subrutinloop: btfss button ;if RB1 is pressed, wait untill will be released btfss button ;if RB1 is pressed, wait untill will be released goto loop ;(wait untill RB1=‘1’) goto loop ;(wait untill RB1=‘1’) return return

25 תרגיל כתוב / כתבי תוכנית אשר תבצע את הדברים הבאים : בעת לחיצה על מפסק אשר מחובר ל RA4 תדליק לדים אשר נמצאים ב PORTB (RB0-RB3) בצורה הבאה : לחיצה ראשונה על RB1 תדליק Led המחובר ל -RA1 לחיצה שניה על RB1 תכבה את ה -Led ב -RA1 ותדליק Led המחובר ל -RA2 לחיצה שלישית על RB1 תכבה את ה -Led ב -RA2 ותדליק Led המחובר ל -RA3 לחיצה רביעית על RB1 תכבה את ה -Led ב -RA3 ותדליק Led המחובר ל -RA4 לחיצה חמישית על RB1 תכבה כל הלדים המחוברים ל - PORTA כך הלאה............... בהצלחה....


Download ppt "I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add."

Similar presentations


Ads by Google