7segment Keypad EEPROM

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

7-Segment Display & Keypad

interface
7-segment display
• Used as an output.
• Can display 0-9 and few alphabets also.
• Consist of 7 individual LEDS
• Two types
– Common anode
– Common cathode.
Common Anode
Common Cathode
Interfacing with PIC
• PORTS are used.
• PORTB, PORTC, PORTD are preferred.
– As they all have 8 pins.
– PORT pins should be configured in output mode.
Logic- Common Anode
• Common Anode of 7-segment is connected to
supply (+).
• If the individual cathodes of segments are
connected to ground, the LED/segment will
glow.
• This is achieved by making PORT pin to be at
ground level or logic low.
• Writing ‘0’ to PORT pin will enable the particular
segment/LED.
Logic- Common Cathode
• Common Cathode of 7-segment is connected
to ground.
• If the individual anodes of segments are
connected to supply, the LED/segment will
glow.
• This is achieved by making PORT pin to be at
logic high.
• Writing ‘1’ to PORT pin will enable the particular
segment/LED.
Program logic- common anode
• PORTD is connected to 7-segment display.
a b c d e f g
RD0 RD1 RD2 RD3 RD4 RD5 RD6

To display ‘3’ on seven segment


a=0, b=0, c=0, d=0 ,g=0 remaining
segments should be 1

So accordingly RD0=0, RD1=0, RD2=0, RD3=0


RD6=0, remaining all should be ‘1’.

Binary sequence would be RD7-RD0


1 0 1 1 0 0 0 0 = 0 x B0 or
0 0 1 1 0 0 0 0 = 0 x 30 (as RD7 is not at all used)
Contd…
BANKSEL TRISD
CLRF TRISD
MOVLW 0xB0 or 0x 30
BANKSEL PORTD
MOVWF PORTD
Programming logic- common cathode
• PORTD is connected to 7-segment display
a b c d e f g
RD0 RD1 RD2 RD3 RD4 RD5 RD6

To display ‘3’ on seven segment


a=1, b=1, c=1, d=1 ,g=1 remaining
segments should be 0

So accordingly RD0=1, RD1=1, RD2=1, RD3=1


RD6=1, remaining all should be ‘0’.

Binary sequence would be RD7- RD0


0 1 0 0 1 1 1 1 = 0 x 4F or
1 1 0 0 1 1 1 1 = 0 x CF (as RD7 is not at all used)
Contd…
BANKSEL TRISD
CLRF TRISD
MOVLW 0x4F or 0x CF
BANKSEL PORTD
MOVWF PORTD
Keypad interface
Logic
1 2 3 Connect ROWs to PORT pins which are
configured in output mode.

Connect columns to PORT pins- configured in


4 5 6 input mode

Make each rows as ‘1’ and then check all 3


columns
7 8 9 If any column is ‘1’ then the corresponding
switch/number is pressed.

* 0 #
EEPROM
• PIC16F877a – EEPROM- 256 X 8
• 8 bits wide, 256 locations  256 bytes
• EEPROM is not directly accessible.
• Indirectly accessed through SFR
Contd…
• EEDATA - Data to be written or read
• EEADR - addresses of EEPROM to be accessed
• EECON1- bits controlling read and write
operation.

• EECON2- used only for EEPROM write cycle.


EECON1

EEIE- interrupt enable- PIE2 , EEIF- interrupt flag- PIR2


EEPROM READ
1. EEADR in BANK2. (banksel)

2. Load EEPROM address to be read in EEADR.

3. EECON1 in Bank2 (Banksel)

4. RD bit in EECON1 is set in program.

5. After Read is complete RD is cleared in hardware.( user cannot clear)

6. EEDATA in Bank3. (banksel)

7. Transfer data from EEDATA to desired location. (MOVF EEDATA, 0)


EEPROM Write
1. Disable GIE (to prevent interrupts during write)
2. Load EEDATA and EEADR ( with data to be written and
location to be written)
3. EECON1 in bank3 (banksel)
4. WREN=1, write enable.
5. Carry out the sequence
1. 0x55 EECON2
Provided by microchip in datasheet
2. 0xAA EECON2
6. WR=1,in program( reset by hardware once write is finished)
7. Wait till WR becomes ‘0’
8. Enable GIE
9. Disable WREN
Logic- EEPROM write
BCF INTCON, GIE
BSF EECON1, WREN
MOVLW 0x55 During write operation the
MOVWF EECON2 processor clock is halted
processor no longer executes.
MOVLW 0xAA
MOVWF EECON2 For this reason interrupts are
disabled.
BSF EECON1, WR
Loop BTFSC EECON1, WR During write operation
Goto Loop Peripherals can run in background.
BSF INTCON , GIE After write operation and GIE=1.
BCF EECON1, WREN the peripheral interrupt flags will
be still set as ‘1’ and will generate
interrupt.

* BANKSEL has to be used appropriately

You might also like