Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●

Similar presentations


Presentation on theme: "Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●"— Presentation transcript:

1 Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ● call and retlw instructions ● lookup table ● Driving a 7seg display

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 In the notes we often miss out some of this stuff 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 PORTA and TRISA (addressing)

8

9 RPO Selects the bank 7 bits from opcode Don't worry about this yet! Address Register Memory Map

10 Department of Electronic & Electrical Engineering MOVWF instruction. 7 bits for register address opcode operand

11 Department of Electronic & Electrical Engineering Registers and banks. There are only 7 bits in an instruction for addressing the registers but we really need 8 bits ! Solution: One of the bits in the STATUS is used as a bank select.

12 Department of Electronic & Electrical Engineering

13 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

14 Department of Electronic & Electrical Engineering

15 Configuring PORTA (from data sheet) (start of program not shown)

16 Department of Electronic & Electrical Engineering Literal means the data (operand) is contained in the instruction. There is no instruction to move a literal directly to a file register. We need to use MOVLW first then move W to the register.

17 Department of Electronic & Electrical Engineering Note: 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

18 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 movwf PORTB ; output to PORTB goto loop ; loop forever end

19 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.

20 Department of Electronic & Electrical Engineering Seven Segment LED Display

21 Department of Electronic & Electrical Engineering Seven Segment Display Internal Circuit Common Anode

22 Department of Electronic & Electrical Engineering Circuit for 7seg display

23 Department of Electronic & Electrical Engineering Binary  seven segment display ● We have 4 bits of input (hex number). ● We want to display the corresponding character on the 7seg display. ● Each segment can be represented by a bit of a binary number. ● The problem is to lookup the correct 7seg code for each 4bit number. ● This can be done using a lookup table.

24 Department of Electronic & Electrical Engineering Lookup table using programmed return. ; setup stuff here..... ; w contains the 4 bit number movl 4,w call conversion ; w now contains the 7 segment code ;....more stuff here ; convert 4bit number in w into a seven segment code. conversion: ; this is just a label for the assembler addwf PCL ; add w to the PC (jump) retlw B'10111110' ; 0 return 7 seg code. retlw B'00001100' ; 1 retlw B'11011010' ; 2 retlw B'11110010' ; 3 retlw B'11100100' ; 4

25 Department of Electronic & Electrical Engineering Demo Do a demo now Dr Leonard.... If there is time?


Download ppt "Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●"

Similar presentations


Ads by Google