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.

Slides:



Advertisements
Similar presentations
Interrupts How to do 2 things at the same time. Need for interrupts Computers often have to deal with asynchronous events. That is to say events that.
Advertisements

Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
Embedded System Spring, 2011 Lecture 9: I/O Programming Eng. Wazen M. Shbair.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
68HC11 Polling and Interrupts
Prof. Jorge A. Ramón Introducción a Microcontroladores.
SENIOR PROJECT PRESENTATION REMOTE CONTROL CAR MURAT DİNÇER.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 26: PIC microcontroller intro.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
Railway Foundation Electronic, Electrical and Processor Engineering.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
Smart-grid Interface with Photovoltaic Installation – Phase 2 PP-01 Team members: Matt Koresh Ivan Mills Matt Martin Advisor: Dr. Aliprantis.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
I/O PORTS (Simplest Peripherals) PORT A: 6 bits wide (7th and 8th bit always read as 0) PORT B: 8 bits wide PORT C: 8 bits wide PORT D: 8 bits wide.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
EEE237 Introduction to Microprocessors Week x. SFRs.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ●
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Working with Time: Interrupts, Counters and Timers
PIC16F887.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Department of Electronic & Electrical Engineering Lecture 4. ➢ Loops ➢ Delays ➢ Conditional instructions ➢ Simple clock example.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
Microprocessors A practical approach..
TIMERS.
16F877A.
Chapter 9 PIC18 Timer Programming in Assembly
Microprocessor Systems Design I
Microprocessor Systems Design I
Prof. Ahmad Abu-El-Haija
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Microprocessor Systems Design I
Microprocessor Systems Design I
Interrupts, Counter and Timers
Microprocessor Systems Design I
PIC 16F877.
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
PIC18 Interrupt Programming
Presentation transcript:

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 flexibility and functionality to a device, some pins are multiplexed with an alternate function(s).

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.

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

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

BLOCK DIAGRAM OF RA5 PIN BLOCK DIAGRAM OF RA4 PIN

SUMMARY OF REGISTERS ASSOCIATED WITH PORTA

ADCON1 (9Fh-Bank1) PCFG3PCFG2PCFG1PCFG0

; 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

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

BLOCK DIAGRAM OF RB3:RB0 PINS

SUMMARY OF REGISTERS ASSOCIATED WITH PORTB

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.

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' ' ; 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

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

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

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

main ; Declaration in BANK ; Declaration in BANK 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' ' movlw B' ' 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 ; Declaration in BANK 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

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

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

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

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

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

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

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