Download presentation
Presentation is loading. Please wait.
Published byPaul Cain Modified over 9 years ago
1
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ● PORTA PORTB (IO ports) ● TRISA TRISB (direction IN/OUT ) ● Register banks ● GOTO statement
2
Department of Electronic & Electrical Engineering Background reading Quintessential PIC. Chapter 11 has lots of (too much?) detail that we skip in the lecture.
3
Department of Electronic & Electrical Engineering Template Program #include P16F84A.INC __config _XT_OSC & _WDT_OFF & _PWRTE_ON ORG h'0' ; PROGRAM IN HERE END Useful constants Sets some hardware configuration bits Program starts at address 0 Tell assembler about the end of your program I often miss out some of this stuff to fit examples on a single slide! comment
4
Department of Electronic & Electrical Engineering Input and output TRISA TRISB PORTA PORTB REGISTER BANKS STATUS REGISTER and RP0
5
Department of Electronic & Electrical Engineering
6
Input and output (from PIC16F84A sheet) PORTA is a 5-bit wide, bi-directional port. The corresponding data direction register is TRISA. Setting a TRISA bit will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISA bit will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin)
7
Department of Electronic & Electrical Engineering Registers and banks. There are only 7 bits in an instruction for addressing the registers. TRISA is ‘H’85 or B’10000101’ But we need 8 bits ! Solution: One of the bits in the STATUS is used as a bank select. (Most significant bit of the address)
8
Department of Electronic & Electrical Engineering PORTA and TRISA (addressing) BANK 0BANK 1
10
RPO Selects the bank 7 bits from opcode Don't worry about this yet! Address Register Memory Map
11
Department of Electronic & Electrical Engineering Selecting a data bank To select a data bank we must set/clear RP0 in the STATUS register. BCF STATUS,RP0 ; CLEAR RP0 selects BANK 0 BSF STATUS,RP0 ; SET RP0 selects BANK 1
12
Department of Electronic & Electrical Engineering Configuring PORTA (from data sheet) (start of program not shown)
13
Department of Electronic & Electrical Engineering Notes and mpasm conventions: STATUS RP0 etc are symbolic constants defined in PIC16F84A.INC for example RP0 has the value 5 0x0F is a hexadecimal constant All the following are equivalent in MAPLABX (mpasm.exe) 0x0F ; hexadecimal H'F' ; hexadecimal B'00001111' ; binary D'15' ; decimal 15
14
Department of Electronic & Electrical Engineering Example: copying data from portA to portB bsf STATUS,5 ;select bank 1 movlw B'00000000' ;set up port B as all outputs movwf TRISB movlw B'00001111' ;set up port A 0-3 as inputs movwf TRISA bcf STATUS,5 ;select bank 0 loop movfw PORTA ; input PORTA -> W movwf PORTB ; output W -> PORTB goto loop ; loop forever end
15
Department of Electronic & Electrical Engineering Labels and goto. In the previous example loop is an label (not an instruction) it is just a marker (the assembler knows the address of the next instruction. GOTO label is an instruction that makes the program execution goto the instruction that follows the label.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.